diff --git a/src/frontend/app/viewer/document-viewer.component.html b/src/frontend/app/viewer/document-viewer.component.html index 6468dbaa6142ac31c1964fc700ab5f747fe1a5a3..2d60fec99c38d3925eb940767be639f10e4c813d 100644 --- a/src/frontend/app/viewer/document-viewer.component.html +++ b/src/frontend/app/viewer/document-viewer.component.html @@ -43,7 +43,24 @@ <div style="display: block;width:100%;" appUploadFileDragDrop (onFileDropped)="dndUploadFile($event)" [disabled]="!editMode"> <div *ngIf="!loading && file.content !== null && !hideTools" class="viewer-tools"> - <button mat-icon-button (click)="downloadOriginalFile()" [matTooltip]="'lang.downloadOriginalFile' | translate"> + <!-- Download original file with pdf or docx format --> + <ng-container *ngIf="status === 'SIGN'"> + <button mat-icon-button [matMenuTriggerFor]="menuOptions"> + <mat-icon class="fa fa-download"></mat-icon> + </button> + <mat-menu #menuOptions="matMenu" [class]="'optionsListMenu'"> + <button mat-menu-item (click)="downloadOriginalFile('docx')"> + <mat-icon color="primary" class="fas fa-file-word"></mat-icon> + <span>{{'lang.docxFormat' | translate}}</span> + </button> + <button mat-menu-item (click)="downloadOriginalFile('pdf')"> + <mat-icon color="primary" class="fas fa-file-pdf"></mat-icon> + <span>{{'lang.pdfFormat' | translate}}</span> + </button> + </mat-menu> + </ng-container> + <!-- --> + <button *ngIf="status !== 'SIGN'" mat-icon-button (click)="downloadOriginalFile()" [matTooltip]="'lang.downloadOriginalFile' | translate"> <mat-icon class="fa fa-download"></mat-icon> </button> <ng-container *ngIf="editMode && resId !== null && !noConvertedFound"> diff --git a/src/frontend/app/viewer/document-viewer.component.ts b/src/frontend/app/viewer/document-viewer.component.ts index 716f0e8ff3f9a10f1cbcab3032ed90f755cc69c5..a93a3b1140cb4b981da0d419adc37d6db8ebcf92 100755 --- a/src/frontend/app/viewer/document-viewer.component.ts +++ b/src/frontend/app/viewer/document-viewer.component.ts @@ -88,6 +88,10 @@ export class DocumentViewerComponent implements OnInit, OnDestroy { */ @Input() attachType: string = null; + /** + * Original file version + */ + @Input() version: number; /** * Event emitter */ @@ -161,6 +165,8 @@ export class DocumentViewerComponent implements OnInit, OnDestroy { docToUploadValue: any; + status: string = ''; + constructor( public translate: TranslateService, public http: HttpClient, @@ -582,17 +588,12 @@ export class DocumentViewerComponent implements OnInit, OnDestroy { } } - downloadOriginalFile() { + downloadOriginalFile(type: string = '') { const downloadLink = document.createElement('a'); - if (this.file.contentMode === 'base64') { - downloadLink.href = `data:${this.file.type};base64,${this.file.content}`; - downloadLink.setAttribute('download', this.file.name); - document.body.appendChild(downloadLink); - downloadLink.click(); - } else { - this.http.get(this.file.content).pipe( + if (type === 'docx' && this.file.content.includes('base64')) { + this.http.get(`../rest/resources/${this.resId}/content/${this.version}?type=SIGN`).pipe( tap((data: any) => { - downloadLink.href = `data:${data.mimeType};base64,${data.encodedDocument}`; + downloadLink.href = `data:application/docx;base64,${data.encodedDocument}`; downloadLink.setAttribute('download', data.filename); document.body.appendChild(downloadLink); downloadLink.click(); @@ -602,6 +603,26 @@ export class DocumentViewerComponent implements OnInit, OnDestroy { return of(false); }) ).subscribe(); + } else { + if (this.file.contentMode === 'base64') { + downloadLink.href = `data:${this.file.type};base64,${this.file.content}`; + downloadLink.setAttribute('download', this.file.name); + document.body.appendChild(downloadLink); + downloadLink.click(); + } else { + this.http.get(this.file.content).pipe( + tap((data: any) => { + downloadLink.href = `data:${data.mimeType};base64,${data.encodedDocument}`; + downloadLink.setAttribute('download', data.filename); + document.body.appendChild(downloadLink); + downloadLink.click(); + }), + catchError((err: any) => { + this.notify.handleSoftErrors(err); + return of(false); + }) + ).subscribe(); + } } } @@ -729,6 +750,10 @@ export class DocumentViewerComponent implements OnInit, OnDestroy { commentedDocVersions: commentedDocVersions, mainDocPDFVersions: mainDocPDFVersions }; + + if (!this.functions.empty(this.version)) { + this.status = data.SIGN.find((id: any) => id === this.version) !== undefined && data.DOC.find((id: any) => id === this.version) !== undefined ? 'SIGN' : ''; + } }), exhaustMap(() => this.http.get(`../rest/resources/${this.resId}/fileInformation`)), tap((data: any) => { @@ -1205,15 +1230,23 @@ export class DocumentViewerComponent implements OnInit, OnDestroy { } openResourceVersion(version: number, type: string) { - const title = type !== 'PDF' ? this.translate.instant('lang.' + type + '_version') : `${this.translate.instant('lang.version')} ${version}`; - // TO SHOW ORIGINAL DOC (because autoload signed doc) type = type === 'SIGN' ? 'PDF' : type; this.http.get(`../rest/resources/${this.resId}/content/${version}?type=${type}`).pipe( tap((data: any) => { - this.dialog.open(DocumentViewerModalComponent, { autoFocus: false, panelClass: 'maarch-full-height-modal', data: { title: `${title}`, base64: data.encodedDocument, filename: data.filename } }); + this.dialog.open(DocumentViewerModalComponent, { + autoFocus: false, + panelClass: 'maarch-full-height-modal', + data: { + title: `${title}`, + base64: data.encodedDocument, + filename: data.filename, + version: version, + resId: this.resId + } + }); }), catchError((err: any) => { this.notify.handleSoftErrors(err); diff --git a/src/frontend/app/viewer/modal/document-viewer-modal.component.html b/src/frontend/app/viewer/modal/document-viewer-modal.component.html index de9a4b8dec6e91dac694f851cbe5e5669d0ca01b..62eb10e9dfdf87afaadd55fa412e6b3749c6d044 100755 --- a/src/frontend/app/viewer/modal/document-viewer-modal.component.html +++ b/src/frontend/app/viewer/modal/document-viewer-modal.component.html @@ -6,7 +6,8 @@ </button> </h1> <mat-dialog-content> - <app-document-viewer #appDocumentViewer style="height:100%;width:100%;" [editMode]="false" [base64]="data.base64" [title]="data.title" [filename]="data.filename"> + <app-document-viewer #appDocumentViewer style="height:100%;width:100%;" [editMode]="false" [base64]="data.base64" + [title]="data.title" [filename]="data.filename" [version]="data.version" [resId]="data.resId"> </app-document-viewer> </mat-dialog-content> </div> diff --git a/src/lang/lang-en.json b/src/lang/lang-en.json index c6d0c4ca5a8a79d3304c224c45f5554ececa0732..b4832da6cecf45416b9d817653ef6e5b9acaf13e 100644 --- a/src/lang/lang-en.json +++ b/src/lang/lang-en.json @@ -2529,5 +2529,7 @@ "getProcessLimitDate": "Processing deadline", "getProcessLimitDateSample": "<b color=\"warn\">3 day(s)</b>", "getCreationDate": "Creation date", - "getCreationDateSample": "Jan. 1st" + "getCreationDateSample": "Jan. 1st", + "docxFormat": "DOCX format", + "pdfFormat": "PDF format" } diff --git a/src/lang/lang-fr.json b/src/lang/lang-fr.json index aed1318954afb6307ee221dbed775e4b843beea6..baf75c65046668f4012aa8995185b6fc2677ba7d 100644 --- a/src/lang/lang-fr.json +++ b/src/lang/lang-fr.json @@ -2524,5 +2524,7 @@ "getProcessLimitDate": "Date limite de traitement", "getProcessLimitDateSample": "<b color=\"warn\">3 jour(s)</b>", "getCreationDate": "Date de création", - "getCreationDateSample": "1er janv." + "getCreationDateSample": "1er janv.", + "docxFormat": "Format DOCX", + "pdfFormat": "Format PDF" }