Subversion Repositories bacoAlunos

Rev

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