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