Skip to content

Commit bcb62ec

Browse files
committed
listen to annotationChanged
1 parent e6e3840 commit bcb62ec

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,30 @@ qx.Class.define("osparc.data.model.StudyUI", {
114114

115115
addAnnotation: function(annotation) {
116116
this.getAnnotations()[annotation.getId()] = annotation;
117+
this.fireDataEvent("projectDocumentChanged", {
118+
"op": "add",
119+
"path": `/ui/annotations/${annotation.getId()}`,
120+
"value": annotation.serialize(),
121+
"osparc-resource": "study-ui",
122+
});
123+
annotation.addListener("annotationChanged", () => {
124+
this.fireDataEvent("projectDocumentChanged", {
125+
"op": "replace",
126+
"path": `/ui/annotations/${annotation.getId()}`,
127+
"value": annotation.serialize(),
128+
"osparc-resource": "study-ui",
129+
});
130+
}, this);
117131
},
118132

119133
removeAnnotation: function(annotationId) {
120134
if (annotationId in this.getAnnotations()) {
135+
const annotation = this.getAnnotations()[annotationId]
136+
this.fireDataEvent("projectDocumentChanged", {
137+
"op": "delete",
138+
"path": `/ui/annotations/${annotation.getId()}`,
139+
"osparc-resource": "study-ui",
140+
});
121141
delete this.getAnnotations()[annotationId];
122142
}
123143
},

services/static-webserver/client/source/class/osparc/workbench/Annotation.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ qx.Class.define("osparc.workbench.Annotation", {
7878
attributes: {
7979
check: "Object",
8080
nullable: false,
81+
apply: "__applyAttributes",
8182
},
8283

8384
svgCanvas: {
@@ -95,7 +96,8 @@ qx.Class.define("osparc.workbench.Annotation", {
9596
"annotationClicked": "qx.event.type.Data",
9697
"annotationStartedMoving": "qx.event.type.Event",
9798
"annotationMoving": "qx.event.type.Event",
98-
"annotationStoppedMoving": "qx.event.type.Event"
99+
"annotationStoppedMoving": "qx.event.type.Event",
100+
"annotationChanged": "qx.event.type.Event",
99101
},
100102

101103
members: {
@@ -174,6 +176,14 @@ qx.Class.define("osparc.workbench.Annotation", {
174176
osparc.wrapper.Svg.updateTextColor(representation, color);
175177
break;
176178
}
179+
this.fireEvent("annotationChanged");
180+
}
181+
},
182+
183+
__applyAttributes: function(attrs) {
184+
const representation = this.getRepresentation();
185+
if (representation) {
186+
this.fireEvent("annotationChanged");
177187
}
178188
},
179189

@@ -223,6 +233,7 @@ qx.Class.define("osparc.workbench.Annotation", {
223233
this.getAttributes().x = x;
224234
this.getAttributes().y = y;
225235
}
236+
this.fireEvent("annotationChanged");
226237
},
227238

228239
setText: function(newText) {

0 commit comments

Comments
 (0)