RED-10396 - fixed current page active annotations re evaluation when they are updated

This commit is contained in:
Valentin Mihai 2024-11-12 11:16:39 +02:00
parent d59a4c02a0
commit 969e375986
2 changed files with 38 additions and 25 deletions

View File

@ -129,7 +129,7 @@
></iqser-circle-button>
<span
[translateParams]="{ page: pdf.currentPage(), count: activeAnnotations.length }"
[translateParams]="{ page: pdf.currentPage(), count: activeAnnotations().length }"
[translate]="'page'"
class="all-caps-label"
></span>
@ -160,7 +160,7 @@
id="annotations-list"
tabindex="1"
>
<ng-container *ngIf="pdf.currentPage() && !displayedAnnotations.get(pdf.currentPage())?.length">
<ng-container *ngIf="pdf.currentPage() && !displayedAnnotations().get(pdf.currentPage())?.length">
<iqser-empty-state
[horizontalPadding]="24"
[text]="'file-preview.no-data.title' | translate"

View File

@ -1,5 +1,17 @@
import { AsyncPipe, NgIf, NgTemplateOutlet } from '@angular/common';
import { ChangeDetectorRef, Component, computed, effect, ElementRef, HostListener, OnDestroy, OnInit, ViewChild } from '@angular/core';
import {
ChangeDetectorRef,
Component,
computed,
effect,
ElementRef,
HostListener,
OnDestroy,
OnInit,
signal,
untracked,
ViewChild,
} from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatIcon } from '@angular/material/icon';
import { MatTooltip } from '@angular/material/tooltip';
@ -91,7 +103,8 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
protected readonly currentPageIsExcluded = computed(() => this.state.file().excludedPages.includes(this.pdf.currentPage()));
protected readonly translations = workloadTranslations;
protected readonly isDocumine = getConfig().IS_DOCUMINE;
displayedAnnotations = new Map<number, AnnotationWrapper[]>();
displayedAnnotations = signal(new Map<number, AnnotationWrapper[]>());
readonly activeAnnotations = computed(() => this.displayedAnnotations().get(this.pdf.currentPage()) || []);
displayedPages: number[] = [];
pagesPanelActive = true;
@ -156,10 +169,6 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
);
}
get activeAnnotations(): AnnotationWrapper[] {
return this.displayedAnnotations.get(this.pdf.currentPage()) || [];
}
get showAnalysisDisabledBanner() {
const file = this.state.file();
return this.isDocumine && file.excludedFromAutomaticAnalysis && file.workflowStatus !== WorkflowFileStatuses.APPROVED;
@ -216,12 +225,14 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
}
selectAllOnActivePage() {
this.listingService.selectAnnotations(this.activeAnnotations);
const activeAnnotations = untracked(this.activeAnnotations);
this.listingService.selectAnnotations(activeAnnotations);
}
deselectAllOnActivePage(): void {
this.listingService.deselect(this.activeAnnotations);
this.annotationManager.deselect(this.activeAnnotations);
const activeAnnotations = untracked(this.activeAnnotations);
this.listingService.deselect(activeAnnotations);
this.annotationManager.deselect(activeAnnotations);
}
@HostListener('window:keyup', ['$event'])
@ -326,20 +337,21 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
@Debounce(15)
navigateAnnotations($event: KeyboardEvent) {
const currentPage = this.pdf.currentPage();
const activeAnnotations = untracked(this.activeAnnotations);
if (!this._firstSelectedAnnotation || currentPage !== this._firstSelectedAnnotation.pageNumber) {
if (this.displayedPages.indexOf(currentPage) !== -1) {
// Displayed page has annotations
return this.listingService.selectAnnotations(this.activeAnnotations ? this.activeAnnotations[0] : null);
return this.listingService.selectAnnotations(activeAnnotations ? activeAnnotations[0] : null);
}
// Displayed page doesn't have annotations
if ($event.key === 'ArrowDown') {
const nextPage = this.#nextPageWithAnnotations();
return this.listingService.selectAnnotations(this.displayedAnnotations.get(nextPage)[0]);
return this.listingService.selectAnnotations(this.displayedAnnotations().get(nextPage)[0]);
}
const prevPage = this.#prevPageWithAnnotations();
const prevPageAnnotations = this.displayedAnnotations.get(prevPage);
const prevPageAnnotations = this.displayedAnnotations().get(prevPage);
return this.listingService.selectAnnotations(getLast(prevPageAnnotations));
}
@ -348,7 +360,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
const pageIdx = this.displayedPages.indexOf(page);
const nextPageIdx = pageIdx + 1;
const previousPageIdx = pageIdx - 1;
const annotationsOnPage = this.displayedAnnotations.get(page);
const annotationsOnPage = this.displayedAnnotations().get(page);
const idx = annotationsOnPage.findIndex(a => a.id === this._firstSelectedAnnotation.id);
if ($event.key === 'ArrowDown') {
@ -358,7 +370,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
} 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]);
const nextPageAnnotations = this.displayedAnnotations().get(this.displayedPages[i]);
if (nextPageAnnotations) {
this.listingService.selectAnnotations(nextPageAnnotations[0]);
break;
@ -376,7 +388,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
if (pageIdx) {
// If not first page
for (let i = previousPageIdx; i >= 0; i--) {
const prevPageAnnotations = this.displayedAnnotations.get(this.displayedPages[i]);
const prevPageAnnotations = this.displayedAnnotations().get(this.displayedPages[i]);
if (prevPageAnnotations) {
this.listingService.selectAnnotations(getLast(prevPageAnnotations));
break;
@ -415,8 +427,8 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
annotations = annotations.filter(a => !a.isOCR);
}
this.displayedAnnotations = this._annotationProcessingService.filterAndGroupAnnotations(annotations, primary, secondary);
const pagesThatDisplayAnnotations = [...this.displayedAnnotations.keys()];
this.displayedAnnotations.set(this._annotationProcessingService.filterAndGroupAnnotations(annotations, primary, secondary));
const pagesThatDisplayAnnotations = [...this.displayedAnnotations().keys()];
const enabledFilters = this.filterService.enabledFlatFilters;
if (enabledFilters.some(f => f.id === 'pages-without-annotations')) {
if (enabledFilters.length === 1 && !onlyPageWithAnnotations) {
@ -424,7 +436,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
} else {
this.displayedPages = [];
}
this.displayedAnnotations.clear();
this.displayedAnnotations().clear();
} else if (enabledFilters.length || onlyPageWithAnnotations) {
this.displayedPages = pagesThatDisplayAnnotations;
} else {
@ -432,17 +444,18 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
}
this.displayedPages.sort((a, b) => a - b);
return this.displayedAnnotations;
return this.displayedAnnotations();
}
#selectFirstAnnotationOnCurrentPageIfNecessary() {
const currentPage = this.pdf.currentPage();
const activeAnnotations = untracked(this.activeAnnotations);
if (
(!this._firstSelectedAnnotation || currentPage !== this._firstSelectedAnnotation.pageNumber) &&
this.displayedPages.indexOf(currentPage) >= 0 &&
this.activeAnnotations.length > 0
activeAnnotations.length > 0
) {
this.listingService.selectAnnotations(this.activeAnnotations[0]);
this.listingService.selectAnnotations(activeAnnotations[0]);
}
}
@ -481,7 +494,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
#nextPageWithAnnotations() {
let idx = 0;
for (const page of this.displayedPages) {
if (page > this.pdf.currentPage() && this.displayedAnnotations.get(page)) {
if (page > this.pdf.currentPage() && this.displayedAnnotations().get(page)) {
break;
}
++idx;
@ -493,7 +506,7 @@ export class FileWorkloadComponent extends AutoUnsubscribe implements OnInit, On
let idx = this.displayedPages.length - 1;
const reverseDisplayedPages = [...this.displayedPages].reverse();
for (const page of reverseDisplayedPages) {
if (page < this.pdf.currentPage() && this.displayedAnnotations.get(page)) {
if (page < this.pdf.currentPage() && this.displayedAnnotations().get(page)) {
break;
}
--idx;