Subversion Repositories bacoAlunos

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1936 grupo5 1
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
2
<%@ page import="jomm.dao.impl.AbstractDao" %>
3
<%@ page import="pt.estgp.estgweb.domain.CourseImpl" %>
4
<%@ page import="pt.estgp.estgweb.domain.dao.DaoFactory" %>
5
<%@ page import="pt.estgp.estgweb.utils.documentBuilder.TextComponent" %>
6
<%@ page import="pt.estgp.estgweb.utils.documentBuilder.ImageComponent" %>
7
<%@ page import="pt.estgp.estgweb.services.courses.CourseReportServices" %>
8
<%@ page import="pt.estgp.estgweb.services.courses.coursereport.documentmodel.CourseReportDocument" %>
9
<%@ page import="org.json.JSONException" %>
10
<%@ page import="pt.estgp.estgweb.services.sigesimports.ImportCourseService" %>
11
<%@ page import="pt.estgp.estgweb.domain.UserSession" %>
12
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
13
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
14
<%@ taglib uri="/WEB-INF/tlds/jomm.tld" prefix="jomm" %>
15
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
16
<%@ taglib uri="/WEB-INF/tlds/struts-nested.tld" prefix="nested" %>
17
<%@ taglib uri="/WEB-INF/tlds/baco.tld" prefix="baco" %>
18
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
19
 
20
<link rel="stylesheet" href="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.css">
21
<script src="<%=request.getContextPath()%>/js/jquery-ui-1.12.1/jquery-ui.min.js"></script>
22
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/flora-commons/flora.resizable.css">
23
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
24
<script>
25
    function demoFromHTML() {
26
        var pdf = new jsPDF('p', 'pt', 'letter');
27
        // source can be HTML-formatted string, or a reference
28
        // to an actual DOM element from which the text will be scraped.
29
        source = $('#courseReportApp')[0];
30
 
31
        // we support special element handlers. Register them with jQuery-style
32
        // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
33
        // There is no support for any other type of selectors
34
        // (class, of compound) at this time.
35
        specialElementHandlers = {
36
            // element with id of "bypass" - jQuery style selector
37
            '#bypassme': function (element, renderer) {
38
                // true = "handled elsewhere, bypass text extraction"
39
                return true
40
            }
41
        };
42
        margins = {
43
            top: 80,
44
            bottom: 60,
45
            left: 40,
46
            width: 522
47
        };
48
        // all coords and widths are in jsPDF instance's declared units
49
        // 'inches' in this case
50
        pdf.fromHTML(
51
            source, // HTML string or DOM elem ref.
52
            margins.left, // x coord
53
            margins.top, { // y coord
54
                'width': margins.width, // max width of content on PDF
55
                'elementHandlers': specialElementHandlers
56
            },
57
 
58
            function (dispose) {
59
                // dispose: object with X, Y of the last line add to the PDF
60
                //          this allow the insertion of new lines after html
61
                //var pdfDocument =  pdf.save('Test.pdf');
62
                var pdfDocument = pdf.output();
63
 
64
                var boundary = '---------------------------';
65
                boundary += Math.floor(Math.random()*32768);
66
                boundary += Math.floor(Math.random()*32768);
67
                boundary += Math.floor(Math.random()*32768);
68
 
69
                var body = '';
70
                body += '--' + boundary + '\r\n' +
71
                    'Content-Disposition: form-data; name="filesInputId-UPLOAD[]"; filename="20170530_210340.pdf"' + '\r\n';
72
                body += 'Content-Type: application/pdf';
73
                body += '\r\n\r\n';
74
                body += pdfDocument;
75
                body += '\r\n'
76
                body += '--' + boundary + '--';
77
 
78
 
79
 
80
                $.ajax({
81
                    type: "POST",
82
                    cache: false,
83
                    url: "<%=request.getContextPath()%>/filesUpload",
84
                    data: body ,
85
                    processData: false,
86
                    contentType : 'multipart/form-data; boundary=' + boundary,
87
                    success: function (data) {
88
                        alert('success');
89
                        return false;
90
                    }
91
                });
92
            }, margins
93
        );
94
    }
95
</script>
96
 
97
<%
98
 
99
    String courseCode = request.getParameter("courseCode");
100
    String year = request.getParameter("year");
101
 
102
    AbstractDao.getCurrentSession().beginTransaction();
103
    CourseImpl courseImpl = DaoFactory.getCourseDaoImpl().findCourseByCode(courseCode);
104
    request.setAttribute("course",courseImpl);
