From 355b197220cbe90dddec64c06d5279683b3340dc Mon Sep 17 00:00:00 2001 From: Timo Bejan Date: Tue, 27 Oct 2020 23:57:34 +0200 Subject: [PATCH] added throttle and handling for missing annotations --- .../file-preview-screen.component.ts | 7 +++---- .../screens/file/pdf-viewer/pdf-viewer.component.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts index a150195aa..65054dc32 100644 --- a/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/screens/file/file-preview-screen/file-preview-screen.component.ts @@ -5,14 +5,14 @@ import { HostListener, NgZone, OnInit, - ViewChild + ViewChild, + EventEmitter } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; import { DictionaryControllerService, ManualRedactionEntry, - ReanalysisControllerService, - TypeValue + ReanalysisControllerService } from '@redaction/red-ui-http'; import { AppStateService } from '../../../state/app-state.service'; import { Annotations, WebViewerInstance } from '@pdftron/webviewer'; @@ -461,7 +461,6 @@ export class FilePreviewScreenComponent implements OnInit { } handleAnnotationsAdded(annotations: Annotations.Annotation[]) { - // handle comments annotations.forEach((a) => { a['comments'] = a['Mi'] ? a['Mi'].map((m) => { diff --git a/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts b/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts index 07a126c3e..76fef7b8b 100644 --- a/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts +++ b/apps/red-ui/src/app/screens/file/pdf-viewer/pdf-viewer.component.ts @@ -15,6 +15,8 @@ import { FileStatus, ManualRedactionEntry, Rectangle } from '@redaction/red-ui-h import WebViewer, { Annotations, WebViewerInstance } from '@pdftron/webviewer'; import { TranslateService } from '@ngx-translate/core'; import { FileDownloadService } from '../service/file-download.service'; +import { Subject } from 'rxjs'; +import { throttleTime } from 'rxjs/operators'; export interface ViewerState { displayMode?: any; @@ -33,6 +35,7 @@ export interface ViewerState { }) export class PdfViewerComponent implements OnInit, AfterViewInit, OnChanges { private _viewerState: ViewerState = null; // no initial state + private _annotationEventDebouncer = new Subject(); @Input() fileData: Blob; @Input() fileStatus: FileStatus; @@ -59,6 +62,12 @@ export class PdfViewerComponent implements OnInit, AfterViewInit, OnChanges { ngOnInit() { this._restoreViewerState = this._restoreViewerState.bind(this); + // always publish all existing annotations this way everything gets drawn always + this._annotationEventDebouncer + .pipe(throttleTime(300)) + .subscribe((value) => + this.annotationsAdded.emit(this.instance.annotManager.getAnnotationsList()) + ); } ngOnChanges(changes: SimpleChanges): void { @@ -87,7 +96,7 @@ export class PdfViewerComponent implements OnInit, AfterViewInit, OnChanges { this._configureHeader(); instance.annotManager.on('annotationChanged', (annotations, action) => { if (action === 'add') { - this.annotationsAdded.emit(annotations); + this._annotationEventDebouncer.next(annotations); } });