Skip to content

Commit cc7dfdd

Browse files
committed
support markers
1 parent d3602f9 commit cc7dfdd

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ qx.Class.define("osparc.data.model.Node", {
525525
this.setPosition(nodeUIData.position);
526526
}
527527
if ("marker" in nodeUIData) {
528-
this.__addMarker(nodeUIData.marker);
528+
this.addMarker(nodeUIData.marker);
529529
}
530530
},
531531

@@ -683,11 +683,11 @@ qx.Class.define("osparc.data.model.Node", {
683683
if (this.getMarker()) {
684684
this.__removeMarker();
685685
} else {
686-
this.__addMarker();
686+
this.addMarker();
687687
}
688688
},
689689

690-
__addMarker: function(marker) {
690+
addMarker: function(marker) {
691691
if (marker === undefined) {
692692
marker = {
693693
color: osparc.utils.Utils.getRandomColor()

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,24 +162,50 @@ qx.Class.define("osparc.data.model.StudyUI", {
162162
if (currentStudy) {
163163
Object.keys(uiDiff["workbench"]).forEach(nodeId => {
164164
const node = currentStudy.getWorkbench().getNode(nodeId);
165-
if (node) {
166-
if ("position" in uiDiff["workbench"][nodeId]) {
167-
const position = uiDiff["workbench"][nodeId]["position"];
168-
const newPos = node.getPosition();
169-
if ("x" in position) {
170-
newPos.x = position["x"][1];
171-
}
172-
if ("y" in position) {
173-
newPos.y = position["y"][1];
174-
}
175-
node.setPosition(newPos);
176-
}
165+
if ("position" in uiDiff["workbench"][nodeId]) {
166+
const positionDiff = uiDiff["workbench"][nodeId]["position"];
167+
this.__updatePositionFromDiff(node, positionDiff);
168+
}
169+
if ("marker" in uiDiff["workbench"][nodeId]) {
170+
const markerDiff = uiDiff["workbench"][nodeId]["marker"];
171+
this.__updateMarkerFromDiff(node, markerDiff);
177172
}
178173
});
179174
}
180175
}
181176
},
182177

178+
__updatePositionFromDiff: function(node, positionDiff) {
179+
if (node) {
180+
const newPos = node.getPosition();
181+
if ("x" in positionDiff) {
182+
newPos.x = positionDiff["x"][1];
183+
}
184+
if ("y" in positionDiff) {
185+
newPos.y = positionDiff["y"][1];
186+
}
187+
node.setPosition(newPos);
188+
}
189+
},
190+
191+
__updateMarkerFromDiff: function(node, markerDiff) {
192+
if (node) {
193+
if (markerDiff instanceof Array) {
194+
if (markerDiff.length === 1) {
195+
// it was added
196+
node.addMarker(markerDiff[0]);
197+
} else if (markerDiff.length === 2 && markerDiff[1] === null) {
198+
// it was removed
199+
node.setMarker(null);
200+
}
201+
} else if ("color" in markerDiff && markerDiff["color"] instanceof Array) {
202+
// it was updated
203+
const newColor = markerDiff["color"][1];
204+
node.getMarker().setColor(newColor);
205+
}
206+
}
207+
},
208+
183209
listenToChanges: function() {
184210
const propertyKeys = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.StudyUI));
185211
this.self().ListenChangesProps.forEach(key => {

0 commit comments

Comments
 (0)