Merge branch 'dan' into 'master'

RED-7612 Fix annotations selected when file is opened

See merge request redactmanager/red-ui!85
This commit is contained in:
Dan Percic 2023-09-15 18:21:59 +02:00
commit 46577a81b4
8 changed files with 33 additions and 46 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

@ -9,7 +9,6 @@ import { ActiveDossiersService } from '@services/dossiers/active-dossiers.servic
import { DictionaryService } from '@services/entity-services/dictionary.service';
import { JustificationsService } from '@services/entity-services/justifications.service';
import { Roles } from '@users/roles';
import { removeHyphensAndSpecialChars } from '@utils/functions';
import { firstValueFrom } from 'rxjs';
import { ManualRedactionService } from '../../services/manual-redaction.service';
@ -186,7 +185,6 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme
addRedactionRequest.value = addRedactionRequest.rectangle
? this.form.get('classification').value
: this.form.get('selectedText').value;
addRedactionRequest.value = removeHyphensAndSpecialChars(addRedactionRequest.value);
}
#selectReason() {

View File

@ -52,7 +52,7 @@ import JSZip from 'jszip';
import { NGXLogger } from 'ngx-logger';
import { combineLatest, first, firstValueFrom, of, pairwise } from 'rxjs';
import { catchError, filter, map, startWith, switchMap, tap } from 'rxjs/operators';
import { byId, byPage, download, handleFilterDelta, hasChanges, removeHyphensAndSpecialChars } from '../../utils';
import { byId, byPage, download, handleFilterDelta, hasChanges } from '../../utils';
import { AnnotationDrawService } from '../pdf-viewer/services/annotation-draw.service';
import { REDAnnotationManager } from '../pdf-viewer/services/annotation-manager.service';
import { REDDocumentViewer } from '../pdf-viewer/services/document-viewer.service';
@ -533,7 +533,6 @@ export class FilePreviewScreenComponent
}
const hint = manualRedactionEntryWrapper.type === ManualRedactionEntryTypes.HINT;
result.redaction.value = removeHyphensAndSpecialChars(result.redaction.value);
const add$ = this._manualRedactionService.addAnnotation([result.redaction], this.dossierId, this.fileId, {
hint,
dictionaryLabel: result.dictionary?.label,

View File

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

View File

@ -133,11 +133,3 @@ export function calcTextWidthInPixels(text: string): number {
return width;
}
export function removeHyphensAndSpecialChars(text: string): string {
return text?.replace(
// eslint-disable-next-line no-control-regex,max-len
/([^\s\d-]{2,})[-\u00AD]\u000A\u000D|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]/gi,
'$1',
);
}

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