Subversion Repositories bacoAlunos

Rev

Rev 1927 | 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(
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
                },
55
 
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();
61
 
62
                    var boundary = '---------------------------';
63
                    boundary += Math.floor(Math.random()*32768);
64
                    boundary += Math.floor(Math.random()*32768);
65
                    boundary += Math.floor(Math.random()*32768);
66
 
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 + '--';
75
 
76
 
77
 
78
                    $.ajax({
79
                        type: "POST",
80
                        cache: false,
81
                        url: "<%=request.getContextPath()%>/filesUpload",
82
                        data: body ,
83
                        processData: false,
84
                        contentType : 'multipart/form-data; boundary=' + boundary,
85
                        success: function (data) {
86
                            alert('success');
87
                            return false;
88
                        }
89
                    });
90
                }, margins
91
        );
92
    }
93
</script>
94
 
95
<%
1935 grupo5 96
    //Falta Chamar Serviço
1830 jmachado 97
 
1935 grupo5 98
 
1848 jmachado 99
    String courseCode = request.getParameter("courseCode");
1927 grupo5 100
    String year = request.getParameter("year");
1830 jmachado 101
    AbstractDao.getCurrentSession().beginTransaction();
1848 jmachado 102
    CourseImpl courseImpl = DaoFactory.getCourseDaoImpl().findCourseByCode(courseCode);
1830 jmachado 103
    request.setAttribute("course",courseImpl);
1848 jmachado 104
    CourseReportDocument courseReport = null;
105
    try {
1927 grupo5 106
        courseReport = new CourseReportServices().createNewCourseReportDocument(courseCode, year);
1848 jmachado 107
    } catch (Throwable e) {
108
        System.out.println(e);
109
        e.printStackTrace();
110
    }
111
    String courseReportJson = courseReport.toJson();
112
    request.setAttribute("courseDocumentJson",courseReportJson);
113
    request.setAttribute("courseDocument",courseReport);
1830 jmachado 114
 
115
%>
1848 jmachado 116
<%--<a href="javascript:demoFromHTML()" class="button">Run Code</a>--%>
1830 jmachado 117
 
118
<div class="container-fluid">
119
 
1927 grupo5 120
<style>
121
    .separatorSection
122
    {
123
        border: 1px solid #ddd;
124
    }
125
</style>
1830 jmachado 126
 
127
 
1927 grupo5 128
<!-- Apresentacao da Unidade -->
1830 jmachado 129
 
1927 grupo5 130
<div class="panel panel-default">
131
<div class="panel-heading">
132
    Relatório Anual do curso: ${course.name}
133
</div>
134
<div class="panel-body">
1830 jmachado 135
 
1927 grupo5 136
<p><b class="label-info">Tipo de Curso:</b> <bean:message key="course.${course.degree}"/></p>
137
<p><b class="label-info">Ano Lectivo:</b> ${course.importYear}</p>
138
<p><b class="label-info">Departamento:</b> ${course.department.name}</p>
139
<p><b class="label-info">Escola:</b> ${course.department.courseSchool.name}</p>
1830 jmachado 140
 
141
 
142
 
143
 
1927 grupo5 144
<script>
1830 jmachado 145
 
1927 grupo5 146
    //Especifico da aplicacao
147
    var courseReportApp = angular.module('courseReportApp', ['ui.tree']);
148
    GLOBAL_BacoAngularAppDependencies.push('courseReportApp');
1830 jmachado 149
 
150
 
1927 grupo5 151
    courseReportApp.directive('resizable', function () {
152
        return {
153
            restrict: 'A',
154
            scope: {
155
                callback: '&onResize'
156
            },
157
            link: function postLink(scope, elem, attrs) {
158
                elem.resizable();
159
                elem.on('resize', function (evt, ui, comp) {
160
                    scope.$apply(function() {
161
                        if (scope.callback) {
162
                            scope.callback({$evt: evt, $ui: ui, $comp: comp });
1830 jmachado 163
                        }
1927 grupo5 164
                    })
1830 jmachado 165
                });
1927 grupo5 166
            }
167
        };
168
    });
