From c59641651c57462e09b187d5604f12b7df4d5281 Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Mon, 18 Oct 2021 08:34:37 +0300 Subject: [PATCH] RED-2491 RED-2330 --- .../file-preview-screen.component.ts | 41 +++++++++---------- .../services/annotation-actions.service.ts | 1 - .../services/annotation-draw.service.ts | 39 ++++++++++++++---- 3 files changed, 51 insertions(+), 30 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 53faa4da0..93a92d091 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 @@ -573,7 +573,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni this.addSubscription = timer(0, 5000).subscribe(async () => this.appStateService.reloadActiveFile()); this.addSubscription = this.appStateService.fileReanalysed$.subscribe(async (file: File) => { if (file.fileId === this.fileId) { - console.log('file', file); await this._loadFileData(!this._reloadFileOnReanalysis); this._reloadFileOnReanalysis = false; this._loadingService.stop(); @@ -621,9 +620,9 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni /* Get the documentElement () to display the page in fullscreen */ private _cleanupAndRedrawManualAnnotations() { - this._fileDownloadService.loadActiveFileRedactionLog().subscribe(redactionLogPreview => { + this._fileDownloadService.loadActiveFileRedactionLog().subscribe(async redactionLogPreview => { this.fileData.redactionLog = redactionLogPreview; - this._annotationDrawService.drawAnnotations( + await this._annotationDrawService.drawAnnotations( this._instance, this.annotationData.allAnnotations, this.hideSkipped, @@ -635,25 +634,25 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni private async _cleanupAndRedrawManualAnnotationsForEntirePage(page: number) { const currentPageAnnotations = this.annotations.filter(a => a.pageNumber === page); const currentPageAnnotationIds = currentPageAnnotations.map(a => a.id); - this.fileData.file = await this.appStateService.reloadActiveFile(); - this._fileDownloadService.loadActiveFileRedactionLog().subscribe(redactionLogPreview => { - this.fileData.redactionLog = redactionLogPreview; - this.rebuildFilters(); - if (this.viewMode === 'STANDARD') { - currentPageAnnotationIds.forEach(id => { - this._findAndDeleteAnnotation(id); - }); - const newPageAnnotations = this.annotations.filter(item => item.pageNumber === page); - this._handleDeltaAnnotationFilters(currentPageAnnotations, newPageAnnotations); - this._annotationDrawService.drawAnnotations( - this._instance, - newPageAnnotations, - this.hideSkipped, - this.viewerComponent.utils.isCompareMode, - ); - } - }); + this.fileData.file = await this.appStateService.reloadActiveFile(); + this.fileData.redactionLog = await this._fileDownloadService.loadActiveFileRedactionLog().toPromise(); + + this.rebuildFilters(); + + if (this.viewMode === 'STANDARD') { + currentPageAnnotationIds.forEach(id => { + this._findAndDeleteAnnotation(id); + }); + const newPageAnnotations = this.annotations.filter(item => item.pageNumber === page); + this._handleDeltaAnnotationFilters(currentPageAnnotations, newPageAnnotations); + await this._annotationDrawService.drawAnnotations( + this._instance, + newPageAnnotations, + this.hideSkipped, + this.viewerComponent.utils.isCompareMode, + ); + } } private _handleDeltaAnnotationFilters(currentPageAnnotations: AnnotationWrapper[], newPageAnnotations: AnnotationWrapper[]) { diff --git a/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts index 6dc69210d..291f42c10 100644 --- a/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/annotation-actions.service.ts @@ -126,7 +126,6 @@ export class AnnotationActionsService { annotations: AnnotationWrapper[], annotationsChanged: EventEmitter, ): Record[] { - console.log('============ get actions'); const availableActions = []; const annotationPermissions = annotations.map(annotation => ({ diff --git a/apps/red-ui/src/app/modules/dossier/services/annotation-draw.service.ts b/apps/red-ui/src/app/modules/dossier/services/annotation-draw.service.ts index b21a14aa0..2e1b22449 100644 --- a/apps/red-ui/src/app/modules/dossier/services/annotation-draw.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/annotation-draw.service.ts @@ -7,6 +7,7 @@ import { AnnotationWrapper } from '@models/file/annotation.wrapper'; import { UserPreferenceService } from '@services/user-preference.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { RedactionLogService } from './redaction-log.service'; +import { environment } from '../../../../environments/environment'; import Annotation = Core.Annotations.Annotation; @Injectable() @@ -18,23 +19,45 @@ export class AnnotationDrawService { private readonly _userPreferenceService: UserPreferenceService, ) {} - drawAnnotations(activeViewer: WebViewerInstance, annotationWrappers: AnnotationWrapper[], hideSkipped = false, compareMode = false) { + async drawAnnotations( + activeViewer: WebViewerInstance, + annotationWrappers: AnnotationWrapper[], + hideSkipped = false, + compareMode = false, + ) { if (!activeViewer) { return; } + + const pdfNet = activeViewer.Core.PDFNet; + + await pdfNet.runWithCleanup( + async () => { + await this._drawAnnotations(activeViewer, annotationWrappers, hideSkipped, compareMode); + }, + environment.licenseKey ? atob(environment.licenseKey) : null, + ); + } + + private async _drawAnnotations( + activeViewer: WebViewerInstance, + annotationWrappers: AnnotationWrapper[], + hideSkipped = false, + compareMode = false, + ) { const annotations = annotationWrappers.map(annotation => this._computeAnnotation(activeViewer, annotation, hideSkipped, compareMode), ); const annotationManager = activeViewer.Core.annotationManager; annotationManager.addAnnotations(annotations, { imported: true }); - annotationManager.drawAnnotationsFromList(annotations); + await annotationManager.drawAnnotationsFromList(annotations); if (this._userPreferenceService.areDevFeaturesEnabled) { - this._redactionLogService + const sectionsGrid = await this._redactionLogService .getSectionGrid(this._dossiersService.activeDossierId, this._appStateService.activeFileId) - .subscribe(sectionGrid => { - this._drawSections(activeViewer, sectionGrid); - }); + .toPromise() + .catch(() => ({ rectanglesPerPage: {} })); + await this._drawSections(activeViewer, sectionsGrid); } } @@ -73,7 +96,7 @@ export class AnnotationDrawService { return new activeViewer.Core.Math.Quad(x1, y1, x2, y2, x3, y3, x4, y4); } - private _drawSections(activeViewer: WebViewerInstance, sectionGrid: SectionGrid) { + private async _drawSections(activeViewer: WebViewerInstance, sectionGrid: SectionGrid) { const sections = []; for (const page of Object.keys(sectionGrid.rectanglesPerPage)) { const sectionRectangles: SectionRectangle[] = sectionGrid.rectanglesPerPage[page]; @@ -86,7 +109,7 @@ export class AnnotationDrawService { } const annotationManager = activeViewer.Core.annotationManager; annotationManager.addAnnotations(sections, { imported: true }); - annotationManager.drawAnnotationsFromList(sections); + await annotationManager.drawAnnotationsFromList(sections); } private _computeSection(activeViewer: WebViewerInstance, pageNumber: number, sectionRectangle: SectionRectangle) {