diff --git a/src/frontend/app/viewer/document-viewer.component.html b/src/frontend/app/viewer/document-viewer.component.html index 5bdf8a2809e1677213f86a8af4b3f44d773b5d96..79892f95e31ff0796dc3928898a6d2a9f798062d 100644 --- a/src/frontend/app/viewer/document-viewer.component.html +++ b/src/frontend/app/viewer/document-viewer.component.html @@ -90,7 +90,7 @@ [sidenavLeft]="sidenavLeft" [editMode]="true" (triggerAfterUpdatedDoc)="triggerEvent.emit()" (triggerCloseEditor)="closeEditor()" (triggerModifiedDocument)="isDocModified = true"></onlyoffice-viewer> </ng-container> -<button mat-fab *ngIf="isDocModified && mode === 'mainDocument'" color="accent" - [title]="lang.saveModifications" style="position: absolute;z-index: 1;bottom: 40px;right: 60px;"> +<button mat-fab *ngIf="isDocModified && mode === 'mainDocument' && resId !== null" color="accent" + [title]="lang.saveModifications" style="position: absolute;z-index: 1;bottom: 40px;right: 60px;" (click)="saveMainDocument()"> <mat-icon style="height:auto;font-size:20px;" class="fas fa-check"></mat-icon> </button> \ No newline at end of file diff --git a/src/frontend/app/viewer/document-viewer.component.ts b/src/frontend/app/viewer/document-viewer.component.ts index f85ed020d07f4188ab15da2c1f2b3390763a896c..d3e44333087d13d2a078cbf0a24032f874606886 100644 --- a/src/frontend/app/viewer/document-viewer.component.ts +++ b/src/frontend/app/viewer/document-viewer.component.ts @@ -512,6 +512,7 @@ export class DocumentViewerComponent implements OnInit { (data: any) => { if (data.encodedDocument) { this.file.contentMode = 'route'; + this.file.format = data.originalFormat; this.file.content = `../../rest/attachments/${resId}/originalContent`; this.file.contentView = `../../rest/attachments/${resId}/content?mode=view`; this.file.src = this.base64ToArrayBuffer(data.encodedDocument); @@ -538,8 +539,9 @@ export class DocumentViewerComponent implements OnInit { (data: any) => { if (data.encodedDocument) { this.file.contentMode = 'route'; + this.file.format = data.originalFormat; this.file.content = `../../rest/resources/${resId}/originalContent`; - this.file.contentView = `../../rest/resources/${resId}/content?mode=view` + this.file.contentView = `../../rest/resources/${resId}/content?mode=view`; this.file.src = this.base64ToArrayBuffer(data.encodedDocument); this.loading = false; } @@ -584,6 +586,8 @@ export class DocumentViewerComponent implements OnInit { this.triggerEvent.emit(); const template = this.listTemplates.filter(template => template.id === templateId)[0]; + this.file.format = template.extension; + if (this.editor.mode === 'onlyoffice') { this.editor.async = false; @@ -668,7 +672,7 @@ export class DocumentViewerComponent implements OnInit { this.editor.async = false; this.editor.options = { objectType: 'resourceModification', - objectId: 1, + objectId: this.resId, docUrl: `rest/onlyOffice/mergedFile` }; this.editInProgress = true; @@ -855,11 +859,12 @@ export class DocumentViewerComponent implements OnInit { map((data: any) => { const formatdatas = { encodedFile: data.content, - format: data.format + format: data.format, + resId: this.resId } - return formatdatas + return formatdatas; }), - exhaustMap((data) => this.http.put(`../../rest/resources/${this.resId}?onlyDocument=true`, { encodedResource: data })), + exhaustMap((data) => this.http.put(`../../rest/resources/${this.resId}?onlyDocument=true`, data )), tap(() => { this.closeEditor(); this.loadRessource(this.resId); diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts index 19da929fa4d4562ec207eaaf3d6d30ffff52f6c8..1c69171aebc61dc0a4ff42fe894c26fa9f512e0f 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -1469,6 +1469,8 @@ export const LANG_EN = { "chooseBAN": "Choose a BAN", "click": "Click", "inSignatureBook_doc" : "Put the main document in signature book", - "inShipping_doc" : "Intégrer le document principal in send Maileva", + "inShipping_doc" : "Put the main document in send Maileva", "preRequisiteMissing": "Prerequisite missing for OnlyOffice : netcat", + "onlyofficeEditDenied": "This document with extension", + "onlyofficeEditDenied2": "can't be edited with onlyoffice", }; diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index 63cfe6274321f8ff1280d8a98a79e6211512c71a..0a7b733add783e1b40fc1c8203366efa0ae9ac8c 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -1510,4 +1510,6 @@ export const LANG_FR = { "inSignatureBook_doc" : "Intégrer le document principal au parapheur", "inShipping_doc" : "Intégrer le document principal à l'envoi Maileva", "preRequisiteMissing": "Prérequis manquant pour OnlyOffice : netcat", + "onlyofficeEditDenied": "Le document avec l'extension", + "onlyofficeEditDenied2": "ne peut pas être édité avec onlyoffice", }; diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts index 84be4842b771810aff3c640e087066b52141653b..3338f37eabe74eafe0634c5fec7209b3adee6d80 100755 --- a/src/frontend/lang/lang-nl.ts +++ b/src/frontend/lang/lang-nl.ts @@ -1496,4 +1496,6 @@ export const LANG_NL = { "inSignatureBook_doc" : "Put the main document in signature book", //_TO_TRANSLATE "inShipping_doc" : "Intégrer le document principal in send Maileva", //_TO_TRANSLATE "preRequisiteMissing": "Prerequisite missing for OnlyOffice : netcat", //_TO_TRANSLATE + "onlyofficeEditDenied": "This document with extension", //_TO_TRANSLATE + "onlyofficeEditDenied2": "can't be edited with onlyoffice", //_TO_TRANSLATE }; diff --git a/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts b/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts index 97ecc01cc69da0751d2afa3bbbff1d1e61478d28..8c7fc29920d9d8a99fecac59be041ce2f4ddbad3 100644 --- a/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts +++ b/src/frontend/plugins/onlyoffice-api-js/onlyoffice-viewer.component.ts @@ -52,7 +52,18 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit { tmpFilename: string = ''; appUrl: string = ''; - onlyfficeUrl: string = ''; + onlyOfficeUrl: string = ''; + + allowedExtension: string[] = [ + "doc", + "docx", + "dotx", + "odt", + "ott", + "rtf", + "txt", + "html" + ]; private eventAction = new Subject<any>(); dialogRef: MatDialogRef<any>; @@ -86,7 +97,7 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit { closeEditor() { console.log('close'); - + if (this.sidenavLeft !== null) { this.sidenavLeft.open(); } @@ -127,15 +138,27 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit { async ngOnInit() { this.key = this.generateUniqueId(); - await this.getServerConfiguration(); - - await this.checkServerStatus(); - - await this.getMergedFileTemplate(); + if (this.canLaunchOnlyOffice()) { + await this.getServerConfiguration(); - this.initOfficeEditor(); - - this.loading = false; + await this.checkServerStatus(); + + await this.getMergedFileTemplate(); + + this.initOfficeEditor(); + + this.loading = false; + } + } + + canLaunchOnlyOffice() { + if (this.isAllowedEditExtension(this.file.format)) { + return true; + } else { + this.notify.error(this.lang.onlyofficeEditDenied + ' <b>' + this.file.format + '</b> ' + this.lang.onlyofficeEditDenied2); + this.closeEditor(); + return false; + } } getServerConfiguration() { @@ -145,7 +168,7 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit { if (data.enabled) { const protocol = data.serverSsl ? 'https://' : 'http://'; const port = data.serverPort ? `:${data.serverPort}` : ':80'; - this.onlyfficeUrl = `${protocol}${data.serverUri}${port}`; + this.onlyOfficeUrl = `${protocol}${data.serverUri}${port}`; this.appUrl = data.coreUrl; resolve(true); } else { @@ -175,7 +198,7 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit { if (data.isAvailable) { resolve(true); } else { - this.notify.error(`${this.lang.errorOnlyoffice2} ${this.onlyfficeUrl}`); + this.notify.error(`${this.lang.errorOnlyoffice2} ${this.onlyOfficeUrl}`); this.closeEditor(); } }), @@ -266,7 +289,7 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit { }, }, }; - this.docEditor = new DocsAPI.DocEditor('placeholder', this.editorConfig, this.onlyfficeUrl); + this.docEditor = new DocsAPI.DocEditor('placeholder', this.editorConfig, this.onlyOfficeUrl); } isLocked() { @@ -304,4 +327,8 @@ export class EcplOnlyofficeViewerComponent implements OnInit, AfterViewInit { } this.fullscreenMode = !this.fullscreenMode; } + + isAllowedEditExtension(extension: string) { + return this.allowedExtension.filter(ext => ext.toLowerCase() === extension.toLowerCase()).length > 0; + } }