From 677c8db116f13fa444cc40f684bfd224ee03b4d2 Mon Sep 17 00:00:00 2001 From: Valentin Mihai Date: Tue, 3 Oct 2023 14:20:49 +0300 Subject: [PATCH] RED-7673 - Resize accept and decline actions not available in the document viewer --- .../annotation-actions.component.html | 1 + .../annotation-actions/annotation-actions.component.ts | 4 ++++ .../services/annotation-actions.service.ts | 1 + .../services/pdf-annotation-actions.service.ts | 2 +- .../modules/file-preview/services/pdf-proxy.service.ts | 5 +---- .../pdf-viewer/services/annotation-manager.service.ts | 10 ++++++++++ 6 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html index 23d3978c5..d0216b725 100644 --- a/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html +++ b/apps/red-ui/src/app/modules/file-preview/components/annotation-actions/annotation-actions.component.html @@ -7,6 +7,7 @@ a.superType === type); 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 689a725bb..33a65fcdd 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 @@ -272,6 +272,7 @@ export class AnnotationActionsService { async cancelResize(annotationWrapper: AnnotationWrapper) { this._annotationManager.resizingAnnotationId = undefined; + this._annotationManager.annotationHasBeenResized = false; this._annotationManager.delete(annotationWrapper); await this._annotationDrawService.draw([annotationWrapper], this._skippedService.hideSkipped(), this._state.dossierTemplateId); this._annotationManager.deselect(); diff --git a/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts b/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts index ec6c0c68d..7312cdf41 100644 --- a/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts +++ b/apps/red-ui/src/app/modules/file-preview/services/pdf-annotation-actions.service.ts @@ -40,7 +40,7 @@ export class PdfAnnotationActionsService { this.#annotationActionsService.cancelResize(firstAnnotation), ); - return [acceptResizeButton, cancelResizeButton]; + return this.#annotationManager.annotationHasBeenResized ? [acceptResizeButton, cancelResizeButton] : [cancelResizeButton]; } const resizeButton = this.#getButton('resize', _('annotation-actions.resize.label'), () => 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 4c190375d..d75331b30 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 @@ -306,10 +306,7 @@ export class PdfProxyService { nextAnnotations = this._annotationManager.selected; } - const annotationWasResized = this._annotationManager.resizingAnnotationId && action === 'modify'; - if (!this._annotationManager.resizingAnnotationId || annotationWasResized) { - this.#configureAnnotationSpecificActions(nextAnnotations); - } + this.#configureAnnotationSpecificActions(nextAnnotations); if (!(annotations.length === 1 && annotations[0].ReadOnly)) { this._pdf.enable(TextPopups.ADD_RECTANGLE); 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 e19af623a..9fb9e0b00 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 @@ -11,6 +11,10 @@ import { AnnotationPredicate, DeleteAnnotationsOptions } from '../utils/types'; import AnnotationManager = Core.AnnotationManager; import Annotation = Core.Annotations.Annotation; +const MODIFY_ACTION = 'modify'; +const RESIZE_OPTION = 'resize'; +const MOVE_OPTION = 'move'; + @Injectable() export class REDAnnotationManager { readonly #hidden = signal(new Set()); @@ -19,6 +23,7 @@ export class REDAnnotationManager { readonly #annotationSelected$ = new Subject<[Annotation[], string]>(); readonly annotationSelected$ = this.#annotationSelected$.asObservable(); resizingAnnotationId?: string = undefined; + annotationHasBeenResized?: boolean = false; readonly hidden = this.#hidden.asReadonly(); get selected() { @@ -146,6 +151,11 @@ export class REDAnnotationManager { #autoSelectRectangleAfterCreation() { this.#manager.addEventListener('annotationChanged', (annotations: Annotation[], action: string, options) => { this.#logger.info('[ANNOTATIONS] Annotations changed: ', annotations, action, options); + + if (action === MODIFY_ACTION && (options.source === RESIZE_OPTION || options.source === MOVE_OPTION)) { + this.annotationHasBeenResized = true; + } + // when a rectangle is drawn, // it returns one annotation with tool name 'AnnotationCreateRectangle; // this will auto select rectangle after drawing