From 50455186eb4e1f4981c56303fe1ec9dde13c2d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Tue, 10 Aug 2021 15:39:15 +0300 Subject: [PATCH] Refactor dossiers dialog service: manual annotation --- .../file-preview-screen.component.ts | 32 ++++++++++------- .../services/dossiers-dialog.service.ts | 34 ++++--------------- 2 files changed, 26 insertions(+), 40 deletions(-) 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 7050ca463..d19f81fe7 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 @@ -323,21 +323,27 @@ export class FilePreviewScreenComponent extends AutoUnsubscribeComponent impleme this._workloadComponent?.scrollAnnotationsToPage(pageNumber, 'always'); } - openManualAnnotationDialog($event: ManualRedactionEntryWrapper) { + openManualAnnotationDialog(entryWrapper: ManualRedactionEntryWrapper) { this._ngZone.run(() => { - this.dialogRef = this._dialogService.openManualAnnotationDialog($event, async (response: ManualAnnotationResponse) => { - if (response?.annotationId) { - const annotation = this._instance.annotManager.getAnnotationById(response.manualRedactionEntryWrapper.rectId); - this._instance.annotManager.deleteAnnotation(annotation); - this.fileData.fileStatus = await this.appStateService.reloadActiveFile(); - const distinctPages = $event.manualRedactionEntry.positions - .map(p => p.page) - .filter((item, pos, self) => self.indexOf(item) === pos); - distinctPages.forEach(page => { - this._cleanupAndRedrawManualAnnotationsForEntirePage(page); - }); + console.log({ entryWrapper }); + this.dialogRef = this._dialogService.openDialog( + 'manualAnnotation', + null, + entryWrapper, + async (response: ManualAnnotationResponse) => { + if (response?.annotationId) { + const annotation = this._instance.annotManager.getAnnotationById(response.manualRedactionEntryWrapper.rectId); + this._instance.annotManager.deleteAnnotation(annotation); + this.fileData.fileStatus = await this.appStateService.reloadActiveFile(); + const distinctPages = entryWrapper.manualRedactionEntry.positions + .map(p => p.page) + .filter((item, pos, self) => self.indexOf(item) === pos); + distinctPages.forEach(page => { + this._cleanupAndRedrawManualAnnotationsForEntirePage(page); + }); + } } - }); + ); }); } diff --git a/apps/red-ui/src/app/modules/dossier/services/dossiers-dialog.service.ts b/apps/red-ui/src/app/modules/dossier/services/dossiers-dialog.service.ts index 96adebc58..33e1eb7a8 100644 --- a/apps/red-ui/src/app/modules/dossier/services/dossiers-dialog.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/dossiers-dialog.service.ts @@ -1,12 +1,11 @@ import { Injectable } from '@angular/core'; -import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog'; +import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; import { AddDossierDialogComponent } from '../dialogs/add-dossier-dialog/add-dossier-dialog.component'; import { RemoveAnnotationsDialogComponent } from '../dialogs/remove-annotations-dialog/remove-annotations-dialog.component'; import { ForceRedactionDialogComponent } from '../dialogs/force-redaction-dialog/force-redaction-dialog.component'; import { ConfirmationDialogComponent } from '@shared/dialogs/confirmation-dialog/confirmation-dialog.component'; import { DocumentInfoDialogComponent } from '../dialogs/document-info-dialog/document-info-dialog.component'; import { AppStateService } from '@state/app-state.service'; -import { ManualRedactionEntryWrapper } from '@models/file/manual-redaction-entry.wrapper'; import { ManualAnnotationService } from './manual-annotation.service'; import { ManualAnnotationDialogComponent } from '../dialogs/manual-redaction-dialog/manual-annotation-dialog.component'; import { DossierDictionaryDialogComponent } from '../dialogs/dossier-dictionary-dialog/dossier-dictionary-dialog.component'; @@ -18,14 +17,6 @@ import { RecategorizeImageDialogComponent } from '../dialogs/recategorize-image- import { DialogService, largeDialogConfig } from '@shared/services/dialog.service'; import { ComponentType } from '@angular/cdk/portal'; -const dialogConfig = { - width: '662px', - maxWidth: '90vw', - autoFocus: false -} as const; - -// TODO: Continue refactor - type DialogType = | 'confirm' | 'documentInfo' @@ -36,7 +27,8 @@ type DialogType = | 'changeLegalBasis' | 'dossierDictionary' | 'removeAnnotations' - | 'forceRedaction'; + | 'forceRedaction' + | 'manualAnnotation'; type DossiersDialogConfig = { [key in DialogType]: { @@ -81,6 +73,10 @@ export class DossiersDialogService extends DialogService { }, forceRedaction: { component: ForceRedactionDialogComponent + }, + manualAnnotation: { + component: ManualAnnotationDialogComponent, + dialogConfig: { autoFocus: true } } }; @@ -92,20 +88,4 @@ export class DossiersDialogService extends DialogService { ) { super(_dialog); } - - openManualAnnotationDialog($event: ManualRedactionEntryWrapper, cb?: Function): MatDialogRef { - const ref = this._dialog.open(ManualAnnotationDialogComponent, { - ...dialogConfig, - autoFocus: true, - data: $event - }); - - ref.afterClosed().subscribe(result => { - if (cb) { - cb(result); - } - }); - - return ref; - } }