Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

fix(frontend:files): add support for dynamic editor naming in OnlyOffice components and error handling

johaven98031da3e6d6
diff --git a/frontend/src/app/applications/files/components/utils/only-office.component.ts b/frontend/src/app/applications/files/components/utils/only-office.component.ts
index 4ba2459b..6e432958 100644
--- a/frontend/src/app/applications/files/components/utils/only-office.component.ts
+++ b/frontend/src/app/applications/files/components/utils/only-office.component.ts
@@ -7,9 +7,10 @@ import loadScript from './only-office.utils'
template: '<div [id]="id"></div>'
})
export class OnlyOfficeComponent implements OnInit, OnChanges, OnDestroy {
- @Input() id: string
- @Input() documentServerUrl: string
- @Input() config: OnlyOfficeConfig
+ @Input({ required: true }) id: string
+ @Input({ required: true }) editorName: string
+ @Input({ required: true }) documentServerUrl: string
+ @Input({ required: true }) config: OnlyOfficeConfig
@Output() loadError = new EventEmitter<{ title: string; message: string }>()
@Output() wasSaved = new EventEmitter<string>()
private isFirstOnChanges = true
@@ -54,6 +55,7 @@ export class OnlyOfficeComponent implements OnInit, OnChanges, OnDestroy {
try {
if (!window.DocsAPI) {
this.onError(-3)
+ return
}
if (window?.DocEditor?.instances[this.id]) {
@@ -75,15 +77,15 @@ export class OnlyOfficeComponent implements OnInit, OnChanges, OnDestroy {
}
private onError(errorCode: number) {
- const error = { title: 'Unknown OnlyOffice error', message: `Code: ${errorCode}` }
+ const error = { title: `Unknown ${this.editorName} error`, message: `Code: ${errorCode}` }
switch (errorCode) {
case -2:
- error.title = 'Unable to load OnlyOffice editor'
+ error.title = `Unable to load ${this.editorName} editor`
error.message = 'The document server may be unreachable or the configuration is invalid'
break
case -3:
- error.title = 'OnlyOffice editor failed to initialize'
+ error.title = `${this.editorName} editor failed to initialize`
error.message = 'DocsAPI not available'
break
}
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.ts
index 58e5d32d..5d850984 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-only-office.component.ts
@@ -26,6 +26,7 @@ import { OnlyOfficeComponent } from '../utils/only-office.component'
<div [style.height.px]="currentHeight()">
<app-files-onlyoffice-document
[id]="docId"
+ [editorName]="officeEditorName"
[documentServerUrl]="documentConfig.documentServerUrl"
[config]="documentConfig.config"
(loadError)="loadError($event)"
@@ -44,6 +45,7 @@ export class FilesViewerOnlyOfficeComponent implements OnInit, OnDestroy {
private readonly http = inject(HttpClient)
private readonly layout = inject(LayoutService)
private readonly store = inject(StoreService)
+ protected readonly officeEditorName = this.store.server().files.editors.onlyoffice ? ONLY_OFFICE_APP_LOCK : EURO_OFFICE_APP_LOCK
ngOnInit() {
this.docId = `viewer-doc-${this.file().id}`
@@ -81,7 +83,11 @@ export class FilesViewerOnlyOfficeComponent implements OnInit, OnDestroy {
},
error: (e: HttpErrorResponse) => {
this.layout.closeDialog()
- this.layout.sendNotification('error', 'Unable to open document', e.status === 404 ? 'Unable to load OnlyOffice editor' : e.error.message)
+ this.layout.sendNotification(
+ 'error',
+ 'Unable to open document',
+ e.status === 404 ? `Unable to load ${this.officeEditorName} editor` : e.error.message
+ )
}
})
}