From 9d4aadbfb47d73a679a15963195bae344d4bc62b Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Wed, 19 Jan 2022 08:22:00 +0200 Subject: [PATCH] file preview screen --- .../file-preview-screen.component.ts | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index ed84d72ab..4ceadefd5 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -469,23 +469,27 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni const previousFile = this.fileData?.file; await this._loadFileData(file); - const fileHasBeenExcludedOrIncluded = previousFile?.excluded !== this.fileData?.file?.excluded; - const excludedPagesHaveChanged = JSON.stringify(previousFile?.excludedPages) !== JSON.stringify(this.fileData?.file?.excludedPages); - if (fileHasBeenExcludedOrIncluded || excludedPagesHaveChanged) { - await this._deleteAnnotations(); - await this._cleanupAndRedrawAnnotations(); + // file already loaded at least once + if (previousFile) { + // If it has been OCRd, we need to wait for it to load into the viewer + if (previousFile.lastOCRTime !== this.fileData?.file?.lastOCRTime) { + return; + } + // excluded pages or document exclusion has changed + const fileHasBeenExcludedOrIncluded = previousFile.excluded !== this.fileData.file.excluded; + const excludedPagesHaveChanged = + JSON.stringify(previousFile.excludedPages) !== JSON.stringify(this.fileData.file.excludedPages); + if (fileHasBeenExcludedOrIncluded || excludedPagesHaveChanged) { + await this._deleteAnnotations(); + await this._cleanupAndRedrawAnnotations(); + } } await this._stampPDF(); } private async _stampPDF() { - if (!this._instance) { - return; - } - - const document = this._instance.Core.documentViewer.getDocument(); - if (!document) { + if (!this._instance?.Core.documentViewer.getDocument()) { return; } @@ -623,6 +627,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } private _deleteAnnotations(annotationsToDelete?: AnnotationWrapper[]) { + if (!this._instance?.Core.documentViewer.getDocument()) { + return; + } + if (!annotationsToDelete) { this._instance.Core.annotationManager.deleteAnnotations(this._instance.Core.annotationManager.getAnnotationsList(), { imported: true, @@ -638,6 +646,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni currentAnnotations?: AnnotationWrapper[], newAnnotationsFilter?: (annotation: AnnotationWrapper) => boolean, ) { + if (!this._instance?.Core.documentViewer.getDocument()) { + return; + } + this.rebuildFilters(); if (this.viewModeService.viewMode === 'STANDARD') {