Refactor dossiers dialog service: manual annotation

This commit is contained in:
Adina Țeudan 2021-08-10 15:39:15 +03:00
parent 92fcc329ba
commit 50455186eb
2 changed files with 26 additions and 40 deletions

View File

@ -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);
});
}
}
});
);
});
}

View File

@ -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<DialogType> {
},
forceRedaction: {
component: ForceRedactionDialogComponent
},
manualAnnotation: {
component: ManualAnnotationDialogComponent,
dialogConfig: { autoFocus: true }
}
};
@ -92,20 +88,4 @@ export class DossiersDialogService extends DialogService<DialogType> {
) {
super(_dialog);
}
openManualAnnotationDialog($event: ManualRedactionEntryWrapper, cb?: Function): MatDialogRef<ManualAnnotationDialogComponent> {
const ref = this._dialog.open(ManualAnnotationDialogComponent, {
...dialogConfig,
autoFocus: true,
data: $event
});
ref.afterClosed().subscribe(result => {
if (cb) {
cb(result);
}
});
return ref;
}
}