Skip to content

Commit b82035e

Browse files
committed
updateNodeFromPatch
1 parent 5281574 commit b82035e

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ qx.Class.define("osparc.data.model.Node", {
238238
"progress", // !! not a property but goes into the model
239239
],
240240

241+
getProperties: function() {
242+
return Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Node));
243+
},
244+
241245
isFrontend: function(metadata) {
242246
return (metadata && metadata.key && metadata.key.includes("/frontend/"));
243247
},
@@ -1306,7 +1310,7 @@ qx.Class.define("osparc.data.model.Node", {
13061310

13071311
listenToChanges: function() {
13081312
const nodeId = this.getNodeId();
1309-
const propertyKeys = Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Node));
1313+
const nodePropertyKeys = this.self().getProperties();
13101314
this.self().ListenChangesProps.forEach(key => {
13111315
switch (key) {
13121316
case "inputs":
@@ -1400,7 +1404,7 @@ qx.Class.define("osparc.data.model.Node", {
14001404
}
14011405
break;
14021406
default:
1403-
if (propertyKeys.includes(key)) {
1407+
if (nodePropertyKeys.includes(key)) {
14041408
this.addListener("change" + qx.lang.String.firstUp(key), e => {
14051409
const data = e.getData();
14061410
this.fireDataEvent("projectDocumentChanged", {
@@ -1418,6 +1422,36 @@ qx.Class.define("osparc.data.model.Node", {
14181422
});
14191423
},
14201424

1425+
updateNodeFromPatch: function(nodePatches) {
1426+
console.log(nodePatches);
1427+
const nodePropertyKeys = this.self().getProperties();
1428+
nodePatches.forEach(patch => {
1429+
const op = patch.op;
1430+
const path = patch.path;
1431+
const value = patch.value;
1432+
const nodeProperty = path.split("/")[3];
1433+
switch (nodeProperty) {
1434+
case "inputs":
1435+
case "inputsUnits":
1436+
case "inputNodes":
1437+
case "inputsRequired":
1438+
case "outputs":
1439+
case "progress":
1440+
console.warn(`To be implemented: patching ${nodeProperty} is not supported yet`);
1441+
default:
1442+
if (nodePropertyKeys.includes(nodeProperty)) {
1443+
const setter = "set" + qx.lang.String.firstUp(nodeProperty);
1444+
if (this[setter]) {
1445+
this[setter](value);
1446+
} else {
1447+
console.warn(`Property "${nodeProperty}" does not have a setter in osparc.data.model.Node`);
1448+
}
1449+
}
1450+
break;
1451+
}
1452+
});
1453+
},
1454+
14211455
serialize: function() {
14221456
// node generic
14231457
let nodeEntry = {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ qx.Class.define("osparc.data.model.Workbench", {
830830
},
831831

832832
updateWorkbenchFromPatches: function(workbenchPatches) {
833-
console.log(workbenchPatches);
834833
// group the patches by nodeId
835834
const workbenchPatchesByNode = {};
836835
workbenchPatches.forEach(workbenchPatch => {
@@ -840,7 +839,16 @@ qx.Class.define("osparc.data.model.Workbench", {
840839
}
841840
workbenchPatchesByNode[nodeId].push(workbenchPatch);
842841
});
843-
console.log(workbenchPatchesByNode);
842+
Object.keys(workbenchPatchesByNode).forEach(nodeId => {
843+
const node = this.getNode(nodeId);
844+
if (node === null) {
845+
console.warn(`Node with id ${nodeId} not found, skipping patch application.`);
846+
return;
847+
}
848+
const nodePatches = workbenchPatchesByNode[nodeId];
849+
node.updateNodeFromPatch(nodePatches);
850+
});
851+
this.getNode()
844852
},
845853
}
846854
});

0 commit comments

Comments
 (0)