diff --git a/src/app/entity/controllers/EntitySeparatorController.php b/src/app/entity/controllers/EntitySeparatorController.php index 07e3258dc1995da05e064eeb3b2ff09ec42fc9d9..70a1794e92ab7432db9e596a14dfd47d38b8605d 100755 --- a/src/app/entity/controllers/EntitySeparatorController.php +++ b/src/app/entity/controllers/EntitySeparatorController.php @@ -116,6 +116,6 @@ class EntitySeparatorController $response->write($fileContent); $response = $response->withAddedHeader('Content-Disposition', "inline; filename=entitySeparator.pdf"); - return $response->withHeader('Content-Type', $mimeType); + return $response->withJson(base64_encode($fileContent)); } } diff --git a/src/frontend/app/separator/print-separator/print-separator.component.html b/src/frontend/app/separator/print-separator/print-separator.component.html index 169f07e9e5506a33be735722ac801514548db001..caa3905aef953f9813f8b55485395e624700aaca 100644 --- a/src/frontend/app/separator/print-separator/print-separator.component.html +++ b/src/frontend/app/separator/print-separator/print-separator.component.html @@ -28,7 +28,7 @@ <div class="col-md-4"> <mat-form-field> <mat-label>{{lang.separatorType}}</mat-label> - <mat-select [(ngModel)]="separator.type"> + <mat-select [(ngModel)]="separator.type" (selectionChange)="this.docBuffer = null"> <mat-option *ngFor="let separatorType of separatorTypes" [value]="separatorType"> {{lang[separatorType]}} </mat-option> @@ -44,28 +44,35 @@ </mat-form-field> </div> <div class="col-md-8"> + <mat-form-field> + <input matInput id="jstree_search" name="jstree_search" type="text" + placeholder="{{lang.searchEntities}}"> + <mat-hint>{{lang.entityTreeInfoSeparator}}</mat-hint> + </mat-form-field> <div id="jstree"></div> </div> - + <div class="col-md-12 text-center" style="padding-top: 10px;"> + <button mat-raised-button color="primary" (click)="generateSeparators()" + [disabled]="loading || (separator.target == 'entities' && separator.entities.length == 0)">{{lang.generateAndDownload}}</button> + </div> </div> <div class="table-head"> </div> </div> </div> </mat-sidenav-content> - <mat-sidenav #snav2 [fixedInViewport]="mobileMode" position='end' [opened]="mobileMode || docUrl == '' ? false : true" - [mode]="mobileMode ? 'over' : 'side'" class="panel-right" style="overflow-x:hidden;" - [ngStyle]="{'width': mobileMode ? '80%' : '30%'}" autoFocus="false"> + <mat-sidenav #snav2 [fixedInViewport]="mobileMode" position='end' + [opened]="mobileMode || docBuffer == null ? false : true" [mode]="mobileMode ? 'over' : 'side'" + class="panel-right" style="overflow-x:hidden;" [ngStyle]="{'width': mobileMode ? '80%' : '30%'}" + autoFocus="false"> <div class="example-loading-shade" *ngIf="loading"> <mat-spinner></mat-spinner> </div> <div class="titlePanel"> - <span color="primary" style="flex:1;font-size: 20px;font-weight: bold;padding: 10px;">{{lang.separators}}</span> - <span> - <button mat-raised-button color="primary">{{lang.print}}</button> - </span> + <span color="primary" + style="flex:1;font-size: 20px;font-weight: bold;padding: 10px;">{{lang.separators}}</span> </div> - <pdf-viewer class="viewSep" [src]="docUrl" [render-text]="false" [autoresize]="true" [original-size]="false" - [show-all]="true"></pdf-viewer> + <pdf-viewer class="viewSep" [src]="this.docBuffer" [render-text]="false" [autoresize]="true" + [original-size]="false" [show-all]="true"></pdf-viewer> </mat-sidenav> </mat-sidenav-container> \ No newline at end of file diff --git a/src/frontend/app/separator/print-separator/print-separator.component.ts b/src/frontend/app/separator/print-separator/print-separator.component.ts index ece37654ce99f0e8d25424a3c18c5f10de28f266..531176163dcee92150c4514764ec4d16fc340c01 100644 --- a/src/frontend/app/separator/print-separator/print-separator.component.ts +++ b/src/frontend/app/separator/print-separator/print-separator.component.ts @@ -7,18 +7,23 @@ import { MatSidenav } from '@angular/material'; declare function $j(selector: any): any; +declare var angularGlobals: any; @Component({ templateUrl: "print-separator.component.html", styleUrls: ['print-separator.component.scss'], + providers: [NotificationService], }) export class PrintSeparatorComponent implements OnInit { + mobileMode: boolean = false; lang: any = LANG; entities: any[] = []; entitiesChosen: any[] = []; loading: boolean = false; docUrl: string = ''; + docData: string = ''; + docBuffer: ArrayBuffer = null; separatorTypes: string [] = ['barcode', 'qrcode']; separatorTargets: string [] = ['entities', 'generic']; @@ -31,7 +36,8 @@ export class PrintSeparatorComponent implements OnInit { @ViewChild('snav') sidenavLeft: MatSidenav; @ViewChild('snav2') sidenavRight: MatSidenav; - constructor(public http: HttpClient, private headerService: HeaderService) { + constructor(public http: HttpClient, private notify: NotificationService, private headerService: HeaderService) { + this.mobileMode = angularGlobals.mobileMode; (<any>window).pdfWorkerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.min.js'; } @@ -55,9 +61,18 @@ export class PrintSeparatorComponent implements OnInit { loadEntities() { setTimeout(() => { - $j('#jstree').jstree({ + $j('#jstree') + .on('select_node.jstree', (e: any, data: any) => { + this.separator.entities = $j('#jstree').jstree(true).get_checked(); // to trigger disable button if no entities + if (data.event) { + data.instance.select_node(data.node.children_d); + } + }) + .on('deselect_node.jstree', (e: any, data: any) => { + this.separator.entities = $j('#jstree').jstree(true).get_checked(); // to trigger disable button if no entities + }) + .jstree({ "checkbox": { - 'deselect_all': true, "three_state": false //no cascade selection }, 'core': { @@ -65,7 +80,6 @@ export class PrintSeparatorComponent implements OnInit { 'name': 'proton', 'responsive': true }, - 'multiple': true, 'data': this.entities, }, "plugins": ["checkbox", "search", "sort"] @@ -79,13 +93,6 @@ export class PrintSeparatorComponent implements OnInit { }, 250); }); $j('#jstree') - // listen for event - .on('select_node.jstree', (e: any, data: any) => { - this.generateSeparators(); - - }).on('deselect_node.jstree', (e: any, data: any) => { - this.generateSeparators(); - }) // create the instance .jstree(); }, 0); @@ -93,18 +100,31 @@ export class PrintSeparatorComponent implements OnInit { generateSeparators() { this.loading = true; - this.entitiesChosen = $j('#jstree').jstree(true).get_checked(); + this.separator.entities = $j('#jstree').jstree(true).get_checked(); + this.http.post("../../rest/entitySeparators", this.separator) + .subscribe((data: any) => { + this.docData = data; + this.docBuffer = this.base64ToArrayBuffer(this.docData); + this.downloadSeparators(); + this.loading = false; + }, (err: any) => { + this.notify.handleErrors(err); + }); + } - if (this.entitiesChosen.length > 0) { - this.docUrl = '../../rest/res/100/content'; - } else { - this.docUrl = ''; + base64ToArrayBuffer(base64: any) { + var binary_string = window.atob(base64); + var len = binary_string.length; + var bytes = new Uint8Array( len ); + for (var i = 0; i < len; i++) { + bytes[i] = binary_string.charCodeAt(i); } + return bytes.buffer; } changeType(type: any) { + this.docBuffer = null; if (type.value == 'entities') { - this.docUrl = ''; this.entities.forEach(entity => { entity.state.disabled = false; }); @@ -118,8 +138,44 @@ export class PrintSeparatorComponent implements OnInit { $j('#jstree').jstree(true).settings.core.data = this.entities; $j('#jstree').jstree('deselect_all'); $j('#jstree').jstree("refresh"); - this.sidenavRight.open(); - this.generateSeparators(); } } + + downloadSeparators() { + + const url = this.docUrl; + this.http.get(url, { + responseType: 'blob' + }).subscribe( + (response) => { + const a = document.createElement('a'); + document.body.appendChild(a); + a.style.display = 'none'; + + const url = `data:application/pdf;base64,${this.docData}`; + a.href = url; + + let today: any; + let dd: any; + let mm: any; + let yyyy: any; + + today = new Date(); + dd = today.getDate(); + mm = today.getMonth() + 1; + yyyy = today.getFullYear(); + + if (dd < 10) { + dd = '0' + dd; + } + if (mm < 10) { + mm = '0' + mm; + } + today = dd + '-' + mm + '-' + yyyy; + + a.download = this.lang.separators + "_" + today + ".pdf"; + a.click(); + window.URL.revokeObjectURL(url); + }); + } } diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts index 68cc8e42f05031007938dc63472f88de0900c057..06d74725d34ccb162cb67a986ae63758fed6f87d 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -997,6 +997,7 @@ export const LANG_EN = { "qrcode" : "QR code", "separatorType" : "Separator type", "separatorTarget" : "Separator target", - "print" : "print", + "generateAndDownload" : "Generate and download", "separators" : "Separator(s)", + "entityTreeInfoSeparator" : "Click on entity tree in order to generate the separator", }; diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index ae75c016dcad3a7db4bd26d12f9361ff971bdf3f..8758a8c576f938ef375b74883c4469e63d0e8817 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -1030,6 +1030,7 @@ export const LANG_FR = { "qrcode" : "QR code", "separatorType" : "Type de séparateur", "separatorTarget" : "Cible de séparateur", - "print" : "Imprimer", + "generateAndDownload" : "Générer et télécharger", "separators" : "Séparateur(s)", + "entityTreeInfoSeparator" : "Cliquez sur une entité de l'arborescence afin de l'ajouter à la génération des séparateurs", }; \ No newline at end of file diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts index f7d9f1ffc18edeac7876fb9b2ce2aeb05eb8f14f..a4d9d878133fb0eb9d403951f94fd35081160024 100755 --- a/src/frontend/lang/lang-nl.ts +++ b/src/frontend/lang/lang-nl.ts @@ -1024,6 +1024,7 @@ export const LANG_NL = { "qrcode" : "QR code", //_TO_TRANSLATE "separatorType" : "Separator type", //_TO_TRANSLATE "separatorTarget" : "Separator target", //_TO_TRANSLATE - "print" : "print", //_TO_TRANSLATE + "generateAndDownload" : "Generate and download", //_TO_TRANSLATE "separators" : "Separator(s)", //_TO_TRANSLATE + "entityTreeInfoSeparator" : "Click on entity tree in order to generate the separator", //_TO_TRANSLATE };