From 41a794a2467281bc8b237a1b1d390a7b370d0531 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Tue, 7 Feb 2023 17:39:09 +0200 Subject: [PATCH] RED-6145: fix resizing for images & rectangles --- .../services/annotation-actions.service.ts | 1 - .../services/pdf-proxy.service.ts | 26 ++++++++++++++----- .../services/annotation-manager.service.ts | 3 ++- .../services/document-viewer.service.ts | 3 ++- .../app/modules/pdf-viewer/utils/constants.ts | 4 +++ 5 files changed, 28 insertions(+), 9 deletions(-) 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 8b6da0e1a..bdbf06f1c 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 @@ -192,7 +192,6 @@ export class AnnotationActionsService { this._annotationManager.delete(annotationWrapper); const rectangleAnnotation = this.#generateRectangle(annotationWrapper); await this._annotationManager.add(rectangleAnnotation); - this._annotationManager.select(rectangleAnnotation); return; } diff --git a/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts b/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts index 5a8f079b4..ece3bf308 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/pdf-proxy.service.ts @@ -20,7 +20,12 @@ import { ViewerHeaderService } from '../../pdf-viewer/services/viewer-header.ser import { ManualRedactionService } from './manual-redaction.service'; import { PdfViewer } from '../../pdf-viewer/services/pdf-viewer.service'; import { REDAnnotationManager } from '../../pdf-viewer/services/annotation-manager.service'; -import { ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED, HEADER_ITEMS_TO_TOGGLE, TEXT_POPUPS_TO_TOGGLE } from '../../pdf-viewer/utils/constants'; +import { + ALLOWED_ACTIONS_WHEN_PAGE_EXCLUDED, + AnnotationToolNames, + HEADER_ITEMS_TO_TOGGLE, + TEXT_POPUPS_TO_TOGGLE, +} from '../../pdf-viewer/utils/constants'; import { REDDocumentViewer } from '../../pdf-viewer/services/document-viewer.service'; import { combineLatest, Observable, Subject } from 'rxjs'; import { ViewModeService } from './view-mode.service'; @@ -160,10 +165,19 @@ export class PdfProxyService { return; } - const annotation = this._fileDataService.find(annotations[0].Id); - if (annotation?.resizing) { - this._annotationsActionsService.cancelResize(null, annotation).then(); + const annotation = annotations[0]; + const wrapper = this._fileDataService.find(annotation.Id); + if (!wrapper?.resizing) { + return; } + + // When resizing a rectangle, the original annotation is removed and triggers a deselect event and a new one is created + // So we want to skip the first deselect event. + if ((wrapper.isImage || wrapper.rectangle) && annotation.ToolName !== AnnotationToolNames.AnnotationCreateRectangle) { + return; + } + + this._annotationsActionsService.cancelResize(null, wrapper).then(); } private _configureElements() { @@ -307,7 +321,7 @@ export class PdfProxyService { if (!isCurrentPageExcluded) { if (this.canPerformActions) { try { - this._pdf.instance.UI.enableTools(['AnnotationCreateRectangle']); + this._pdf.instance.UI.enableTools([AnnotationToolNames.AnnotationCreateRectangle]); } catch (e) { // happens } @@ -318,7 +332,7 @@ export class PdfProxyService { this._pdf.enable([TextPopups.ADD_DICTIONARY, TextPopups.ADD_FALSE_POSITIVE]); } } else { - this._pdf.instance.UI.disableTools(['AnnotationCreateRectangle']); + this._pdf.instance.UI.disableTools([AnnotationToolNames.AnnotationCreateRectangle]); this._pdf.disable(TEXT_POPUPS_TO_TOGGLE); this._viewerHeaderService.disable(HEADER_ITEMS_TO_TOGGLE); } diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts index 9f1943edf..d17a81d54 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/annotation-manager.service.ts @@ -7,6 +7,7 @@ import { fromEvent, Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; import { asList, getId, isStringOrWrapper } from '../utils/functions'; import { getLast } from '@utils/functions'; +import { AnnotationToolNames } from '../utils/constants'; import AnnotationManager = Core.AnnotationManager; import Annotation = Core.Annotations.Annotation; @@ -120,7 +121,7 @@ export class REDAnnotationManager { // when a rectangle is drawn, // it returns one annotation with tool name 'AnnotationCreateRectangle; // this will auto select rectangle after drawing - if (annotations.length === 1 && annotations[0].ToolName === 'AnnotationCreateRectangle') { + if (annotations.length === 1 && annotations[0].ToolName === AnnotationToolNames.AnnotationCreateRectangle) { this.#manager.selectAnnotations(annotations); annotations[0].disableRotationControl(); } diff --git a/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts b/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts index 3b3e9e2d0..cca642fef 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/services/document-viewer.service.ts @@ -9,6 +9,7 @@ import { UserPreferenceService } from '@users/user-preference.service'; import { log, shareLast } from '@iqser/common-ui'; import { stopAndPrevent, stopAndPreventIfNotAllowed } from '../utils/functions'; import { RotationType, RotationTypes } from '@red/domain'; +import { AnnotationToolNames } from '../utils/constants'; import DocumentViewer = Core.DocumentViewer; import Color = Core.Annotations.Color; import Quad = Core.Math.Quad; @@ -135,7 +136,7 @@ export class REDDocumentViewer { } setRectangleToolStyles(color: Color) { - this.#document.getTool('AnnotationCreateRectangle').setStyles({ + this.#document.getTool(AnnotationToolNames.AnnotationCreateRectangle).setStyles({ StrokeThickness: 2, StrokeColor: color, FillColor: color, diff --git a/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts b/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts index 6f3ce0c6d..51396e3c6 100644 --- a/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts +++ b/apps/red-ui/src/app/modules/pdf-viewer/utils/constants.ts @@ -87,3 +87,7 @@ export const DISABLED_HOTKEYS = [ 'K', 'U', ] as const; + +export const AnnotationToolNames = { + AnnotationCreateRectangle: 'AnnotationCreateRectangle', +} as const;