From a24edcfa60ee13ec703124fd3b0abbacae8f5ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Mon, 11 Apr 2022 15:25:17 +0300 Subject: [PATCH] RED-3738: Removed selectAnnotations event emitter --- .../annotations-list.component.ts | 3 +- .../file-workload.component.html | 3 +- .../file-workload/file-workload.component.ts | 25 +++++----- .../file-preview-screen.component.html | 1 - .../file-preview-screen.component.ts | 10 ---- .../services/pdf-viewer.service.ts | 50 ++++++++++++------- libs/common-ui | 2 +- 7 files changed, 47 insertions(+), 47 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts b/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts index 640fc46f2..50a23def5 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.ts @@ -32,7 +32,6 @@ export class AnnotationsListComponent extends HasScrollbarDirective implements O @Input() activeViewerPage: number; @Output() readonly pagesPanelActive = new EventEmitter(); - @Output() readonly selectAnnotations = new EventEmitter(); highlightGroups$ = new BehaviorSubject([]); @@ -82,7 +81,7 @@ export class AnnotationsListComponent extends HasScrollbarDirective implements O if (canMultiSelect && ($event?.ctrlKey || $event?.metaKey) && this._listingService.selected.length > 0) { this._multiSelectService.activate(); } - this.selectAnnotations.emit([annotation]); + this._pdf.selectAnnotations([annotation]); } } diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html index e8b918261..55cbdb3e3 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html @@ -48,7 +48,7 @@
@@ -213,7 +213,6 @@ ; @Input() file!: File; @Input() annotationActionsTemplate: TemplateRef; - @Output() readonly selectAnnotations = new EventEmitter(); @Output() readonly selectPage = new EventEmitter(); displayedPages: number[] = []; pagesPanelActive = true; @@ -78,7 +77,7 @@ export class FileWorkloadComponent { readonly fileDataService: FileDataService, readonly viewModeService: ViewModeService, readonly listingService: ListingService, - private readonly _pdf: PdfViewer, + readonly pdf: PdfViewer, private readonly _changeDetectorRef: ChangeDetectorRef, private readonly _annotationProcessingService: AnnotationProcessingService, ) { @@ -122,7 +121,7 @@ export class FileWorkloadComponent { return this.multiSelectService.inactive$.pipe( tap(value => { if (value) { - this.selectAnnotations.emit(); + this.pdf.selectAnnotations(); } }), shareDistinctLast(), @@ -167,11 +166,11 @@ export class FileWorkloadComponent { } selectAllOnActivePage() { - this.selectAnnotations.emit(this.activeAnnotations); + this.pdf.selectAnnotations(this.activeAnnotations); } deselectAllOnActivePage(): void { - this._pdf.deselectAnnotations(this.activeAnnotations); + this.pdf.deselectAnnotations(this.activeAnnotations); } @HostListener('window:keyup', ['$event']) @@ -279,18 +278,18 @@ export class FileWorkloadComponent { if (!this._firstSelectedAnnotation || this.activeViewerPage !== this._firstSelectedAnnotation.pageNumber) { if (this.displayedPages.indexOf(this.activeViewerPage) !== -1) { // Displayed page has annotations - return this.selectAnnotations.emit(this.activeAnnotations ? [this.activeAnnotations[0]] : null); + return this.pdf.selectAnnotations(this.activeAnnotations ? [this.activeAnnotations[0]] : null); } // Displayed page doesn't have annotations if ($event.key === 'ArrowDown') { const nextPage = this._nextPageWithAnnotations(); - this.selectAnnotations.emit([this.displayedAnnotations.get(nextPage)[0]]); + this.pdf.selectAnnotations([this.displayedAnnotations.get(nextPage)[0]]); return; } const prevPage = this._prevPageWithAnnotations(); const prevPageAnnotations = this.displayedAnnotations.get(prevPage); - this.selectAnnotations.emit([prevPageAnnotations[prevPageAnnotations.length - 1]]); + this.pdf.selectAnnotations([prevPageAnnotations[prevPageAnnotations.length - 1]]); return; } @@ -304,13 +303,13 @@ export class FileWorkloadComponent { if ($event.key === 'ArrowDown') { if (idx + 1 !== annotationsOnPage.length) { // If not last item in page - this.selectAnnotations.emit([annotationsOnPage[idx + 1]]); + this.pdf.selectAnnotations([annotationsOnPage[idx + 1]]); } else if (nextPageIdx < this.displayedPages.length) { // If not last page for (let i = nextPageIdx; i < this.displayedPages.length; i++) { const nextPageAnnotations = this.displayedAnnotations.get(this.displayedPages[i]); if (nextPageAnnotations) { - this.selectAnnotations.emit([nextPageAnnotations[0]]); + this.pdf.selectAnnotations([nextPageAnnotations[0]]); break; } } @@ -320,7 +319,7 @@ export class FileWorkloadComponent { if (idx !== 0) { // If not first item in page - return this.selectAnnotations.emit([annotationsOnPage[idx - 1]]); + return this.pdf.selectAnnotations([annotationsOnPage[idx - 1]]); } if (pageIdx) { @@ -328,7 +327,7 @@ export class FileWorkloadComponent { for (let i = previousPageIdx; i >= 0; i--) { const prevPageAnnotations = this.displayedAnnotations.get(this.displayedPages[i]); if (prevPageAnnotations) { - this.selectAnnotations.emit([prevPageAnnotations[prevPageAnnotations.length - 1]]); + this.pdf.selectAnnotations([prevPageAnnotations[prevPageAnnotations.length - 1]]); break; } } @@ -376,7 +375,7 @@ export class FileWorkloadComponent { this.displayedPages.indexOf(this.activeViewerPage) >= 0 && this.activeAnnotations.length > 0 ) { - this.selectAnnotations.emit([this.activeAnnotations[0]]); + this.pdf.selectAnnotations([this.activeAnnotations[0]]); } } diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html index 49de602a9..28f4c98d6 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html @@ -87,7 +87,6 @@ , private readonly _logger: NGXLogger, ) { this.documentLoaded$ = this.#documentLoaded$.asObservable().pipe( @@ -178,25 +181,15 @@ export class PdfViewer { this.annotationManager?.deselectAllAnnotations(); } - selectAnnotations(annotations: AnnotationWrapper[], multiSelectActive: boolean = false) { - if (!annotations) { - return; - } - - const filteredAnnotations = annotations.filter(a => !!a); - - if (!filteredAnnotations.length) { - return; - } - - if (!multiSelectActive) { + selectAnnotations(annotations?: AnnotationWrapper[]) { + if (annotations) { + const annotationsToSelect = this._multiSelectService.isActive + ? [...this._listingService.selected, ...annotations] + : annotations; + this.#selectAnnotations(annotationsToSelect); + } else { this.deselectAllAnnotations(); } - - const annotationsFromViewer = this.getAnnotationsById(filteredAnnotations.map(a => a.id)); - - this.annotationManager.jumpToAnnotation(annotationsFromViewer[0]); - this.annotationManager.selectAnnotations(annotationsFromViewer); } deleteAnnotations(annotationsIds?: readonly string[]) { @@ -221,6 +214,27 @@ export class PdfViewer { this.annotationManager.deselectAnnotations(ann); } + #selectAnnotations(annotations?: AnnotationWrapper[]) { + if (!annotations) { + return; + } + + const filteredAnnotations = annotations.filter(a => !!a); + + if (!filteredAnnotations.length) { + return; + } + + if (!this._multiSelectService.isActive) { + this.deselectAllAnnotations(); + } + + const annotationsFromViewer = this.getAnnotationsById(filteredAnnotations.map(a => a.id)); + + this.annotationManager.jumpToAnnotation(annotationsFromViewer[0]); + this.annotationManager.selectAnnotations(annotationsFromViewer); + } + private _navigateToPage(pageNumber: number) { if (this._currentInternalPage !== pageNumber) { this.documentViewer.displayPageLocation(pageNumber, 0, 0); diff --git a/libs/common-ui b/libs/common-ui index 3c0d4368c..5adbd5342 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit 3c0d4368c70975255478d5ee038587c1ea97ecf8 +Subproject commit 5adbd5342fe94e2d1292054e7f0a8c6185b9420e