1830 jmachado 169
 
170
 
1927 grupo5 171
    courseReportApp.controller('courseReportAppController', function($scope)
172
    {
1830 jmachado 173
 
1927 grupo5 174
        $scope.docAppSelector = "#courseReportApp";
175
        $scope.report = <%=courseReportJson%>
1830 jmachado 176
 
1927 grupo5 177
                $scope.resize = function(evt,ui,comp) {
178
                    //console.log (evt,ui);
179
                    comp.width = ui.size.width;
180
                    comp.height = ui.size.height;
181
                }
1830 jmachado 182
 
1927 grupo5 183
        /**
184
         * @classe class to match
185
         * @superClasses array of strings
186
         * */
187
        $scope.contains = function(obj,classe)
188
        {
189
            if(obj['@class'] && obj['@class'] == classe)
190
                return true;
191
            if(obj.allSuperClasses)
192
            {
193
                for(var i in obj.allSuperClasses)
194
                {
195
                    if(classe == obj.allSuperClasses[i])
196
                        return true;
197
                }
198
            }
199
            return false;
200
        }
1848 jmachado 201
 
1927 grupo5 202
        $scope.showSep = function(section,subSection)
203
        {
204
            var s;
205
            for(s in section.sections)
206
            {
207
                section.sections[s].active = false;
208
            }
209
            /*$(".separatorSectionNav").each(function()
210
             {
211
             angular.element($(this)).scope().section.active = false;
212
             });*/
213
            subSection.active = true;
214
        }
1848 jmachado 215
 
1927 grupo5 216
        /**
217
         * Este metodo devolve o template mais profundo na hierarquia de classes
218
         * permitindo emular o override, quanto mais especifica for a classe
219
         * e caso exista template é esse o template devolvido
220
         * procura um script com o id da classe e se nao existir
221
         * vai subindo nas super classes
222
         * @param obj
223
         * @returns {*}
224
         */
225
        $scope.class2id = function(obj)
226
        {
227
            var objClassId = obj["@class"].replaceAll(".","_");
228
            if($("script#" + objClassId).length > 0)
229
            {
230
                return objClassId;
231
            }
232
            if(obj.allSuperClasses)
233
            {
234
                var s;
235
                for(s in obj.allSuperClasses)
236
                {
237
                    var superClass = obj.allSuperClasses[s];
238
                    var superClassId = superClass.replaceAll(".","_");
239
                    if($("script#" + superClassId).length > 0)
1848 jmachado 240
                    {
1927 grupo5 241
                        return superClassId;
1848 jmachado 242
                    }
1927 grupo5 243
                }
244
            }
245
            return obj["@class"].replaceAll(".","_");
246
        }
1848 jmachado 247
 
1927 grupo5 248
        $scope.addText = function(parentCustomPane)
249
        {
250
            $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.TextComponent")
251
        }
1830 jmachado 252
 
1927 grupo5 253
        $scope.addImage = function(parentCustomPane)
254
        {
255
            $scope.addSimpleDocComponent(parentCustomPane,"pt.estgp.estgweb.utils.documentBuilder.ImageComponent")
256
        }
1830 jmachado 257
 
1927 grupo5 258
        $scope.addSimpleDocComponent = function(parentCustomPane,classComponent)
259
        {
260
            if(!parentCustomPane.components)
261
            {
262
                parentCustomPane.components = [];
263
            }
264
            parentCustomPane.components.push(
1830 jmachado 265
                    {
1927 grupo5 266
                        "@class" : classComponent
1830 jmachado 267
                    }
1927 grupo5 268
            );
269
        }
270
        $scope.removeComponent = function(index,array)
271
        {
272
            array.splice(index,1);
273
        }
1830 jmachado 274
 
1927 grupo5 275
        $scope.callbackUploadedFiles = function(filesUploadResult,token,targetElement)
276
        {
277
            var modelObject = BacoAngularUtils.getAngularElementModel(targetElement);
1830 jmachado 278
 
1927 grupo5 279
            if(modelObject.image && modelObject.image.identifier)
280
            {
281
                widgetCallWithActionParameters(
282
                        "<%=request.getContextPath()%>/user/json/repository.do",
283
                        "replaceRepositoryFileFromTempPrivateDomain",
1830 jmachado 284
                        {
1927 grupo5 285
                            "identifier" : modelObject.image.identifier,
286
                            "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
287
                        },
288
                        "#courseReportApp",
289
                        function(repositoryFile4JsonView)
1830 jmachado 290
                        {
1927 grupo5 291
                            modelObject.image = repositoryFile4JsonView;
292
                            //image URL is generated on reimport just to avoid caching
293
                            modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
294
                            angular.element($("#courseReportApp")).scope().$apply();
295
                        },
296
                        function(){}
297
                );
298
            }
299
            else
300
            {
301
                widgetCallWithActionParameters(
302
                        "<%=request.getContextPath()%>/user/json/repository.do",
303
                        "saveRepositoryFileFromTempPrivateDomain",
304
                        {
305
                            "fileUploaded" : BacoJS.stringifyOrdered(filesUploadResult.uploadedFiles[0])
306
                        },
307
                        "#courseReportApp",
308
                        function(repositoryFile4JsonView)
309
                        {
310
                            modelObject.image = repositoryFile4JsonView;
311
                            modelObject.imageUrl = "<%=request.getContextPath()%>/repositoryStream/" + modelObject.image.identifier + "?" + new Date().getTime();
312
                            angular.element($("#courseReportApp")).scope().$apply();
313
                        },
314
                        function(){}
315
                );
316
            }
317
        }
1830 jmachado 318
 
1935 grupo5 319
        $scope.Save = function () {
320
            widgetCallWithActionParameters(
321
                "<%=request.getContextPath()%>/user/courseReport.do",
322
                "SaveCourseReportDocument",
323
                {
324
                    "courseReportDocument":BacoJS.stringifyOrdered($scope.report)
325
                },
326
                "#courseReportApp",
327
                function(json)
328
                {
329
                    alert(BacoJS.stringifyOrdered(json));
330
                },
331
                function(){}
332
            );
333
        }
1830 jmachado 334
 
1848 jmachado 335
 
1927 grupo5 336
    });
