From ffac0fb42019f4d3f18073caeb37c1575c6243ed Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Mon, 11 Apr 2022 17:15:11 +0300 Subject: [PATCH] RED-3747: check pages not out of bounds, fix rectangle deletion time --- .../components/pdf-viewer/pdf-viewer.component.ts | 2 -- .../manual-annotation-dialog.component.html | 9 +++++++-- .../manual-annotation-dialog.component.ts | 12 ++++++++---- .../file-preview/file-preview-screen.component.ts | 13 +++++++++---- 4 files changed, 24 insertions(+), 12 deletions(-) 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 4e389bd61..d1abb67d5 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 @@ -415,13 +415,11 @@ export class PdfViewerComponent extends AutoUnsubscribe implements OnInit, OnCha const quads = [this._annotationDrawService.annotationToQuads(activeAnnotation)]; const manualRedactionEntry = this._getManualRedaction({ [activePage]: quads }); this._cleanUpSelectionAndButtonState(); - this.pdfViewer.deleteAnnotations([activeAnnotation.Id]); this.manualAnnotationRequested.emit({ manualRedactionEntry, type: 'REDACTION' }); } private _cleanUpSelectionAndButtonState() { - this.pdfViewer.deselectAllAnnotations(); this._headerConfigService.disable([HeaderElements.SHAPE_TOOL_GROUP_BUTTON]); this._headerConfigService.enable([HeaderElements.SHAPE_TOOL_GROUP_BUTTON]); } diff --git a/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html b/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html index bb0fbcd81..6102f2b82 100644 --- a/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html +++ b/apps/red-ui/src/app/modules/file-preview/dialogs/manual-redaction-dialog/manual-annotation-dialog.component.html @@ -88,11 +88,16 @@
- + {{ 'manual-annotation.dialog.content.apply-on-multiple-pages' | translate }} -
+
, - @Inject(MAT_DIALOG_DATA) readonly data: { manualRedactionEntryWrapper: ManualRedactionEntryWrapper; dossierId: string }, + @Inject(MAT_DIALOG_DATA) readonly data: { manualRedactionEntryWrapper: ManualRedactionEntryWrapper; dossierId: string; file: File }, ) { super(_injector, _dialogRef); this._dossier = this._activeDossiersService.find(this.data.dossierId); @@ -70,7 +71,7 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme } get disabled() { - return this.form.invalid; + return this.form.invalid || (this.applyOnMultiplePages && !this.form.get('multiplePages')?.value); } async ngOnInit() { @@ -116,11 +117,14 @@ export class ManualAnnotationDialogComponent extends BaseDialogComponent impleme const splitted = range.split('-'); const startPage = parseInt(splitted[0], 10); const endPage = splitted.length > 1 ? parseInt(splitted[1], 10) : startPage; - if (!startPage || !endPage) { + if (!startPage || !endPage || startPage > this.data.file.numberOfPages || endPage > this.data.file.numberOfPages) { throw new Error(); } for (let page = startPage; page <= endPage; page++) { + if (page === wrapper.manualRedactionEntry.positions[0].page) { + continue; + } const manualRedactionEntry = { ...entry, positions: [{ ...quads, page }] }; wrappers.push({ ...wrapper, manualRedactionEntry }); } 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 80def0dde..48e6f2bf0 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 @@ -250,13 +250,18 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni } openManualAnnotationDialog(manualRedactionEntryWrapper: ManualRedactionEntryWrapper) { - this._ngZone.run(() => { + return this._ngZone.run(async () => { + const file = await this.state.file; + this.dialogRef = this._dialogService.openDialog( 'manualAnnotation', null, - { manualRedactionEntryWrapper, dossierId: this.dossierId }, - async (wrappers: ManualRedactionEntryWrapper[]) => { - const file = await this.state.file; + { manualRedactionEntryWrapper, dossierId: this.dossierId, file }, + (wrappers: ManualRedactionEntryWrapper[]) => { + const selectedAnnotations = this.pdf.annotationManager.getSelectedAnnotations(); + if (selectedAnnotations.length > 0) { + this.pdf.deleteAnnotations([selectedAnnotations[0].Id]); + } const add$ = this._manualRedactionService.addAnnotation( wrappers.map(w => w.manualRedactionEntry).filter(e => e.positions[0].page <= file.numberOfPages), this.dossierId,