Subversion Repositories bacoAlunos

Rev

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