Skip to content

Commit 2fd7335

Browse files
committed
annotation added and removed
1 parent 0c1b7b9 commit 2fd7335

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
3838

3939
if (studyDataUI["annotations"]) {
4040
Object.entries(studyDataUI["annotations"]).forEach(([annotationId, annotationData]) => {
41-
const annotation = new osparc.workbench.Annotation(annotationData, annotationId);
42-
this.addAnnotation(annotation);
41+
this.addAnnotation(annotationData, annotationId);
4342
});
4443
}
4544

@@ -96,6 +95,8 @@ qx.Class.define("osparc.data.model.StudyUI", {
9695

9796
events: {
9897
"projectDocumentChanged": "qx.event.type.Data",
98+
"annotationAdded": "qx.event.type.Data",
99+
"annotationRemoved": "qx.event.type.Data",
99100
},
100101

101102
statics: {
@@ -121,7 +122,8 @@ qx.Class.define("osparc.data.model.StudyUI", {
121122
}
122123
},
123124

124-
addAnnotation: function(annotation) {
125+
addAnnotation: function(annotationData, annotationId) {
126+
const annotation = new osparc.workbench.Annotation(annotationData, annotationId);
125127
this.getAnnotations()[annotation.getId()] = annotation;
126128
this.fireDataEvent("projectDocumentChanged", {
127129
"op": "add",
@@ -137,6 +139,7 @@ qx.Class.define("osparc.data.model.StudyUI", {
137139
"osparc-resource": "study-ui",
138140
});
139141
}, this);
142+
return annotation;
140143
},
141144

142145
removeAnnotation: function(annotationId) {
@@ -172,6 +175,9 @@ qx.Class.define("osparc.data.model.StudyUI", {
172175
}
173176
});
174177
}
178+
} else if ("annotations" in uiDiff) {
179+
const annotationsDiff = uiDiff["annotations"];
180+
this.__updateAnnotationsFromDiff(annotationsDiff);
175181
}
176182
},
177183

@@ -206,6 +212,23 @@ qx.Class.define("osparc.data.model.StudyUI", {
206212
}
207213
},
208214

215+
__updateAnnotationsFromDiff: function(annotationsData) {
216+
// check if annotation data is an object or an array
217+
if (annotationsData instanceof Object) {
218+
Object.entries(annotationsData).forEach(([annotationId, annotationData]) => {
219+
if (annotationData.length === 1) {
220+
// it was added
221+
const annotation = this.addAnnotation(annotationData[0], annotationId);
222+
this.fireDataEvent("annotationAdded", annotation);
223+
} else if (annotationData.length === 3 && annotationData[1] === null) {
224+
// it was removed
225+
this.removeAnnotation(annotationId);
226+
this.fireDataEvent("annotationRemoved", annotationId);
227+
}
228+
});
229+
}
230+
},
231+
209232
listenToChanges: function() {
210233
const propertyKeys = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.StudyUI));
211234
this.self().ListenChangesProps.forEach(key => {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,14 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
12071207
Object.values(annotations).forEach(annotation => {
12081208
this.__renderAnnotation(annotation);
12091209
});
1210+
studyUI.addListener("annotationAdded", e => {
1211+
const annotation = e.getData();
1212+
this.__renderAnnotation(annotation);
1213+
}, this);
1214+
studyUI.addListener("annotationRemoved", e => {
1215+
const annotationId = e.getData();
1216+
this.__removeAnnotation(annotationId);
1217+
}, this);
12101218
},
12111219

12121220
__setSelectedItem: function(newID) {
@@ -2018,9 +2026,8 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
20182026
this.__toolHint.setValue(null);
20192027
},
20202028

2021-
__addAnnotation: function(annotationData, id) {
2022-
const annotation = new osparc.workbench.Annotation(annotationData, id);
2023-
this.getStudy().getUi().addAnnotation(annotation);
2029+
__addAnnotation: function(annotationData) {
2030+
const annotation = this.getStudy().getUi().addAnnotation(annotationData);
20242031

20252032
this.__renderAnnotation(annotation);
20262033

0 commit comments

Comments
 (0)