337
</script>
1830 jmachado 338
 
1927 grupo5 339
<!--TEMPLATES FOR DOCUMENT BUILDER-->
340
<jsp:include page="../utils/documentsBuilder.jsp"/>
341
<jsp:include page="coursereport/templates.jsp"/>
1830 jmachado 342
 
1935 grupo5 343
 
1927 grupo5 344
<div class="form-vertical">
345
    <div id="courseReportApp" ng-app="courseReportApp" ng-controller="courseReportAppController">
1935 grupo5 346
        <div class="web-messages"> </div>
347
        <button ng-click="Save()">Click me</button>
1927 grupo5 348
        <div ng-init="section=report;" ng-include="'pt_estgp_estgweb_utils_documentBuilder_DocumentSection'">
1830 jmachado 349
 
1927 grupo5 350
        </div>
1830 jmachado 351
 
1927 grupo5 352
        <!-- <pre class="code">{{ report | json }}</pre>-->
1830 jmachado 353
 
354
 
355
 
1927 grupo5 356
    </div><!--App-->
357
</div> <!--form-->
1830 jmachado 358
 
1927 grupo5 359
</div><!--Panel Body-->
1830 jmachado 360
 
1927 grupo5 361
</div><!--Panel-->
1830 jmachado 362
 
363
</div><!--container-fluid-->
364
 
365
<%
366
    AbstractDao.getCurrentSession().getTransaction().commit();
1935 grupo5 367
%>