From 149610a801f0e89167bee8b7bb05fe2a63daf341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Mon, 11 Apr 2022 09:58:11 +0300 Subject: [PATCH] RED-3831: Remove annotationsChanged event emitters --- .../annotation-actions.component.html | 27 ++-- .../annotation-actions.component.ts | 13 +- .../annotations-list.component.html | 6 +- .../annotations-list.component.ts | 1 - .../file-workload.component.html | 2 - .../file-workload/file-workload.component.ts | 1 - .../highlights-separator.component.ts | 7 +- .../pdf-viewer/pdf-viewer.component.ts | 3 +- .../highlight-action-dialog.component.ts | 6 +- .../file-preview-screen.component.html | 3 - .../file-preview-screen.component.ts | 9 -- .../services/annotation-actions.service.ts | 142 ++++++------------ .../services/file-data.service.ts | 13 ++ 13 files changed, 83 insertions(+), 150 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html index ffe99a522..3b07d1bae 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html @@ -38,7 +38,7 @@ > - - (); annotationPermissions: AnnotationPermissions; constructor( @@ -94,15 +93,15 @@ export class AnnotationActionsComponent implements OnChanges { removeOrSuggestRemoveAnnotation($event: MouseEvent, removeFromDict: boolean) { $event.stopPropagation(); - this.annotationActionsService.removeOrSuggestRemoveAnnotation($event, this.annotations, removeFromDict, this.annotationsChanged); + this.annotationActionsService.removeOrSuggestRemoveAnnotation($event, this.annotations, removeFromDict); } markAsFalsePositive($event: MouseEvent) { - this.annotationActionsService.markAsFalsePositive($event, this.annotations, this.annotationsChanged); + this.annotationActionsService.markAsFalsePositive($event, this.annotations); } acceptRecommendation($event: MouseEvent) { - this.annotationActionsService.convertRecommendationToAnnotation($event, this.annotations, this.annotationsChanged); + this.annotationActionsService.convertRecommendationToAnnotation($event, this.annotations); } hideAnnotation($event: MouseEvent) { @@ -124,11 +123,11 @@ export class AnnotationActionsComponent implements OnChanges { } acceptResize($event: MouseEvent) { - return this.annotationActionsService.acceptResize($event, this.annotations[0], this.annotationsChanged); + return this.annotationActionsService.acceptResize($event, this.annotations[0]); } cancelResize($event: MouseEvent) { - return this.annotationActionsService.cancelResize($event, this.annotations[0], this.annotationsChanged); + return this.annotationActionsService.cancelResize($event, this.annotations[0]); } private async _setPermissions() { diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.html b/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.html index 632c97e3a..4d28f4d07 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/annotations-list/annotations-list.component.html @@ -1,10 +1,6 @@
- +
(); @Output() readonly selectAnnotations = new EventEmitter(); - @Output() readonly annotationsChanged = new EventEmitter(); highlightGroups$ = new BehaviorSubject([]); diff --git a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html index 70b6abc7f..e8b918261 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/file-workload/file-workload.component.html @@ -56,7 +56,6 @@ {{ listingService.selectedLength$ | async }} selected ; @Output() readonly selectAnnotations = new EventEmitter(); @Output() readonly selectPage = new EventEmitter(); - @Output() readonly annotationsChanged = new EventEmitter(); displayedPages: number[] = []; pagesPanelActive = true; readonly displayedAnnotations$: Observable>; diff --git a/apps/red-ui/src/app/modules/file-preview/components/highlights-separator/highlights-separator.component.ts b/apps/red-ui/src/app/modules/file-preview/components/highlights-separator/highlights-separator.component.ts index cd0f1bc3b..eb3522420 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/highlights-separator/highlights-separator.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/highlights-separator/highlights-separator.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; import { CircleButtonTypes } from '@iqser/common-ui'; import { TextHighlightOperation, TextHighlightsGroup } from '@red/domain'; import { FilePreviewStateService } from '../../services/file-preview-state.service'; @@ -16,7 +16,6 @@ import { MultiSelectService } from '../../services/multi-select.service'; export class HighlightsSeparatorComponent { @Input() highlightGroup: TextHighlightsGroup; @Input() annotation: AnnotationWrapper; - @Output() readonly annotationsChanged = new EventEmitter(); readonly circleButtonTypes = CircleButtonTypes; readonly isWritable$ = this._state.isWritable$; @@ -48,7 +47,9 @@ export class HighlightsSeparatorComponent { operation, highlights, pageNumber: this.annotation.pageNumber, - annotationsChanged: this.annotationsChanged, + annotationsChanged: async () => { + await this._fileDataService.annotationsChanged(); + }, }; } } diff --git a/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts b/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts index 5cc471472..4e389bd61 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/components/pdf-viewer/pdf-viewer.component.ts @@ -60,7 +60,6 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha @Output() readonly manualAnnotationRequested = new EventEmitter(); @Output() readonly pageChanged = new EventEmitter(); @Output() readonly keyUp = new EventEmitter(); - @Output() readonly annotationsChanged = new EventEmitter(); @ViewChild('viewer', { static: true }) viewer: ElementRef; @ViewChild('compareFileInput', { static: true }) compareFileInput: ElementRef; instance: WebViewerInstance; @@ -392,7 +391,7 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha ]); } - const actions = this._annotationActionsService.getViewerAvailableActions(this.dossier, annotationWrappers, this.annotationsChanged); + const actions = this._annotationActionsService.getViewerAvailableActions(this.dossier, annotationWrappers); this.instance.UI.annotationPopup.add(actions); } diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/highlight-action-dialog/highlight-action-dialog.component.ts b/apps/red-ui/src/app/modules/file-preview/dialogs/highlight-action-dialog/highlight-action-dialog.component.ts index b09d8b661..fe571896f 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/highlight-action-dialog/highlight-action-dialog.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/highlight-action-dialog/highlight-action-dialog.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Inject, Injector } from '@angular/core'; +import { Component, Inject, Injector } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { TextHighlightOperation, TextHighlightOperationPages } from '@red/domain'; @@ -15,7 +15,7 @@ export interface HighlightActionData { readonly fileId: string; readonly highlights: AnnotationWrapper[]; readonly pageNumber: number; - readonly annotationsChanged?: EventEmitter; + readonly annotationsChanged?: () => Promise; } @Component({ @@ -51,7 +51,7 @@ export class HighlightActionDialogComponent extends BaseDialogComponent { const ids = filteredHighlights.map(h => h.id); await firstValueFrom(this._textHighlightService.performHighlightsAction(ids, dossierId, fileId, operation)); if (this.data.annotationsChanged) { - this.data.annotationsChanged.emit(highlights); + await this.data.annotationsChanged(); } this._loadingService.stop(); this._dialogRef.close(true); diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html index e4ed0ac06..49de602a9 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.html @@ -65,7 +65,6 @@
diff --git a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts index bca100150..712000d04 100644 --- a/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts +++ b/apps/red-ui/src/app/modules/file-preview/file-preview-screen.component.ts @@ -362,15 +362,6 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni this._changeDetectorRef.markForCheck(); } - async annotationsChangedByReviewAction() { - this.multiSelectService.deactivate(); - const file = await this.state.file; - const fileReloaded = await firstValueFrom(this._filesService.reload(this.dossierId, file)); - if (!fileReloaded) { - await this._fileDataService.loadAnnotations(file); - } - } - closeFullScreen() { if (!!document.fullscreenElement && document.exitFullscreen) { document.exitFullscreen().then(); diff --git a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts index 70e089cd3..4319d4a19 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/annotation-actions.service.ts @@ -1,4 +1,4 @@ -import { EventEmitter, Inject, Injectable, NgZone } from '@angular/core'; +import { Inject, Injectable, NgZone } from '@angular/core'; import { PermissionsService } from '@services/permissions.service'; import { ManualRedactionService } from './manual-redaction.service'; import { AnnotationWrapper } from '@models/file/annotation.wrapper'; @@ -34,6 +34,7 @@ import { FilePreviewStateService } from './file-preview-state.service'; import { PdfViewer } from './pdf-viewer.service'; import { FilePreviewDialogService } from './file-preview-dialog.service'; import { DictionariesMapService } from '@services/entity-services/dictionaries-map.service'; +import { FileDataService } from './file-data.service'; import Quad = Core.Math.Quad; @Injectable() @@ -52,13 +53,14 @@ export class AnnotationActionsService { private readonly _activeDossiersService: ActiveDossiersService, private readonly _dictionariesMapService: DictionariesMapService, private readonly _state: FilePreviewStateService, + private readonly _fileDataService: FileDataService, ) {} private get _dossier(): Dossier { return this._activeDossiersService.find(this._state.dossierId); } - acceptSuggestion($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + acceptSuggestion($event: MouseEvent, annotations: AnnotationWrapper[]) { $event?.stopPropagation(); const { dossierId, fileId } = this._state; this._processObsAndEmit( @@ -67,22 +69,20 @@ export class AnnotationActionsService { dossierId, fileId, ), - annotations, - annotationsChanged, ); } - removeHighlights(highlights: AnnotationWrapper[], annotationsChanged: EventEmitter): void { - const data = this._getHighlightOperationData(TextHighlightOperation.REMOVE, highlights, annotationsChanged); + removeHighlights(highlights: AnnotationWrapper[]): void { + const data = this._getHighlightOperationData(TextHighlightOperation.REMOVE, highlights); this._dialogService.openDialog('highlightAction', null, data); } - convertHighlights(highlights: AnnotationWrapper[], annotationsChanged: EventEmitter): void { - const data = this._getHighlightOperationData(TextHighlightOperation.CONVERT, highlights, annotationsChanged); + convertHighlights(highlights: AnnotationWrapper[]): void { + const data = this._getHighlightOperationData(TextHighlightOperation.CONVERT, highlights); this._dialogService.openDialog('highlightAction', null, data); } - rejectSuggestion($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + rejectSuggestion($event: MouseEvent, annotations: AnnotationWrapper[]) { $event?.stopPropagation(); const { dossierId, fileId } = this._state; this._processObsAndEmit( @@ -92,17 +92,10 @@ export class AnnotationActionsService { fileId, annotations[0].isModifyDictionary, ), - annotations, - annotationsChanged, ); } - forceAnnotation( - $event: MouseEvent, - annotations: AnnotationWrapper[], - annotationsChanged: EventEmitter, - hint: boolean = false, - ) { + forceAnnotation($event: MouseEvent, annotations: AnnotationWrapper[], hint: boolean = false) { const { dossierId, fileId } = this._state; const data = { dossier: this._dossier, annotations, hint }; this._dialogService.openDialog('forceAnnotation', $event, data, (request: ILegalBasisChangeRequest) => { @@ -112,13 +105,11 @@ export class AnnotationActionsService { dossierId, fileId, ), - annotations, - annotationsChanged, ); }); } - changeLegalBasis($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + changeLegalBasis($event: MouseEvent, annotations: AnnotationWrapper[]) { const { dossierId, fileId } = this._state; this._dialogService.openDialog( 'changeLegalBasis', @@ -133,21 +124,12 @@ export class AnnotationActionsService { value: data.value, })); - this._processObsAndEmit( - this._manualRedactionService.changeLegalBasis(body, dossierId, fileId), - annotations, - annotationsChanged, - ); + this._processObsAndEmit(this._manualRedactionService.changeLegalBasis(body, dossierId, fileId)); }, ); } - removeOrSuggestRemoveAnnotation( - $event: MouseEvent, - annotations: AnnotationWrapper[], - removeFromDictionary: boolean, - annotationsChanged: EventEmitter, - ) { + removeOrSuggestRemoveAnnotation($event: MouseEvent, annotations: AnnotationWrapper[], removeFromDictionary: boolean) { const data = { annotationsToRemove: annotations, removeFromDictionary, @@ -161,15 +143,11 @@ export class AnnotationActionsService { removeFromDictionary, comment: result.comment, })); - this._processObsAndEmit( - this._manualRedactionService.removeOrSuggestRemove(body, dossierId, fileId, removeFromDictionary), - annotations, - annotationsChanged, - ); + this._processObsAndEmit(this._manualRedactionService.removeOrSuggestRemove(body, dossierId, fileId, removeFromDictionary)); }); } - recategorizeImages($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + recategorizeImages($event: MouseEvent, annotations: AnnotationWrapper[]) { const data = { annotations, dossier: this._dossier }; const { dossierId, fileId } = this._state; this._dialogService.openDialog('recategorizeImage', $event, data, ({ comment, type }: { type: string; comment: string }) => { @@ -178,15 +156,11 @@ export class AnnotationActionsService { type, comment, })); - this._processObsAndEmit( - this._manualRedactionService.recategorizeImage(body, dossierId, fileId), - annotations, - annotationsChanged, - ); + this._processObsAndEmit(this._manualRedactionService.recategorizeImage(body, dossierId, fileId)); }); } - undoDirectAction($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + undoDirectAction($event: MouseEvent, annotations: AnnotationWrapper[]) { $event?.stopPropagation(); const { dossierId, fileId } = this._state; @@ -198,16 +172,10 @@ export class AnnotationActionsService { fileId, modifyDictionary, ), - annotations, - annotationsChanged, ); } - convertRecommendationToAnnotation( - $event: any, - recommendations: AnnotationWrapper[], - annotationsChanged: EventEmitter, - ) { + convertRecommendationToAnnotation($event: any, recommendations: AnnotationWrapper[]) { $event?.stopPropagation(); const { dossierId, fileId } = this._state; @@ -218,19 +186,11 @@ export class AnnotationActionsService { const dialogClosed = dialogRef.afterClosed().pipe(filter(value => !!value && !!value.annotations)); dialogClosed.subscribe(({ annotations, comment: commentText }) => { const comment = commentText ? { text: commentText } : undefined; - this._processObsAndEmit( - this._manualRedactionService.addRecommendation(annotations, dossierId, fileId, comment), - annotations, - annotationsChanged, - ); + this._processObsAndEmit(this._manualRedactionService.addRecommendation(annotations, dossierId, fileId, comment)); }); } - getViewerAvailableActions( - dossier: Dossier, - annotations: AnnotationWrapper[], - annotationsChanged: EventEmitter, - ): Record[] { + getViewerAvailableActions(dossier: Dossier, annotations: AnnotationWrapper[]): Record[] { const availableActions = []; const annotationPermissions = annotations.map(annotation => ({ annotation, @@ -254,14 +214,14 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.resize-accept.label'), onClick: () => this._ngZone.run(() => { - this.acceptResize(null, firstAnnotation, annotationsChanged); + this.acceptResize(null, firstAnnotation); }), }); availableActions.push({ type: 'actionButton', img: this._convertPath('/assets/icons/general/close.svg'), title: this._translateService.instant('annotation-actions.resize-cancel.label'), - onClick: () => this._ngZone.run(() => this.cancelResize(null, firstAnnotation, annotationsChanged)), + onClick: () => this._ngZone.run(() => this.cancelResize(null, firstAnnotation)), }); return availableActions; } @@ -282,7 +242,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.edit-reason.label'), onClick: () => this._ngZone.run(() => { - this.changeLegalBasis(null, annotations, annotationsChanged); + this.changeLegalBasis(null, annotations); }), }); } @@ -295,7 +255,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.recategorize-image'), onClick: () => this._ngZone.run(() => { - this.recategorizeImages(null, annotations, annotationsChanged); + this.recategorizeImages(null, annotations); }), }); } @@ -311,7 +271,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.remove-annotation.remove-from-dict'), onClick: () => this._ngZone.run(() => { - this.removeOrSuggestRemoveAnnotation(null, annotations, true, annotationsChanged); + this.removeOrSuggestRemoveAnnotation(null, annotations, true); }), }); } @@ -324,7 +284,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.accept-recommendation.label'), onClick: () => this._ngZone.run(() => { - this.convertRecommendationToAnnotation(null, annotations, annotationsChanged); + this.convertRecommendationToAnnotation(null, annotations); }), }); } @@ -337,7 +297,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.accept-suggestion.label'), onClick: () => this._ngZone.run(() => { - this.acceptSuggestion(null, annotations, annotationsChanged); + this.acceptSuggestion(null, annotations); }), }); } @@ -350,7 +310,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.undo'), onClick: () => this._ngZone.run(() => { - this.undoDirectAction(null, annotations, annotationsChanged); + this.undoDirectAction(null, annotations); }), }); } @@ -363,7 +323,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.remove-annotation.false-positive'), onClick: () => this._ngZone.run(() => { - this.markAsFalsePositive(null, annotations, annotationsChanged); + this.markAsFalsePositive(null, annotations); }), }); } @@ -376,7 +336,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.force-redaction.label'), onClick: () => this._ngZone.run(() => { - this.forceAnnotation(null, annotations, annotationsChanged); + this.forceAnnotation(null, annotations); }), }); } @@ -389,7 +349,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.force-hint.label'), onClick: () => this._ngZone.run(() => { - this.forceAnnotation(null, annotations, annotationsChanged, true); + this.forceAnnotation(null, annotations, true); }), }); } @@ -402,7 +362,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.reject-suggestion'), onClick: () => this._ngZone.run(() => { - this.rejectSuggestion(null, annotations, annotationsChanged); + this.rejectSuggestion(null, annotations); }), }); } @@ -418,7 +378,7 @@ export class AnnotationActionsService { title: this._translateService.instant('annotation-actions.remove-annotation.only-here'), onClick: () => this._ngZone.run(() => { - this.removeOrSuggestRemoveAnnotation(null, annotations, false, annotationsChanged); + this.removeOrSuggestRemoveAnnotation(null, annotations, false); }), }); } @@ -448,7 +408,7 @@ export class AnnotationActionsService { this._pdf.annotationManager.selectAnnotation(viewerAnnotation); } - acceptResize($event: MouseEvent, annotationWrapper: AnnotationWrapper, annotationsChanged?: EventEmitter) { + acceptResize($event: MouseEvent, annotationWrapper: AnnotationWrapper) { const data = { dossier: this._dossier }; const fileId = this._state.fileId; this._dialogService.openDialog('resizeAnnotation', $event, data, async (result: { comment: string }) => { @@ -463,15 +423,11 @@ export class AnnotationActionsService { value: text, }; - this._processObsAndEmit( - this._manualRedactionService.resizeOrSuggestResize([resizeRequest], data.dossier.dossierId, fileId), - [annotationWrapper], - annotationsChanged, - ); + this._processObsAndEmit(this._manualRedactionService.resizeOrSuggestResize([resizeRequest], data.dossier.dossierId, fileId)); }); } - async cancelResize($event: MouseEvent, annotationWrapper: AnnotationWrapper, annotationsChanged: EventEmitter) { + async cancelResize($event: MouseEvent, annotationWrapper: AnnotationWrapper) { $event?.stopPropagation(); annotationWrapper.resizing = false; @@ -479,10 +435,10 @@ export class AnnotationActionsService { this._pdf.deleteAnnotations([annotationWrapper.id]); await this._annotationDrawService.drawAnnotations([annotationWrapper]); this._pdf.annotationManager.deselectAllAnnotations(); - annotationsChanged.emit([annotationWrapper]); + await this._fileDataService.annotationsChanged(); } - markAsFalsePositive($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + markAsFalsePositive($event: MouseEvent, annotations: AnnotationWrapper[]) { $event?.stopPropagation(); const requests: List = annotations.map(annotation => ({ @@ -498,7 +454,7 @@ export class AnnotationActionsService { })); const { dossierId, fileId } = this._state; - this._processObsAndEmit(this._manualRedactionService.addAnnotation(requests, dossierId, fileId), annotations, annotationsChanged); + this._processObsAndEmit(this._manualRedactionService.addAnnotation(requests, dossierId, fileId)); } #generateRectangle(annotationWrapper: AnnotationWrapper) { @@ -521,28 +477,22 @@ export class AnnotationActionsService { return annotation; } - private _getHighlightOperationData( - operation: TextHighlightOperation, - highlights: AnnotationWrapper[], - annotationsChanged: EventEmitter, - ) { + private _getHighlightOperationData(operation: TextHighlightOperation, highlights: AnnotationWrapper[]) { return { dossierId: this._state.dossierId, fileId: this._state.fileId, operation, highlights, - annotationsChanged, + annotationsChanged: async () => { + await this._fileDataService.annotationsChanged(); + }, }; } - private _processObsAndEmit( - obs: Observable, - annotations: AnnotationWrapper[], - annotationsChanged: EventEmitter, - ) { + private _processObsAndEmit(obs: Observable) { obs.subscribe({ - next: () => annotationsChanged.emit(annotations), - error: () => annotationsChanged.emit(), + next: () => this._fileDataService.annotationsChanged(), + error: () => this._fileDataService.annotationsChanged(), }); } diff --git a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts index 97a3b1f43..a67feff0f 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/file-data.service.ts @@ -27,6 +27,8 @@ import { ViewModeService } from './view-mode.service'; import { Core } from '@pdftron/webviewer'; import dayjs from 'dayjs'; import { NGXLogger } from 'ngx-logger'; +import { MultiSelectService } from './multi-select.service'; +import { FilesService } from '../../../services/entity-services/files.service'; import Annotation = Core.Annotations.Annotation; const DELTA_VIEW_TIME = 10 * 60 * 1000; // 10 minutes; @@ -51,6 +53,8 @@ export class FileDataService extends EntitiesService { private readonly _permissionsService: PermissionsService, private readonly _redactionLogService: RedactionLogService, private readonly _textHighlightsService: TextHighlightService, + private readonly _multiSelectService: MultiSelectService, + private readonly _filesService: FilesService, private readonly _toaster: Toaster, private readonly _logger: NGXLogger, protected readonly _injector: Injector, @@ -99,6 +103,15 @@ export class FileDataService extends EntitiesService { await this.loadRedactionLog(); } + async annotationsChanged() { + this._multiSelectService.deactivate(); + const file = await this._state.file; + const fileReloaded = await firstValueFrom(this._filesService.reload(file.dossierId, file)); + if (!fileReloaded) { + await this.loadAnnotations(file); + } + } + async loadTextHighlights(): Promise { const highlights = await firstValueFrom(this._textHighlightsService.getTextHighlights(this._state.dossierId, this._state.fileId)); this.#textHighlights$.next(highlights);