Skip to content

Commit 5f6f8e8

Browse files
committed
annotations done
1 parent 586f62a commit 5f6f8e8

File tree

1 file changed

+46
-25
lines changed
  • services/static-webserver/client/source/class/osparc/data/model

1 file changed

+46
-25
lines changed

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

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ qx.Class.define("osparc.data.model.StudyUI", {
177177
}
178178
}
179179
if (uiDiff["annotations"]) {
180-
const annotationsData = uiDiff["annotations"];
181-
this.__updateAnnotationsFromDiff(annotationsData);
180+
const annotationsDiff = uiDiff["annotations"];
181+
this.__updateAnnotationsFromDiff(annotationsDiff);
182182
}
183183
},
184184

@@ -226,35 +226,56 @@ qx.Class.define("osparc.data.model.StudyUI", {
226226
}
227227
},
228228

229-
__updateAnnotationsFromDiff: function(annotationsData) {
229+
__updateAnnotationsFromDiff: function(annotationsDiff) {
230230
// check if annotation data is an object or an array
231231
const annotations = this.getAnnotations();
232-
Object.entries(annotationsData).forEach(([annotationId, annotationDiff]) => {
233-
if (annotationDiff instanceof Array) {
234-
if (annotationDiff.length === 1) {
235-
// it was added
236-
const annotation = this.addAnnotation(annotationDiff[0], annotationId);
237-
this.fireDataEvent("annotationAdded", annotation);
238-
} else if (annotationDiff.length === 3 && annotationDiff[1] === 0) {
239-
// it was removed
240-
this.removeAnnotation(annotationId);
241-
this.fireDataEvent("annotationRemoved", annotationId);
232+
if (annotationsDiff instanceof Array) {
233+
// from or to empty annotations
234+
if (annotationsDiff.length === 2) {
235+
if (annotationsDiff[0] === null) {
236+
// first annotation(s) was added
237+
const annotationsData = annotationsDiff[1];
238+
Object.entries(annotationsData).forEach(([annotationId, annotationData]) => {
239+
const annotation = this.addAnnotation(annotationData, annotationId);
240+
this.fireDataEvent("annotationAdded", annotation);
241+
});
242+
} else if (annotationsDiff[1] === null) {
243+
// all annotations were removed
244+
const removedAnnotationsData = annotationsDiff[0];
245+
Object.keys(removedAnnotationsData).forEach(annotationId => {
246+
this.removeAnnotation(annotationId);
247+
this.fireDataEvent("annotationRemoved", annotationId);
248+
});
242249
}
243-
} else if (annotationDiff instanceof Object) {
244-
// it was updated
245-
if (annotationId in annotations) {
246-
const annotation = annotations[annotationId];
247-
if ("attributes" in annotationDiff) {
248-
this.__updateAnnotationPositionFromDiff(annotation, annotationDiff["attributes"]);
250+
}
251+
} else if (annotationsDiff instanceof Object) {
252+
Object.entries(annotationsDiff).forEach(([annotationId, annotationDiff]) => {
253+
if (annotationDiff instanceof Array) {
254+
if (annotationDiff.length === 1) {
255+
// it was added
256+
const annotation = this.addAnnotation(annotationDiff[0], annotationId);
257+
this.fireDataEvent("annotationAdded", annotation);
258+
} else if (annotationDiff.length === 3 && annotationDiff[1] === 0) {
259+
// it was removed
260+
this.removeAnnotation(annotationId);
261+
this.fireDataEvent("annotationRemoved", annotationId);
249262
}
250-
if ("color" in annotationDiff) {
251-
annotation.setColor(annotationDiff["color"][1]);
263+
} else if (annotationDiff instanceof Object) {
264+
// it was updated
265+
if (annotationId in annotations) {
266+
const annotation = annotations[annotationId];
267+
if ("attributes" in annotationDiff) {
268+
this.__updateAnnotationPositionFromDiff(annotation, annotationDiff["attributes"]);
269+
}
270+
if ("color" in annotationDiff) {
271+
annotation.setColor(annotationDiff["color"][1]);
272+
}
273+
} else {
274+
console.warn(`Annotation with id ${annotationId} not found`);
252275
}
253-
} else {
254-
console.warn(`Annotation with id ${annotationId} not found`);
255276
}
256-
}
257-
});
277+
});
278+
}
258279
},
259280

260281
listenToChanges: function() {

0 commit comments

Comments
 (0)