105
 
106
    CourseReportDocument courseReportDocument = null;
107
 
108
    String auxCourseReportDocument;
109
    auxCourseReportDocument = new CourseReportServices().loadCourseReportDocument(courseCode,year);
110
 
111
    try {
112
        courseReportDocument = courseReportDocument.fromJson(auxCourseReportDocument);
113
    }catch (Throwable e) {
114
        System.out.println(e);
115
        e.printStackTrace();
116
    }
117
    /*try {
118
        courseReport = new CourseReportServices().createNewCourseReportDocument(courseCode, year);
119
    } catch (Throwable e) {
120
        System.out.println(e);
121
        e.printStackTrace();
122
    }*/
123
 
124
    String courseReportJson = courseReportDocument.toJson();
125
    request.setAttribute("courseDocumentJson",courseReportJson);
126
    request.setAttribute("courseDocument",courseReportDocument);
127
 
128
%>
129
<%--<a href="javascript:demoFromHTML()" class="button">Run Code</a>--%>
130
 
131
<div class="container-fluid">
132
 
133
    <style>
134
        .separatorSection
135
        {
136
            border: 1px solid #ddd;
137
        }
138
    </style>
139
 
140
 
141
    <!-- Apresentacao da Unidade -->
142
 
143
    <div class="panel panel-default">
144
        <div class="panel-heading">
145
            Relatório Anual do curso: ${course.name}
146
        </div>
147
        <div class="panel-body">
148
 
149
            <p><b class="label-info">Tipo de Curso:</b> <bean:message key="course.${course.degree}"/></p>
150
            <p><b class="label-info">Ano Lectivo:</b> ${course.importYear}</p>
151
            <p><b class="label-info">Departamento:</b> ${course.department.name}</p>
152
            <p><b class="label-info">Escola:</b> ${course.department.courseSchool.name}</p>
153
 
154
 
155
 
156
 
157
            <script>
158
 
159
                //Especifico da aplicacao
160
                var courseReportApp = angular.module('courseReportApp', ['ui.tree']);
161
                GLOBAL_BacoAngularAppDependencies.push('courseReportApp');
162
 
163
 
164
                courseReportApp.directive('resizable', function () {
165
                    return {
166
                        restrict: 'A',
167
                        scope: {
168
                            callback: '&onResize'
169
                        },
170
                        link: function postLink(scope, elem, attrs) {
171
                            elem.resizable();
172
                            elem.on('resize', function (evt, ui, comp) {
173
                                scope.$apply(function() {
174
                                    if (scope.callback) {
175
                                        scope.callback({$evt: evt, $ui: ui, $comp: comp });
176
                                    }
177
                                })
178
                            });
179
                        }
180
                    };
181
                });
182
 
183
 
