From ae2797f2b8fb09dd18462aec39887b687a66affc Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 15 Sep 2023 19:10:03 +0300 Subject: [PATCH] RED-7612 fix annotations selected when opened file --- .../annotation-wrapper.component.ts | 15 +++--- .../annotations-list.component.ts | 2 +- .../file-workload/file-workload.component.ts | 46 +++++++++---------- .../services/annotation-manager.service.ts | 1 - libs/common-ui | 2 +- 5 files changed, 32 insertions(+), 34 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotation-wrapper/annotation-wrapper.component.ts b/apps/red-ui/src/app/modules/file-preview/components/annotation-wrapper/annotation-wrapper.component.ts index 5ec1cb170..ce271befd 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotation-wrapper/annotation-wrapper.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/annotation-wrapper/annotation-wrapper.component.ts @@ -1,10 +1,10 @@ import { Component, HostBinding, inject, Input, OnChanges } from '@angular/core'; +import { getConfig } from '@iqser/common-ui'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; -import { PdfProxyService } from '../../services/pdf-proxy.service'; -import { ActionsHelpModeKeys } from '../../utils/constants'; import { ListItem } from '@models/file/list-item'; import { MultiSelectService } from '../../services/multi-select.service'; -import { getConfig } from '@iqser/common-ui'; +import { PdfProxyService } from '../../services/pdf-proxy.service'; +import { ActionsHelpModeKeys } from '../../utils/constants'; @Component({ selector: 'redaction-annotation-wrapper', @@ -12,14 +12,13 @@ import { getConfig } from '@iqser/common-ui'; styleUrls: ['./annotation-wrapper.component.scss'], }) export class AnnotationWrapperComponent implements OnChanges { - @Input({ required: true }) annotation!: ListItem; - - @HostBinding('attr.annotation-id') annotationId: string; - @HostBinding('class.active') active = false; - actionsHelpModeKey?: string; readonly #isDocumine = getConfig().IS_DOCUMINE; protected readonly _pdfProxyService = inject(PdfProxyService); protected readonly _multiSelectService = inject(MultiSelectService); + @Input({ required: true }) annotation!: ListItem; + @HostBinding('attr.annotation-id') annotationId: string; + @HostBinding('class.active') active = false; + actionsHelpModeKey?: string; ngOnChanges() { this.annotationId = this.annotation.item.id; 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 2abe4b8fe..1c53f1b14 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 @@ -24,7 +24,7 @@ export class AnnotationsListComponent extends HasScrollbarDirective implements O } return [] as EarmarkGroup[]; }); - @Input() annotations: ListItem[]; + @Input({ required: true }) annotations: ListItem[]; @Output() readonly pagesPanelActive = new EventEmitter(); constructor( diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts index 78dcd0814..8a2de4483 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.ts @@ -37,7 +37,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On @ViewChild('annotationsElement') private readonly _annotationsElement: ElementRef; @ViewChild('quickNavigation') private readonly _quickNavigationElement: ElementRef; readonly #isDocumine = getConfig().IS_DOCUMINE; - readonly #devMode = this._userPreferenceService.isIqserDevMode; + readonly #isIqserDevMode = this._userPreferenceService.isIqserDevMode; readonly iconButtonTypes = IconButtonTypes; readonly circleButtonTypes = CircleButtonTypes; displayedAnnotations = new Map(); @@ -96,14 +96,14 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On }); effect(() => { - const __ = this.viewModeService.viewMode(); + this.viewModeService.viewMode(); this._scrollViews(); }); effect( () => { if (this.excludedPagesService.shown()) { - this._disableMultiSelectAndDocumentInfo(); + this.#disableMultiSelectAndDocumentInfo(); } }, { allowSignalWrites: true }, @@ -130,8 +130,8 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On this._pageRotationService.rotations$, ]).pipe( delay(0), - map(([annotations, primary, secondary]) => this._filterAnnotations(annotations, primary, secondary)), - map(annotations => this._mapListItemsFromAnnotationWrapperArray(annotations)), + map(([annotations, primary, secondary]) => this.#filterAnnotations(annotations, primary, secondary)), + map(annotations => this.#mapListItemsFromAnnotationWrapperArray(annotations)), ); } @@ -196,7 +196,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On // selected annotation on this page and not in multi select mode if (!this.pagesPanelActive && this.multiSelectService.inactive()) { this._documentViewer.clearSelection(); - this._selectFirstAnnotationOnCurrentPageIfNecessary(); + this.#selectFirstAnnotationOnCurrentPageIfNecessary(); } this._changeDetectorRef.markForCheck(); return; @@ -209,7 +209,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On this.navigateAnnotations($event); } } else { - this._navigatePages($event); + this.#navigatePages($event); } this._changeDetectorRef.markForCheck(); @@ -247,7 +247,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On if (quickNavPageIndex === -1 || this.displayedPages[quickNavPageIndex] !== currentPage) { quickNavPageIndex = Math.max(0, quickNavPageIndex - 1); } - this._scrollQuickNavigationToPage(this.displayedPages[quickNavPageIndex]); + this.#scrollQuickNavigationToPage(this.displayedPages[quickNavPageIndex]); } scrollQuickNavFirst(): void { @@ -265,11 +265,11 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On } jumpToPreviousWithAnnotations(): void { - this.pdf.navigateTo(this._prevPageWithAnnotations()); + this.pdf.navigateTo(this.#prevPageWithAnnotations()); } jumpToNextWithAnnotations(): void { - this.pdf.navigateTo(this._nextPageWithAnnotations()); + this.pdf.navigateTo(this.#nextPageWithAnnotations()); } navigateAnnotations($event: KeyboardEvent) { @@ -281,12 +281,12 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On } // Displayed page doesn't have annotations if ($event.key === 'ArrowDown') { - const nextPage = this._nextPageWithAnnotations(); + const nextPage = this.#nextPageWithAnnotations(); return this.listingService.selectAnnotations(this.displayedAnnotations.get(nextPage)[0]); } - const prevPage = this._prevPageWithAnnotations(); + const prevPage = this.#prevPageWithAnnotations(); const prevPageAnnotations = this.displayedAnnotations.get(prevPage); return this.listingService.selectAnnotations(prevPageAnnotations[prevPageAnnotations.length - 1]); @@ -339,12 +339,12 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On this.scrollAnnotations(); } - private _disableMultiSelectAndDocumentInfo(): void { + #disableMultiSelectAndDocumentInfo(): void { this.multiSelectService.deactivate(); this.documentInfoService.hide(); } - private _filterAnnotations( + #filterAnnotations( annotations: AnnotationWrapper[], primary: INestedFilter[], secondary: INestedFilter[] = [], @@ -359,7 +359,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On annotations = annotations.filter(a => !bool(a.isChangeLogRemoved)); } - if (this.#isDocumine && !this.#devMode) { + if (this.#isDocumine && !this.#isIqserDevMode) { annotations = annotations.filter(a => !a.isOCR); } @@ -383,7 +383,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On return this.displayedAnnotations; } - private _selectFirstAnnotationOnCurrentPageIfNecessary() { + #selectFirstAnnotationOnCurrentPageIfNecessary() { const currentPage = this.pdf.currentPage(); if ( (!this._firstSelectedAnnotation || currentPage !== this._firstSelectedAnnotation.pageNumber) && @@ -394,13 +394,13 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On } } - private _navigatePages($event: KeyboardEvent) { + #navigatePages($event: KeyboardEvent) { const pageIdx = this.displayedPages.indexOf(this.pdf.currentPage()); if ($event.key !== 'ArrowDown') { if (pageIdx === -1) { // If active page doesn't have annotations - const prevPage = this._prevPageWithAnnotations(); + const prevPage = this.#prevPageWithAnnotations(); if (prevPage) { this.pdf.navigateTo(prevPage); } @@ -414,7 +414,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On } if (pageIdx === -1) { // If active page doesn't have annotations - const nextPage = this._nextPageWithAnnotations(); + const nextPage = this.#nextPageWithAnnotations(); if (nextPage) { this.pdf.navigateTo(nextPage); } @@ -426,7 +426,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On } } - private _nextPageWithAnnotations() { + #nextPageWithAnnotations() { let idx = 0; for (const page of this.displayedPages) { if (page > this.pdf.currentPage() && this.displayedAnnotations.get(page)) { @@ -437,7 +437,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On return idx < this.displayedPages.length ? this.displayedPages[idx] : this.displayedPages[this.displayedPages.length - 1]; } - private _prevPageWithAnnotations() { + #prevPageWithAnnotations() { let idx = this.displayedPages.length - 1; const reverseDisplayedPages = [...this.displayedPages].reverse(); for (const page of reverseDisplayedPages) { @@ -449,14 +449,14 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On return idx >= 0 ? this.displayedPages[idx] : this.displayedPages[0]; } - private _scrollQuickNavigationToPage(page: number) { + #scrollQuickNavigationToPage(page: number) { if (this._quickNavigationElement) { const elements: HTMLElement[] = this._quickNavigationElement.nativeElement.querySelectorAll(`#quick-nav-page-${page}`); FileWorkloadComponent._scrollToFirstElement(elements); } } - private _mapListItemsFromAnnotationWrapperArray(annotations: Map) { + #mapListItemsFromAnnotationWrapperArray(annotations: Map) { const listItemsMap = new Map[]>(); if (!annotations) { return listItemsMap; diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts index 8aa406601..e19af623a 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts @@ -154,7 +154,6 @@ export class REDAnnotationManager { this.#manager.selectAnnotation(annotation); annotation.disableRotationControl(); } - this.#annotationSelected$.next([annotations, action]); }); } diff --git a/libs/common-ui b/libs/common-ui index a4132b82f..6cb63fcf4 160000 --- a/libs/common-ui +++ b/libs/common-ui @@ -1 +1 @@ -Subproject commit a4132b82f52e92025f2348fb83587680790ca3a8 +Subproject commit 6cb63fcf43fbbf522b847f57467156808bbe72a1