From fd1f14a76a0eebfccda36ce5890c3fe52bfadf87 Mon Sep 17 00:00:00 2001 From: ivmartel Date: Wed, 24 Jul 2024 16:00:03 +0200 Subject: [PATCH] Add keys to annotation update event --- src/app/drawController.js | 5 +++-- src/image/annotation.js | 6 ++++-- src/tools/drawCommands.js | 14 ++++++++------ src/tools/drawShapeEditor.js | 3 ++- src/tools/drawShapeHandler.js | 6 ++++-- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/app/drawController.js b/src/app/drawController.js index 86ab80f7c4..38735f6b92 100644 --- a/src/app/drawController.js +++ b/src/app/drawController.js @@ -51,9 +51,10 @@ export class DrawController { * Update an anotation from the list. * * @param {Annotation} annotation The annotation to update. + * @param {string[]} [propKeys] Optional properties that got updated. */ - updateAnnotation(annotation) { - this.#annotationGroup.update(annotation); + updateAnnotation(annotation, propKeys) { + this.#annotationGroup.update(annotation, propKeys); } /** diff --git a/src/image/annotation.js b/src/image/annotation.js index 58cdeb3202..090b960622 100644 --- a/src/image/annotation.js +++ b/src/image/annotation.js @@ -295,14 +295,16 @@ export class AnnotationGroup { * Update an existing annotation. * * @param {Annotation} annotation The annotation to update. + * @param {string[]} [propKeys] Optional properties that got updated. */ - update(annotation) { + update(annotation, propKeys) { const index = this.#list.findIndex((item) => item.id === annotation.id); if (index !== -1) { this.#list[index] = annotation; this.#fireEvent({ type: 'annotationupdate', - data: annotation + data: annotation, + keys: propKeys }); } else { logger.warn('Cannot find annotation to update'); diff --git a/src/tools/drawCommands.js b/src/tools/drawCommands.js index 6747eb7dc1..3e9b14c9e5 100644 --- a/src/tools/drawCommands.js +++ b/src/tools/drawCommands.js @@ -181,20 +181,22 @@ export class UpdateAnnotationCommand { * Execute the command. */ execute() { - for (const prop in this.#newProps) { - this.#annotation[prop] = this.#newProps[prop]; + const keys = Object.keys(this.#newProps); + for (const key of keys) { + this.#annotation[key] = this.#newProps[key]; } - this.#drawController.updateAnnotation(this.#annotation); + this.#drawController.updateAnnotation(this.#annotation, keys); } /** * Undo the command. */ undo() { - for (const prop in this.#originalProps) { - this.#annotation[prop] = this.#originalProps[prop]; + const keys = Object.keys(this.#originalProps); + for (const key of keys) { + this.#annotation[key] = this.#originalProps[key]; } - this.#drawController.updateAnnotation(this.#annotation); + this.#drawController.updateAnnotation(this.#annotation, keys); } } /** diff --git a/src/tools/drawShapeEditor.js b/src/tools/drawShapeEditor.js index a94e11280b..c6d27f922b 100644 --- a/src/tools/drawShapeEditor.js +++ b/src/tools/drawShapeEditor.js @@ -346,7 +346,8 @@ export class DrawShapeEditor { this.#eventCallback({ type: 'annotationupdate', data: this.#annotation, - dataid: this.#drawLayer.getDataId() + dataid: this.#drawLayer.getDataId(), + keys: Object.keys(newProps) }); // update original properties originalProps = { diff --git a/src/tools/drawShapeHandler.js b/src/tools/drawShapeHandler.js index 5412c9ac63..15ba27f844 100644 --- a/src/tools/drawShapeHandler.js +++ b/src/tools/drawShapeHandler.js @@ -410,7 +410,8 @@ export class DrawShapeHandler { this.#eventCallback({ type: 'annotationupdate', data: annotation, - dataid: drawLayer.getDataId() + dataid: drawLayer.getDataId(), + keys: Object.keys(newProps) }); // update original shape originalProps = { @@ -467,7 +468,8 @@ export class DrawShapeHandler { this.#eventCallback({ type: 'annotationupdate', data: annotation, - dataid: drawLayer.getDataId() + dataid: drawLayer.getDataId(), + keys: ['labelPosition'] }); // update original position originalLabelPosition = newLabelPosition;