RED-7612 fix annotations selected when opened file

This commit is contained in:
Dan Percic 2023-09-15 19:10:03 +03:00
parent 6affd59ca9
commit ae2797f2b8
5 changed files with 32 additions and 34 deletions

View File

@ -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<AnnotationWrapper>;
@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<AnnotationWrapper>;
@HostBinding('attr.annotation-id') annotationId: string;
@HostBinding('class.active') active = false;
actionsHelpModeKey?: string;
ngOnChanges() {
this.annotationId = this.annotation.item.id;

View File

@ -24,7 +24,7 @@ export class AnnotationsListComponent extends HasScrollbarDirective implements O
}
return [] as EarmarkGroup[];
});
@Input() annotations: ListItem<AnnotationWrapper>[];
@Input({ required: true }) annotations: ListItem<AnnotationWrapper>[];
@Output() readonly pagesPanelActive = new EventEmitter<boolean>();
constructor(

View File

@ -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<number, AnnotationWrapper[]>();
@ -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<number, AnnotationWrapper[]>) {
#mapListItemsFromAnnotationWrapperArray(annotations: Map<number, AnnotationWrapper[]>) {
const listItemsMap = new Map<number, ListItem<AnnotationWrapper>[]>();
if (!annotations) {
return listItemsMap;

View File

@ -154,7 +154,6 @@ export class REDAnnotationManager {
this.#manager.selectAnnotation(annotation);
annotation.disableRotationControl();
}
this.#annotationSelected$.next([annotations, action]);
});
}

@ -1 +1 @@
Subproject commit a4132b82f52e92025f2348fb83587680790ca3a8
Subproject commit 6cb63fcf43fbbf522b847f57467156808bbe72a1