184
                courseReportApp.controller('courseReportAppController', function($scope)
185
                {
186
 
187
                    $scope.docAppSelector = "#courseReportApp";
188
                    $scope.report = <%=courseReportJson%>
189
 
190
                        $scope.resize = function(evt,ui,comp) {
191
                            //console.log (evt,ui);
192
                            comp.width = ui.size.width;
193
                            comp.height = ui.size.height;
194
                        }
195
 
196
                    /**
197
                     * @classe class to match
198
                     * @superClasses array of strings
199
                     * */
200
                    $scope.contains = function(obj,classe)
201
                    {
202
                        if(obj['@class'] && obj['@class'] == classe)
203
                            return true;
204
                        if(obj.allSuperClasses)
205
                        {
206
                            for(var i in obj.allSuperClasses)
207
                            {
208
                                if(classe == obj.allSuperClasses[i])
209
                                    return true;
210
                            }
211
                        }
212
                        return false;
213
                    }
214
 
215
                    $scope.showSep = function(section,subSection)
216
                    {
217
                        var s;
218
                        for(s in section.sections)
219
                        {
220
                            section.sections[s].active = false;
221
                        }
222
                        /*$(".separatorSectionNav").each(function()
223
                         {
224
                         angular.element($(this)).scope().section.active = false;
225
                         });*/
226
                        subSection.active = true;
227
                    }
228
 
229
                    /**
230
                     * Este metodo devolve o template mais profundo na hierarquia de classes
231
                     * permitindo emular o override, quanto mais especifica for a classe
232
                     * e caso exista template é esse o template devolvido
233
                     * procura um script com o id da classe e se nao existir
234
                     * vai subindo nas super classes
235
                     * @param obj
236
                     * @returns {*}
237
                     */
238
                    $scope.class2id = function(obj)
239
                    {
240
                        var objClassId = obj["@class"].replaceAll(".","_");
241
                        if($("script#" + objClassId).length > 0)
242
                        {
243
                            return objClassId;
244
                        }
245
                        if(obj.allSuperClasses)
246
                        {
247
                            var s;
248
                            for(s in obj.allSuperClasses)
249
                            {
250
                                var superClass = obj.allSuperClasses[s];
251
                                var superClassId = superClass.replaceAll(".","_");
252
                                if($("script#" + superClassId).length > 0)
253
                                {
254
                                    return superClassId;
255
                                }
256
                            }
257
                        }
258
                        return obj["@class"].replaceAll(".","_");
259
                    }
260
 
261
                    $scope.addText = function(parentCustomPane)
262
                    {
263
                        $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.TextComponent")
264
                    }
265
 
266
                    $scope.addImage = function(parentCustomPane)
267
                    {
268
                        $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.ImageComponent")
269
                    }
270
 
271
                    $scope.addSimpleDocComponent = function(parentCustomPane,classComponent)
272
                    {
273
                        if(!parentCustomPane.components)
274
                        {
275
                            parentCustomPane.components = [];
276
                        }
277
                        parentCustomPane.components.push(
278
                            {
279
                                "@class" : classComponent
280
                            }
281
                        );
282
                    }
283
                    $scope.removeComponent = function(index,array)
284
                    {
285
                        array.splice(index,1);
286
                    }
287
 
288
                    $scope.callbackUploadedFiles = function(filesUploadResult,token,targetElement)
289
                    {
290
                        var modelObject = BacoAngularUtils.getAngularElementModel(targetElement);
291
 
292
                        if(modelObject.image && modelObject.image.identifier)
293
                        {
294
                            widgetCallWithActionParameters(
295
                                "<%=request.getContextPath()%>/user/json/repository.do",
296
                                "replaceRepositoryFileFromTempPrivateDomain",
297
                                {
298
                                    "identifier" : modelObject.image.identifier,
299
                                    "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
300
                                },
301
                                "#courseReportApp",
302
                                function(repositoryFile4JsonView)
303
                                {
304
                                    modelObject.image = repositoryFile4JsonView;
305
                                    //image URL is generated on reimport just to avoid caching
306
                                    modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
307
                                    angular.element($("#courseReportApp")).scope().$apply();
308
                                },
309
                                function(){}
310
                            );
311
                        }
312
                        else
313
                        {
314
                            widgetCallWithActionParameters(
315
                                "<%=request.getContextPath()%>/user/json/repository.do",
316
                                "saveRepositoryFileFromTempPrivateDomain",
317
                                {
318
                                    "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
319
                                },
320
                                "#courseReportApp",
321
                                function(repositoryFile4JsonView)
322
                                {
323
                                    modelObject.image = repositoryFile4JsonView;
324
                                    modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
325
                                    angular.element($("#courseReportApp")).scope().$apply();
326
                                },
327
                                function(){}
328
                            );
329
                        }
330
                    }
331
 
332
                    $scope.Save = function () {
333
                        widgetCallWithActionParameters(
334
                            "<%=request.getContextPath()%>/user/courseReport.do",
335
                            "saveCourseReportDocument",
336
                            {
337
                                "courseReportDocument":BacoJS.stringifyOrdered($scope.report)
338
                            },
339
                            "#courseReportApp",
340
                            function(json)
341
                            {
342
                                alert(BacoJS.stringifyOrdered(json));
343
                            },
344
                            function(){}
345
                        );
346
                    }
347
 
348
 
349
                });
350
            </script>
351
 
352
            <!--TEMPLATES FOR DOCUMENT BUILDER-->
353
            <jsp:include page="../utils/documentsBuilder.jsp"/>
354
 
355
            <div class="form-vertical">
356
                <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController">
357
                    <div class="web-messages"> </div>
358
                    <button class="btn" ng-click="Save()">Save</button>
359
                    <div ng-init="section=report;" ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'">
360
 
361
                    </div>
362
 
363
                    <!-- <pre class="code">{{ report | json }}</pre>-->
364
 
365
 
366
 
367
                </div><!--App-->
368
            </div> <!--form-->
369
 
370
        </div><!--Panel Body-->
371
 
372
    </div><!--Panel-->
373
 
374
</div><!--container-fluid-->
375
 
376
<%
377
    AbstractDao.getCurrentSession().getTransaction().commit();
378
%>