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