Skip to content

Commit a706ec1

Browse files
committed
support remove node
1 parent 11e3c2a commit a706ec1

File tree

3 files changed

+73
-30
lines changed

3 files changed

+73
-30
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ qx.Class.define("osparc.data.model.Node", {
12031203
this.__deleteInBackend()
12041204
.then(() => {
12051205
resolve(true);
1206-
this.removeIFrame();
1206+
this.nodeRemoved();
12071207
})
12081208
.catch(err => {
12091209
console.error(err);
@@ -1212,6 +1212,10 @@ qx.Class.define("osparc.data.model.Node", {
12121212
});
12131213
},
12141214

1215+
nodeRemoved: function() {
1216+
this.removeIFrame();
1217+
},
1218+
12151219
__deleteInBackend: function() {
12161220
// remove node in the backend
12171221
const params = {

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

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ qx.Class.define("osparc.data.model.Workbench", {
5454
"projectDocumentChanged": "qx.event.type.Data",
5555
"restartAutoSaveTimer": "qx.event.type.Event",
5656
"pipelineChanged": "qx.event.type.Event",
57+
"nodeRemoved": "qx.event.type.Data",
5758
"reloadModel": "qx.event.type.Event",
5859
"retrieveInputs": "qx.event.type.Data",
5960
"fileRequested": "qx.event.type.Data",
@@ -539,11 +540,11 @@ qx.Class.define("osparc.data.model.Workbench", {
539540

540541
removeNode: async function(nodeId) {
541542
if (!osparc.data.Permissions.getInstance().canDo("study.node.delete", true)) {
542-
return false;
543+
return;
543544
}
544545
if (this.getStudy().isPipelineRunning()) {
545546
osparc.FlashMessenger.logAs(this.self().CANT_DELETE_NODE, "ERROR");
546-
return false;
547+
return;
547548
}
548549

549550
this.fireEvent("restartAutoSaveTimer");
@@ -552,26 +553,33 @@ qx.Class.define("osparc.data.model.Workbench", {
552553
// remove the node in the backend first
553554
const removed = await node.removeNode();
554555
if (removed) {
555-
this.fireEvent("restartAutoSaveTimer");
556+
this.__nodeRemoved(nodeId);
557+
}
558+
}
559+
},
556560

557-
delete this.__nodes[nodeId];
561+
__nodeRemoved: function(nodeId) {
562+
this.fireEvent("restartAutoSaveTimer");
558563

559-
// remove first the connected edges
560-
const connectedEdges = this.getConnectedEdges(nodeId);
561-
connectedEdges.forEach(connectedEdgeId => {
562-
this.removeEdge(connectedEdgeId);
563-
});
564+
delete this.__nodes[nodeId];
564565

565-
// remove it from ui model
566-
if (this.getStudy()) {
567-
this.getStudy().getUi().removeNode(nodeId);
568-
}
566+
// remove first the connected edges
567+
const connectedEdgeIds = this.getConnectedEdges(nodeId);
568+
connectedEdgeIds.forEach(connectedEdgeId => {
569+
this.removeEdge(connectedEdgeId);
570+
});
569571

570-
this.fireEvent("pipelineChanged");
571-
return true;
572-
}
572+
// remove it from ui model
573+
if (this.getStudy()) {
574+
this.getStudy().getUi().removeNode(nodeId);
573575
}
574-
return false;
576+
577+
this.fireEvent("pipelineChanged");
578+
579+
this.fireDataEvent("nodeRemoved", {
580+
nodeId,
581+
connectedEdgeIds,
582+
});
575583
},
576584

577585
addServiceBetween: async function(service, leftNodeId, rightNodeId) {
@@ -831,14 +839,42 @@ qx.Class.define("osparc.data.model.Workbench", {
831839

832840
updateWorkbenchFromPatches: function(workbenchPatches) {
833841
// group the patches by nodeId
842+
const nodesAdded = [];
843+
const nodesRemoved = [];
834844
const workbenchPatchesByNode = {};
835845
workbenchPatches.forEach(workbenchPatch => {
836846
const nodeId = workbenchPatch.path.split("/")[2];
847+
848+
const pathParts = workbenchPatch.path.split("/");
849+
if (pathParts.length === 3) {
850+
if (workbenchPatch.op === "add") {
851+
// node was added
852+
nodesAdded.push(nodeId);
853+
} else if (workbenchPatch.op === "remove") {
854+
// node was removed
855+
nodesRemoved.push(nodeId);
856+
}
857+
}
858+
837859
if (!(nodeId in workbenchPatchesByNode)) {
838860
workbenchPatchesByNode[nodeId] = [];
839861
}
840862
workbenchPatchesByNode[nodeId].push(workbenchPatch);
841863
});
864+
865+
// first remove nodes
866+
nodesRemoved.forEach(nodeId => {
867+
const node = this.getNode(nodeId);
868+
if (node) {
869+
node.nodeRemoved(nodeId);
870+
}
871+
this.__nodeRemoved(nodeId);
872+
});
873+
874+
// second add nodes
875+
console.log("Adding nodes", nodesAdded);
876+
877+
// third update nodes
842878
Object.keys(workbenchPatchesByNode).forEach(nodeId => {
843879
const node = this.getNode(nodeId);
844880
if (node === null) {
@@ -848,7 +884,6 @@ qx.Class.define("osparc.data.model.Workbench", {
848884
const nodePatches = workbenchPatchesByNode[nodeId];
849885
node.updateNodeFromPatch(nodePatches);
850886
});
851-
this.getNode()
852887
},
853888
}
854889
});

services/static-webserver/client/source/class/osparc/desktop/WorkbenchView.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
246246
this.__connectEvents();
247247

248248
study.getWorkbench().addListener("pipelineChanged", () => this.__evalSlidesButtons());
249+
study.getWorkbench().addListener("nodeRemoved", e => {
250+
const {nodeId, connectedEdgeIds} = e.getData();
251+
this.nodeRemoved(nodeId, connectedEdgeIds);
252+
});
249253
study.getUi().getSlideshow().addListener("changeSlideshow", () => this.__evalSlidesButtons());
250254
study.getUi().addListener("changeMode", () => this.__evalSlidesButtons());
251255
this.__evalSlidesButtons();
@@ -1169,23 +1173,23 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
11691173
}
11701174
},
11711175

1172-
__doRemoveNode: async function(nodeId) {
1176+
__doRemoveNode: function(nodeId) {
11731177
const workbench = this.getStudy().getWorkbench();
1174-
const connectedEdges = workbench.getConnectedEdges(nodeId);
1175-
const removed = await workbench.removeNode(nodeId);
1176-
if (removed) {
1177-
// remove first the connected edges
1178-
for (let i = 0; i < connectedEdges.length; i++) {
1179-
const edgeId = connectedEdges[i];
1180-
this.__workbenchUI.clearEdge(edgeId);
1181-
}
1182-
this.__workbenchUI.clearNode(nodeId);
1183-
}
1178+
workbench.removeNode(nodeId);
11841179
if ([this.__currentNodeId, null].includes(this.__nodesTree.getCurrentNodeId())) {
11851180
this.nodeSelected(this.getStudy().getUuid());
11861181
}
11871182
},
11881183

1184+
nodeRemoved: function(nodeId, connectedEdgeIds) {
1185+
// remove first the connected edges
1186+
connectedEdgeIds.forEach(edgeId => {
1187+
this.__workbenchUI.clearEdge(edgeId);
1188+
});
1189+
// then remove the node
1190+
this.__workbenchUI.clearNode(nodeId);
1191+
},
1192+
11891193
__removeEdge: function(edgeId) {
11901194
const workbench = this.getStudy().getWorkbench();
11911195
const removed = workbench.removeEdge(edgeId);

0 commit comments

Comments
 (0)