Skip to content

Commit 4305445

Browse files
committed
update attributes working
1 parent b5986df commit 4305445

File tree

1 file changed

+48
-8
lines changed
  • services/static-webserver/client/source/class/osparc/data/model

1 file changed

+48
-8
lines changed

services/static-webserver/client/source/class/osparc/data/model/StudyUI.js

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,54 @@ qx.Class.define("osparc.data.model.StudyUI", {
353353
const value = patch.value;
354354
const annotationId = path.split("/")[3];
355355
console.log("Updating annotation from patch", patch);
356-
if (op === "add") {
357-
this.addAnnotation(value, annotationId);
358-
} else if (op === "remove") {
359-
// it was removed
360-
this.removeAnnotation(annotationId);
361-
} else if (op === "replace" && value) {
362-
// it was updated
363-
console.log("Updating annotation", annotationId, "with value", value);
356+
switch (op) {
357+
case "add": {
358+
const annotation = this.addAnnotation(value, annotationId);
359+
this.fireDataEvent("annotationAdded", annotation);
360+
break;
361+
}
362+
case "remove":
363+
this.removeAnnotation(annotationId);
364+
this.fireDataEvent("annotationRemoved", annotationId);
365+
break;
366+
case "replace":
367+
if (annotationId in this.getAnnotations()) {
368+
const annotation = this.getAnnotations()[annotationId];
369+
if (annotation) {
370+
if (path.includes("/color")) {
371+
annotation.setColor(value);
372+
} else if (path.includes("/attributes")) {
373+
this.__updateAnnotationAttributesFromPatch(annotation, path, value);
374+
}
375+
}
376+
}
377+
break;
378+
}
379+
},
380+
381+
__updateAnnotationAttributesFromPatch: function(annotation, path, value) {
382+
if (annotation) {
383+
const attribute = path.split("/")[5];
384+
switch (attribute) {
385+
case "x": {
386+
const newPos = annotation.getPosition();
387+
newPos.x = value;
388+
annotation.setPosition(newPos.x, newPos.y);
389+
break;
390+
}
391+
case "y": {
392+
const newPos = annotation.getPosition();
393+
newPos.y = value;
394+
annotation.setPosition(newPos.x, newPos.y);
395+
break;
396+
}
397+
case "fontSize":
398+
annotation.setFontSize(value);
399+
break;
400+
case "text":
401+
annotation.setText(value);
402+
break;
403+
}
364404
}
365405
},
366406

0 commit comments

Comments
 (0)