From 991e6a1b1cd75c24107114e17aa156d1cbf96fa7 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 31 Jan 2022 22:16:13 +0200 Subject: [PATCH] remove file from action requests --- .../manual-annotation-dialog.component.ts | 22 +-- .../annotation-actions.component.html | 14 +- .../annotation-actions.component.ts | 14 +- .../pdf-viewer/pdf-viewer.component.ts | 5 +- .../user-management.component.ts | 7 +- .../accept-recommendation-dialog.component.ts | 6 +- .../file-preview-screen.component.ts | 25 ++- .../services/annotation-actions.service.ts | 176 ++++++++---------- .../services/manual-annotation.service.ts | 89 +++++---- .../modules/dossier/utils/pdf-viewer.utils.ts | 2 +- apps/red-ui/src/app/utils/filter-utils.ts | 2 - 11 files changed, 176 insertions(+), 186 deletions(-) diff --git a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts index cd7c01318..1b38a8599 100644 --- a/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.ts @@ -4,10 +4,9 @@ import { AppStateService } from '@state/app-state.service'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry.wrapper'; import { ManualAnnotationService } from '../../services/manual-annotation.service'; -import { ManualAnnotationResponse } from '@models/file/manual-annotation-response'; import { PermissionsService } from '@services/permissions.service'; import { JustificationsService } from '@services/entity-services/justifications.service'; -import { Dictionary, Dossier, File, IAddRedactionRequest, IManualAddResponse } from '@red/domain'; +import { Dictionary, Dossier, IAddRedactionRequest } from '@red/domain'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { DictionaryService } from '@shared/services/dictionary.service'; import { BaseDialogComponent } from '@iqser/common-ui'; @@ -20,7 +19,6 @@ export interface LegalBasisOption { } @Component({ - selector: 'redaction-manual-annotation-dialog', templateUrl: './manual-annotation-dialog.component.html', styleUrls: ['./manual-annotation-dialog.component.scss'], }) @@ -44,10 +42,10 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme private readonly _dictionaryService: DictionaryService, protected readonly _injector: Injector, protected readonly _dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: { manualRedactionEntryWrapper: ManualRedactionEntryWrapper; file: File }, + @Inject(MAT_DIALOG_DATA) public data: { manualRedactionEntryWrapper: ManualRedactionEntryWrapper; dossierId: string }, ) { super(_injector, _dialogRef); - this._dossier = this._dossiersService.find(this.data.file.dossierId); + this._dossier = this._dossiersService.find(this.data.dossierId); this.isDocumentAdmin = this._permissionsService.isApprover(this._dossier); this.isFalsePositiveRequest = this.data.manualRedactionEntryWrapper.type === 'FALSE_POSITIVE'; @@ -73,6 +71,10 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme return this.form.invalid; } + get commentIsMandatory() { + return !this.isDocumentAdmin && !this.isDictionaryRequest; + } + async ngOnInit() { super.ngOnInit(); this.possibleDictionaries = await this._appStateService.getDictionariesOptions( @@ -91,11 +93,7 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme save() { this._enhanceManualRedaction(this.data.manualRedactionEntryWrapper.manualRedactionEntry); - this._manualAnnotationService.addAnnotation(this.data.manualRedactionEntryWrapper.manualRedactionEntry, this.data.file).subscribe( - (response: IManualAddResponse) => - this._dialogRef.close(new ManualAnnotationResponse(this.data.manualRedactionEntryWrapper, response)), - () => this._dialogRef.close(), - ); + this._dialogRef.close(this.data.manualRedactionEntryWrapper); } format(value: string) { @@ -118,10 +116,6 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme }); } - get commentIsMandatory() { - return !this.isDocumentAdmin && !this.isDictionaryRequest; - } - private _enhanceManualRedaction(addRedactionRequest: IAddRedactionRequest) { const legalOption: LegalBasisOption = this.form.get('reason').value; addRedactionRequest.type = this.form.get('dictionary').value; diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotation-actions/annotation-actions.component.html b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotation-actions/annotation-actions.component.html index 90a83df7a..6502158f1 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotation-actions/annotation-actions.component.html +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/components/annotation-actions/annotation-actions.component.html @@ -32,7 +32,7 @@ > !file.assignee && canAssignUser && dossier.hasReviewers), - log(), distinctUntilChanged(), ); diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/dialogs/accept-recommendation-dialog/accept-recommendation-dialog.component.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/dialogs/accept-recommendation-dialog/accept-recommendation-dialog.component.ts index 32392f6c8..63663c1e9 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/dialogs/accept-recommendation-dialog/accept-recommendation-dialog.component.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/dialogs/accept-recommendation-dialog/accept-recommendation-dialog.component.ts @@ -3,7 +3,7 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { AppStateService } from '@state/app-state.service'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { PermissionsService } from '@services/permissions.service'; -import { Dictionary, Dossier, File } from '@red/domain'; +import { Dictionary, Dossier } from '@red/domain'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { BaseDialogComponent } from '@iqser/common-ui'; import { DictionaryService } from '@shared/services/dictionary.service'; @@ -12,7 +12,7 @@ import { AnnotationWrapper } from '../../../../../../models/file/annotation.wrap export interface AcceptRecommendationData { readonly annotations: AnnotationWrapper[]; - readonly file: File; + readonly dossierId: string; } export interface AcceptRecommendationReturnType { @@ -42,7 +42,7 @@ export class AcceptRecommendationDialogComponent extends BaseDialogComponent imp @Inject(MAT_DIALOG_DATA) readonly data: AcceptRecommendationData, ) { super(_injector, _dialogRef); - this._dossier = this._dossiersService.find(this.data.file.dossierId); + this._dossier = this._dossiersService.find(this.data.dossierId); this.isDocumentAdmin = this._permissionsService.isApprover(this._dossier); this.form = this._getForm(); this.initialFormValue = this.form.getRawValue(); 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 dc76c7d86..7134c5fe5 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 @@ -24,7 +24,7 @@ import { AnnotationDrawService } from './services/annotation-draw.service'; import { AnnotationProcessingService } from '../../services/annotation-processing.service'; import { File, ViewMode } from '@red/domain'; import { PermissionsService } from '@services/permissions.service'; -import { combineLatest, firstValueFrom, Observable, timer } from 'rxjs'; +import { combineLatest, firstValueFrom, Observable, of, timer } from 'rxjs'; import { UserPreferenceService } from '@services/user-preference.service'; import { PdfViewerDataService } from '../../services/pdf-viewer-data.service'; import { download } from '@utils/file-download-utils'; @@ -36,7 +36,7 @@ import { handleFilterDelta } from '@utils/filter-utils'; import { FilesService } from '@services/entity-services/files.service'; import { DossiersService } from '@services/entity-services/dossiers.service'; import { FileManagementService } from '@services/entity-services/file-management.service'; -import { filter, map, switchMap, tap } from 'rxjs/operators'; +import { catchError, filter, map, switchMap, tap } from 'rxjs/operators'; import { FilesMapService } from '@services/entity-services/files-map.service'; import { WatermarkService } from '@shared/services/watermark.service'; import { ExcludedPagesService } from './services/excluded-pages.service'; @@ -49,6 +49,7 @@ import { SkippedService } from './services/skipped.service'; import { FilePreviewStateService } from './services/file-preview-state.service'; import { FileDataModel } from '../../../../models/file/file-data.model'; import { filePreviewScreenProviders } from './utils'; +import { ManualAnnotationService } from '../../services/manual-annotation.service'; import Annotation = Core.Annotations.Annotation; import PDFNet = Core.PDFNet; @@ -106,6 +107,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni private readonly _reanalysisService: ReanalysisService, private readonly _errorService: ErrorService, private readonly _skippedService: SkippedService, + private readonly _manualAnnotationService: ManualAnnotationService, readonly excludedPagesService: ExcludedPagesService, readonly viewModeService: ViewModeService, readonly multiSelectService: MultiSelectService, @@ -188,7 +190,7 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } async ngOnAttach(previousRoute: ActivatedRouteSnapshot): Promise { - const file = this._filesMapService.get(this.dossierId, this.fileId); + const file = await this.stateService.file; if (!file.canBeOpened) { return this._router.navigate([this._dossiersService.find(this.dossierId)?.routerLink]); } @@ -205,9 +207,10 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni await this.userPreferenceService.saveLastOpenedFileForDossier(this.dossierId, this.fileId); this._subscribeToFileUpdates(); - const file = this._filesMapService.get(this.dossierId, this.fileId); + const file = await this.stateService.file; if (file?.analysisRequired) { - await this._reanalysisService.reanalyzeFilesForDossier([this.fileId], this.dossierId, true).toPromise(); + const reanalyzeFiles = this._reanalysisService.reanalyzeFilesForDossier([this.fileId], this.dossierId, true); + await firstValueFrom(reanalyzeFiles); } this.displayPdfViewer = true; @@ -278,18 +281,22 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni openManualAnnotationDialog(manualRedactionEntryWrapper: ManualRedactionEntryWrapper) { this._ngZone.run(() => { - const file = this._filesMapService.get(this.dossierId, this.fileId); this.dialogRef = this._dialogService.openDialog( 'manualAnnotation', null, - { manualRedactionEntryWrapper, file }, - async (response: ManualAnnotationResponse) => { + { manualRedactionEntryWrapper, dossierId: this.dossierId }, + async (entryWrapper: ManualRedactionEntryWrapper) => { + const addAnnotation$ = this._manualAnnotationService + .addAnnotation(entryWrapper.manualRedactionEntry, this.dossierId, this.fileId) + .pipe(catchError(() => of(undefined))); + const addAnnotationResponse = await firstValueFrom(addAnnotation$); + const response = new ManualAnnotationResponse(entryWrapper, addAnnotationResponse); + if (response?.annotationId) { const annotation = this._instance.Core.annotationManager.getAnnotationById( response.manualRedactionEntryWrapper.rectId, ); this._instance.Core.annotationManager.deleteAnnotation(annotation); - // await this._filesService.reload(this.dossierId, this.fileId).toPromise(); const distinctPages = manualRedactionEntryWrapper.manualRedactionEntry.positions .map(p => p.page) .filter((item, pos, self) => self.indexOf(item) === pos); diff --git a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/annotation-actions.service.ts b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/annotation-actions.service.ts index bd7727000..bc3598fee 100644 --- a/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/dossier/screens/file-preview-screen/services/annotation-actions.service.ts @@ -10,7 +10,7 @@ import { DossiersDialogService } from '../../../services/dossiers-dialog.service import { BASE_HREF } from '../../../../../tokens'; import { UserService } from '@services/user.service'; import { Core, WebViewerInstance } from '@pdftron/webviewer'; -import { Dossier, File, IAddRedactionRequest, ILegalBasisChangeRequest, IRectangle, IResizeRequest } from '@red/domain'; +import { Dossier, IAddRedactionRequest, ILegalBasisChangeRequest, IRectangle, IResizeRequest } from '@red/domain'; import { toPosition } from '../../../utils/pdf-calculation.utils'; import { AnnotationDrawService } from './annotation-draw.service'; import { translateQuads } from '@utils/pdf-coordinates'; @@ -42,42 +42,42 @@ export class AnnotationActionsService { private readonly _screenStateService: FilePreviewStateService, ) {} - acceptSuggestion( - $event: MouseEvent, - annotations: AnnotationWrapper[], - file: File, - annotationsChanged: EventEmitter, - ) { + private get _dossier(): Dossier { + return this._dossiersService.find(this._screenStateService.dossierId); + } + + acceptSuggestion($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { $event?.stopPropagation(); + const { dossierId, fileId } = this._screenStateService; annotations.forEach(annotation => { this._processObsAndEmit( - this._manualAnnotationService.approve(annotation.id, file, annotation.isModifyDictionary), + this._manualAnnotationService.approve(annotation.id, dossierId, fileId, annotation.isModifyDictionary), annotation, annotationsChanged, ); }); } - rejectSuggestion( - $event: MouseEvent, - annotations: AnnotationWrapper[], - file: File, - annotationsChanged: EventEmitter, - ) { + rejectSuggestion($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { $event?.stopPropagation(); + const { dossierId, fileId } = this._screenStateService; annotations.forEach(annotation => { - this._processObsAndEmit(this._manualAnnotationService.declineOrRemoveRequest(annotation, file), annotation, annotationsChanged); + this._processObsAndEmit( + this._manualAnnotationService.declineOrRemoveRequest(annotation, dossierId, fileId), + annotation, + annotationsChanged, + ); }); } forceAnnotation( $event: MouseEvent, annotations: AnnotationWrapper[], - file: File, annotationsChanged: EventEmitter, hint: boolean = false, ) { - const data = { dossier: this._dossier(file), hint }; + const { dossierId, fileId } = this._screenStateService; + const data = { dossier: this._dossier, hint }; this._dialogService.openDialog('forceAnnotation', $event, data, (request: ILegalBasisChangeRequest) => { annotations.forEach(annotation => { this._processObsAndEmit( @@ -86,7 +86,8 @@ export class AnnotationActionsService { ...request, annotationId: annotation.id, }, - file, + dossierId, + fileId, ), annotation, annotationsChanged, @@ -95,22 +96,19 @@ export class AnnotationActionsService { }); } - changeLegalBasis( - $event: MouseEvent, - annotations: AnnotationWrapper[], - file: File, - annotationsChanged: EventEmitter, - ) { + changeLegalBasis($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + const { dossierId, fileId } = this._screenStateService; this._dialogService.openDialog( 'changeLegalBasis', $event, - { annotations, dossier: this._dossier(file) }, + { annotations, dossier: this._dossier }, (data: { comment: string; legalBasis: string; section: string; value: string }) => { annotations.forEach(annotation => { this._processObsAndEmit( this._manualAnnotationService.changeLegalBasis( annotation.annotationId, - file, + dossierId, + fileId, data.section, data.value, data.legalBasis, @@ -127,20 +125,26 @@ export class AnnotationActionsService { removeOrSuggestRemoveAnnotation( $event: MouseEvent, annotations: AnnotationWrapper[], - file: File, removeFromDictionary: boolean, annotationsChanged: EventEmitter, ) { const data = { annotationsToRemove: annotations, removeFromDictionary, - dossier: this._dossier(file), + dossier: this._dossier, hint: annotations[0].hintDictionary, }; + const { dossierId, fileId } = this._screenStateService; this._dialogService.openDialog('removeAnnotations', $event, data, (result: { comment: string }) => { annotations.forEach(annotation => { this._processObsAndEmit( - this._manualAnnotationService.removeOrSuggestRemoveAnnotation(annotation, file, removeFromDictionary, result.comment), + this._manualAnnotationService.removeOrSuggestRemoveAnnotation( + annotation, + dossierId, + fileId, + removeFromDictionary, + result.comment, + ), annotation, annotationsChanged, ); @@ -148,28 +152,19 @@ export class AnnotationActionsService { }); } - markAsFalsePositive( - $event: MouseEvent, - annotations: AnnotationWrapper[], - file: File, - annotationsChanged: EventEmitter, - ) { + markAsFalsePositive($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { annotations.forEach(annotation => { - this._markAsFalsePositive($event, annotation, file, this._getFalsePositiveText(annotation), annotationsChanged); + this._markAsFalsePositive($event, annotation, this._getFalsePositiveText(annotation), annotationsChanged); }); } - recategorizeImages( - $event: MouseEvent, - annotations: AnnotationWrapper[], - file: File, - annotationsChanged: EventEmitter, - ) { - const data = { annotations, dossier: this._dossier(file) }; + recategorizeImages($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { + const data = { annotations, dossier: this._dossier }; + const { dossierId, fileId } = this._screenStateService; this._dialogService.openDialog('recategorizeImage', $event, data, (res: { type: string; comment: string }) => { annotations.forEach(annotation => { this._processObsAndEmit( - this._manualAnnotationService.recategorizeImg(annotation.annotationId, file, res.type, res.comment), + this._manualAnnotationService.recategorizeImg(annotation.annotationId, dossierId, fileId, res.type, res.comment), annotation, annotationsChanged, ); @@ -177,37 +172,37 @@ export class AnnotationActionsService { }); } - undoDirectAction( - $event: MouseEvent, - annotations: AnnotationWrapper[], - file: File, - annotationsChanged: EventEmitter, - ) { + undoDirectAction($event: MouseEvent, annotations: AnnotationWrapper[], annotationsChanged: EventEmitter) { $event?.stopPropagation(); + const { dossierId, fileId } = this._screenStateService; annotations.forEach(annotation => { - this._processObsAndEmit(this._manualAnnotationService.undoRequest(annotation, file), annotation, annotationsChanged); + this._processObsAndEmit( + this._manualAnnotationService.undoRequest(annotation, dossierId, fileId), + annotation, + annotationsChanged, + ); }); } convertRecommendationToAnnotation( $event: any, recommendations: AnnotationWrapper[], - file: File, annotationsChanged: EventEmitter, ) { $event?.stopPropagation(); + const { dossierId, fileId } = this._screenStateService; const dialogRef = this._dialog.open( AcceptRecommendationDialogComponent, - { ...defaultDialogConfig, autoFocus: true, data: { annotations: recommendations, file } }, + { ...defaultDialogConfig, autoFocus: true, data: { annotations: recommendations, dossierId } }, ); const dialogClosed = dialogRef.afterClosed().pipe(filter(value => !!value && !!value.annotations)); dialogClosed.subscribe(({ annotations, comment: commentText }) => { const comment = commentText ? { text: commentText } : undefined; annotations.forEach(annotation => { this._processObsAndEmit( - this._manualAnnotationService.addRecommendation(annotation, file, comment), + this._manualAnnotationService.addRecommendation(annotation, dossierId, fileId, comment), annotation, annotationsChanged, ); @@ -242,8 +237,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/check.svg'), title: this._translateService.instant('annotation-actions.resize-accept.label'), onClick: () => - this._runForCurrentFile(file => { - this.acceptResize(null, viewer, file, firstAnnotation, annotationsChanged); + this._ngZone.run(() => { + this.acceptResize(null, viewer, firstAnnotation, annotationsChanged); }), }); availableActions.push({ @@ -273,8 +268,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/edit.svg'), title: this._translateService.instant('annotation-actions.edit-reason.label'), onClick: () => - this._runForCurrentFile(file => { - this.changeLegalBasis(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.changeLegalBasis(null, annotations, annotationsChanged); }), }); } @@ -286,8 +281,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/thumb-down.svg'), title: this._translateService.instant('annotation-actions.recategorize-image'), onClick: () => - this._runForCurrentFile(file => { - this.recategorizeImages(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.recategorizeImages(null, annotations, annotationsChanged); }), }); } @@ -302,8 +297,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/remove-from-dict.svg'), title: this._translateService.instant('annotation-actions.remove-annotation.remove-from-dict'), onClick: () => - this._runForCurrentFile(file => { - this.removeOrSuggestRemoveAnnotation(null, annotations, file, true, annotationsChanged); + this._ngZone.run(() => { + this.removeOrSuggestRemoveAnnotation(null, annotations, true, annotationsChanged); }), }); } @@ -315,8 +310,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/check.svg'), title: this._translateService.instant('annotation-actions.accept-recommendation.label'), onClick: () => - this._runForCurrentFile(file => { - this.convertRecommendationToAnnotation(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.convertRecommendationToAnnotation(null, annotations, annotationsChanged); }), }); } @@ -328,8 +323,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/check.svg'), title: this._translateService.instant('annotation-actions.accept-suggestion.label'), onClick: () => - this._runForCurrentFile(file => { - this.acceptSuggestion(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.acceptSuggestion(null, annotations, annotationsChanged); }), }); } @@ -341,8 +336,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/undo.svg'), title: this._translateService.instant('annotation-actions.undo'), onClick: () => - this._runForCurrentFile(file => { - this.undoDirectAction(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.undoDirectAction(null, annotations, annotationsChanged); }), }); } @@ -354,8 +349,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/thumb-down.svg'), title: this._translateService.instant('annotation-actions.remove-annotation.false-positive'), onClick: () => - this._runForCurrentFile(file => { - this.markAsFalsePositive(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.markAsFalsePositive(null, annotations, annotationsChanged); }), }); } @@ -367,8 +362,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/thumb-up.svg'), title: this._translateService.instant('annotation-actions.force-redaction.label'), onClick: () => - this._runForCurrentFile(file => { - this.forceAnnotation(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.forceAnnotation(null, annotations, annotationsChanged); }), }); } @@ -380,8 +375,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/thumb-up.svg'), title: this._translateService.instant('annotation-actions.force-hint.label'), onClick: () => - this._runForCurrentFile(file => { - this.forceAnnotation(null, annotations, file, annotationsChanged, true); + this._ngZone.run(() => { + this.forceAnnotation(null, annotations, annotationsChanged, true); }), }); } @@ -393,8 +388,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/close.svg'), title: this._translateService.instant('annotation-actions.reject-suggestion'), onClick: () => - this._runForCurrentFile(file => { - this.rejectSuggestion(null, annotations, file, annotationsChanged); + this._ngZone.run(() => { + this.rejectSuggestion(null, annotations, annotationsChanged); }), }); } @@ -409,8 +404,8 @@ export class AnnotationActionsService { img: this._convertPath('/assets/icons/general/trash.svg'), title: this._translateService.instant('annotation-actions.remove-annotation.only-here'), onClick: () => - this._runForCurrentFile(file => { - this.removeOrSuggestRemoveAnnotation(null, annotations, file, false, annotationsChanged); + this._ngZone.run(() => { + this.removeOrSuggestRemoveAnnotation(null, annotations, false, annotationsChanged); }), }); } @@ -443,11 +438,11 @@ export class AnnotationActionsService { acceptResize( $event: MouseEvent, viewer: WebViewerInstance, - file: File, annotationWrapper: AnnotationWrapper, annotationsChanged?: EventEmitter, ) { - const data = { dossier: this._dossier(file) }; + const data = { dossier: this._dossier }; + const fileId = this._screenStateService.fileId; this._dialogService.openDialog('resizeAnnotation', $event, data, async (result: { comment: string }) => { const textAndPositions = await this._extractTextAndPositions(viewer, annotationWrapper.id); const text = @@ -461,7 +456,7 @@ export class AnnotationActionsService { }; this._processObsAndEmit( - this._manualAnnotationService.resizeOrSuggestToResize(annotationWrapper, file, resizeRequest), + this._manualAnnotationService.resizeOrSuggestToResize(annotationWrapper, data.dossier.dossierId, fileId, resizeRequest), annotationWrapper, annotationsChanged, ); @@ -486,17 +481,6 @@ export class AnnotationActionsService { annotationsChanged.emit(annotationWrapper); } - private async _runForCurrentFile(func: (file: File) => unknown): Promise { - const file = await this._screenStateService.file; - this._ngZone.run(() => { - func(file); - }); - } - - private _dossier(file: File): Dossier { - return this._dossiersService.find(file.dossierId); - } - private _processObsAndEmit( obs: Observable, annotation: AnnotationWrapper, @@ -531,7 +515,6 @@ export class AnnotationActionsService { private _markAsFalsePositive( $event: MouseEvent, annotation: AnnotationWrapper, - file: File, text: string, annotationsChanged: EventEmitter, ) { @@ -544,8 +527,13 @@ export class AnnotationActionsService { falsePositiveRequest.positions = annotation.positions; falsePositiveRequest.addToDictionary = true; falsePositiveRequest.comment = { text: 'False Positive' }; + const { dossierId, fileId } = this._screenStateService; - this._processObsAndEmit(this._manualAnnotationService.addAnnotation(falsePositiveRequest, file), annotation, annotationsChanged); + this._processObsAndEmit( + this._manualAnnotationService.addAnnotation(falsePositiveRequest, dossierId, fileId), + annotation, + annotationsChanged, + ); } private _convertPath(path: string): string { diff --git a/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts b/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts index 247d46473..bbf14433c 100644 --- a/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/manual-annotation.service.ts @@ -2,7 +2,6 @@ import { Injectable, Injector } from '@angular/core'; import { AppStateService } from '@state/app-state.service'; import { Dossier, - File, IAddRedactionRequest, IApproveRequest, IImageRecategorizationRequest, @@ -57,14 +56,15 @@ export class ManualAnnotationService extends GenericService _makeRequest( mode: AnnotationActionMode, - file: File, + dossierId: string, + fileId: string, body: any, secondParam: any = null, modifyDictionary = false, ): Observable { const obs = !secondParam - ? this[this.CONFIG[mode]](body, file.dossierId, file.id) - : this[this.CONFIG[mode]](body, secondParam, file.dossierId, file.id); + ? this[this.CONFIG[mode]](body, dossierId, fileId) + : this[this.CONFIG[mode]](body, secondParam, dossierId, fileId); return obs.pipe( tap({ @@ -74,7 +74,8 @@ export class ManualAnnotationService extends GenericService this._toaster.error(this._getMessage(mode, modifyDictionary, true, isConflict), { error, params: { - dictionaryName: this._appStateService.getDictionary(body.type, this._dossier(file).dossierTemplateId).label, + dictionaryName: this._appStateService.getDictionary(body.type, this._dossier(dossierId).dossierTemplateId) + .label, content: body.value, }, positionClass: 'toast-file-preview', @@ -96,7 +97,7 @@ export class ManualAnnotationService extends GenericService return super.delete({}, url); } - addRecommendation(annotation: AnnotationWrapper, file: File, comment = { text: 'Accepted Recommendation' }) { + addRecommendation(annotation: AnnotationWrapper, dossierId: string, fileId: string, comment = { text: 'Accepted Recommendation' }) { const manualRedactionEntry: IAddRedactionRequest = {}; manualRedactionEntry.addToDictionary = true; // set the ID as reason, so we can hide the suggestion @@ -105,76 +106,89 @@ export class ManualAnnotationService extends GenericService manualRedactionEntry.positions = annotation.positions; manualRedactionEntry.type = annotation.recommendationType; manualRedactionEntry.comment = comment; - return this.addAnnotation(manualRedactionEntry, file); + return this.addAnnotation(manualRedactionEntry, dossierId, fileId); } // /manualRedaction/request/legalBasis - changeLegalBasis(annotationId: string, file: File, section: string, value: string, legalBasis: string, comment?: string) { - const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(file)) + changeLegalBasis( + annotationId: string, + dossierId: string, + fileId: string, + section: string, + value: string, + legalBasis: string, + comment?: string, + ) { + const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(dossierId)) ? 'change-legal-basis' : 'request-change-legal-basis'; - return this._makeRequest(mode, file, { annotationId, legalBasis, comment, section, value }); + return this._makeRequest(mode, dossierId, fileId, { annotationId, legalBasis, comment, section, value }); } // this wraps // /manualRedaction/redaction/legalBasisChange // /manualRedaction/request/recategorize - recategorizeImg(annotationId: string, file: File, type: string, comment: string) { - const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(file)) + recategorizeImg(annotationId: string, dossierId: string, fileId: string, type: string, comment: string) { + const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(dossierId)) ? 'recategorize-image' : 'request-image-recategorization'; - return this._makeRequest(mode, file, { annotationId, type, comment }); + return this._makeRequest(mode, dossierId, fileId, { annotationId, type, comment }); } // this wraps // /manualRedaction/redaction/recategorize // /manualRedaction/request/add - addAnnotation(manualRedactionEntry: IAddRedactionRequest, file: File) { - const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(file)) ? 'add' : 'suggest'; - return this._makeRequest(mode, file, manualRedactionEntry, null, manualRedactionEntry.addToDictionary); + addAnnotation(manualRedactionEntry: IAddRedactionRequest, dossierId: string, fileId: string) { + const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(dossierId)) ? 'add' : 'suggest'; + return this._makeRequest(mode, dossierId, fileId, manualRedactionEntry, null, manualRedactionEntry.addToDictionary); } // this wraps // /manualRedaction/redaction/add // /manualRedaction/request/force - force(request: ILegalBasisChangeRequest, file: File) { - const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(file)) + force(request: ILegalBasisChangeRequest, dossierId: string, fileId: string) { + const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(dossierId)) ? 'force-redaction' : 'request-force-redaction'; - return this._makeRequest(mode, file, request); + return this._makeRequest(mode, dossierId, fileId, request); } // this wraps // /manualRedaction/redaction/force // /manualRedaction/approve - approve(annotationId: string, file: File, addToDictionary: boolean = false) { + approve(annotationId: string, dossierId: string, fileId: string, addToDictionary: boolean = false) { // for only here - approve the request - return this._makeRequest('approve', file, { addOrRemoveFromDictionary: addToDictionary }, annotationId, addToDictionary); + return this._makeRequest( + 'approve', + dossierId, + fileId, + { addOrRemoveFromDictionary: addToDictionary }, + annotationId, + addToDictionary, + ); } // this wraps - - undoRequest(annotationWrapper: AnnotationWrapper, file: File) { - return this._makeRequest('undo', file, annotationWrapper.id, null, annotationWrapper.isModifyDictionary); - } - // /manualRedaction/undo - declineOrRemoveRequest(annotationWrapper: AnnotationWrapper, file: File) { - const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(file)) ? 'decline' : 'undo'; - return this._makeRequest(mode, file, annotationWrapper.id, null, annotationWrapper.isModifyDictionary); + undoRequest(annotationWrapper: AnnotationWrapper, dossierId: string, fileId: string) { + return this._makeRequest('undo', dossierId, fileId, annotationWrapper.id, null, annotationWrapper.isModifyDictionary); } // this wraps // /manualRedaction/decline/remove + declineOrRemoveRequest(annotationWrapper: AnnotationWrapper, dossierId: string, fileId: string) { + const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(dossierId)) ? 'decline' : 'undo'; + return this._makeRequest(mode, dossierId, fileId, annotationWrapper.id, null, annotationWrapper.isModifyDictionary); + } // /manualRedaction/request/resize/ - resizeOrSuggestToResize(annotationWrapper: AnnotationWrapper, file: File, resizeRequest: IResizeRequest) { - const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(file)) ? 'resize' : 'request-resize'; - return this._makeRequest(mode, file, resizeRequest); + resizeOrSuggestToResize(annotationWrapper: AnnotationWrapper, dossierId: string, fileId: string, resizeRequest: IResizeRequest) { + const mode: AnnotationActionMode = this._permissionsService.isApprover(this._dossier(dossierId)) ? 'resize' : 'request-resize'; + return this._makeRequest(mode, dossierId, fileId, resizeRequest); } // this wraps @@ -183,7 +197,8 @@ export class ManualAnnotationService extends GenericService // /manualRedaction/request/remove/ removeOrSuggestRemoveAnnotation( annotationWrapper: AnnotationWrapper, - file: File, + dossierId: string, + fileId: string, removeFromDictionary: boolean = false, comment: string, ) { @@ -191,7 +206,7 @@ export class ManualAnnotationService extends GenericService body: any, removeDict = false; - if (this._permissionsService.isApprover(this._dossier(file))) { + if (this._permissionsService.isApprover(this._dossier(dossierId))) { // if it was something manual simply decline the existing request mode = 'remove'; body = { @@ -210,7 +225,7 @@ export class ManualAnnotationService extends GenericService removeDict = removeFromDictionary; } - return this._makeRequest(mode, file, body, null, removeDict); + return this._makeRequest(mode, dossierId, fileId, body, null, removeDict); } // this wraps @@ -353,8 +368,8 @@ export class ManualAnnotationService extends GenericService return this._post(body, url); } - private _dossier(file: File): Dossier { - return this._dossiersService.find(file.dossierId); + private _dossier(dossierId: string): Dossier { + return this._dossiersService.find(dossierId); } private _getMessage(mode: AnnotationActionMode, modifyDictionary?: boolean, error = false, isConflict = false) { diff --git a/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts b/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts index c903ad0c2..6b3507a45 100644 --- a/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts +++ b/apps/red-ui/src/app/modules/dossier/utils/pdf-viewer.utils.ts @@ -138,7 +138,7 @@ export class PdfViewerUtils { this._annotationManager.deselectAnnotations(ann); } - private _navigateToPage(pageNumber) { + private _navigateToPage(pageNumber: number) { if (this._currentInternalPage !== pageNumber) { this._documentViewer.displayPageLocation(pageNumber, 0, 0); } diff --git a/apps/red-ui/src/app/utils/filter-utils.ts b/apps/red-ui/src/app/utils/filter-utils.ts index 073584694..1b08223df 100644 --- a/apps/red-ui/src/app/utils/filter-utils.ts +++ b/apps/red-ui/src/app/utils/filter-utils.ts @@ -23,8 +23,6 @@ export function handleFilterDelta(oldFilters: INestedFilter[], newFilters: INest } } - console.log(newFiltersDelta); - for (const key of Object.keys(newFiltersDelta)) { const foundFilter = allFilters.find(f => f.id === key); if (foundFilter) {