From 9b330a1f7da007367269fe9c67247dba48f93f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Thu, 10 Feb 2022 17:36:53 +0200 Subject: [PATCH] Disable multi select in delta & preview --- .../annotations-list.component.ts | 10 +++----- .../file-workload.component.html | 2 +- .../pdf-viewer/pdf-viewer.component.ts | 6 ++++- .../file-preview-screen.component.ts | 7 ++++++ .../services/multi-select.service.ts | 25 +++++++++++++------ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotations-list/annotations-list.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotations-list/annotations-list.component.ts index c6ce92cb5..3cda27f73 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotations-list/annotations-list.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotations-list/annotations-list.component.ts @@ -5,7 +5,6 @@ import { MultiSelectService } from '../../services/multi-select.service'; import { AnnotationReferencesService } from '../../services/annotation-references.service'; import { ViewModeService } from '../../services/view-mode.service'; import { FilePreviewStateService } from '../../services/file-preview-state.service'; -import { firstValueFrom } from 'rxjs'; @Component({ selector: 'redaction-annotations-list', @@ -37,8 +36,7 @@ export class AnnotationsListComponent implements OnChanges { } } - async annotationClicked(annotation: AnnotationWrapper, $event: MouseEvent): Promise { - console.log(annotation); + annotationClicked(annotation: AnnotationWrapper, $event: MouseEvent): void { if (($event?.target as IqserEventTarget)?.localName === 'input') { return; } @@ -52,7 +50,7 @@ export class AnnotationsListComponent implements OnChanges { if (this.isSelected(annotation.annotationId)) { this.deselectAnnotations.emit([annotation]); } else { - const canMultiSelect = await firstValueFrom(this._state.isWritable$); + const canMultiSelect = this.multiSelectService.isEnabled; if (canMultiSelect && ($event?.ctrlKey || $event?.metaKey) && this.selectedAnnotations.length > 0) { this.multiSelectService.activate(); } @@ -60,8 +58,8 @@ export class AnnotationsListComponent implements OnChanges { } } - async referenceClicked(annotation: AnnotationWrapper): Promise { - await this.annotationClicked(annotation, null); + referenceClicked(annotation: AnnotationWrapper): void { + this.annotationClicked(annotation, null); if (this._filterService.filtersEnabled('primaryFilters')) { this._filterService.toggleFilter('primaryFilters', annotation.superType, true); } diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html index f80299b25..176f71a18 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/file-workload/file-workload.component.html @@ -14,7 +14,7 @@
{ - this.annotationSelected.emit(this.annotationManager.getSelectedAnnotations().map(ann => ann.Id)); + const nextAnnotations = this.multiSelectService.isEnabled ? this.annotationManager.getSelectedAnnotations() : annotations; + this.annotationSelected.emit(nextAnnotations.map(ann => ann.Id)); if (action === 'deselected') { this._toggleRectangleAnnotationAction(true); } else { + if (!this.multiSelectService.isEnabled) { + this.utils.deselectAnnotations(this.annotations.filter(wrapper => !nextAnnotations.find(ann => ann.Id === wrapper.id))); + } this._configureAnnotationSpecificActions(annotations); this._toggleRectangleAnnotationAction(annotations.length === 1 && annotations[0].ReadOnly); } diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts index c01c905ed..ef453c240 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/file-preview-screen.component.ts @@ -206,6 +206,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni this._loadingService.start(); await this.userPreferenceService.saveLastOpenedFileForDossier(this.dossierId, this.fileId); this._subscribeToFileUpdates(); + this.viewModeService.viewMode$.pipe(tap(() => this.#deactivateMultiSelect())).subscribe(); const file = await this.stateService.file; if (file?.analysisRequired) { @@ -427,6 +428,12 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni download(data, file.filename); } + #deactivateMultiSelect(): void { + this.multiSelectService.deactivate(); + this.viewerComponent?.utils?.deselectAllAnnotations(); + this.handleAnnotationSelected([]); + } + private _setActiveViewerPage() { const currentPage = this._instance?.Core.documentViewer?.getCurrentPage(); if (!currentPage) { diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/multi-select.service.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/multi-select.service.ts index 71455608d..59db5bc89 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/multi-select.service.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/multi-select.service.ts @@ -1,15 +1,28 @@ import { Injectable } from '@angular/core'; -import { BehaviorSubject, Observable } from 'rxjs'; +import { BehaviorSubject, combineLatest, Observable } from 'rxjs'; import { boolFactory } from '@iqser/common-ui'; +import { ViewModeService } from './view-mode.service'; +import { map, tap } from 'rxjs/operators'; +import { FilePreviewStateService } from './file-preview-state.service'; @Injectable() export class MultiSelectService { + readonly enabled$: Observable; readonly active$: Observable; readonly inactive$: Observable; readonly #active$ = new BehaviorSubject(false); + readonly #enabled$ = new BehaviorSubject(true); - constructor() { + constructor(private readonly _viewModeService: ViewModeService, private readonly _state: FilePreviewStateService) { [this.active$, this.inactive$] = boolFactory(this.#active$.asObservable()); + this.enabled$ = combineLatest([this._viewModeService.isStandard$, _state.isWritable$]).pipe( + map((result: boolean[]) => !result.some(res => !res)), + tap(enabled => this.#enabled$.next(enabled)), + ); + } + + get isEnabled() { + return this.#enabled$.value; } get isActive() { @@ -17,14 +30,12 @@ export class MultiSelectService { } activate() { - this.#active$.next(true); + if (this.isEnabled) { + this.#active$.next(true); + } } deactivate() { this.#active$.next(false); } - - toggle() { - this.#active$.next(!this.#active$.value); - } }