Skip to content

Commit 5383213

Browse files
committed
remove edge
1 parent 2dfbdb6 commit 5383213

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ qx.Class.define("osparc.data.model.Node", {
200200
"keyChanged": "qx.event.type.Event",
201201
"changePosition": "qx.event.type.Data",
202202
"createEdge": "qx.event.type.Data",
203+
"removeEdge": "qx.event.type.Data",
203204
"fileRequested": "qx.event.type.Data",
204205
"parameterRequested": "qx.event.type.Data",
205206
"filePickerRequested": "qx.event.type.Data",
@@ -926,8 +927,9 @@ qx.Class.define("osparc.data.model.Node", {
926927
}
927928
},
928929

929-
__removeInputNodeByIndex: function(index) {
930-
// make sue index is valid
930+
removeInputNode: function(inputNodeId) {
931+
const index = this.__inputNodes.indexOf(inputNodeId);
932+
// make sure index is valid
931933
if (index < 0 || index >= this.__inputNodes.length) {
932934
return false;
933935
}
@@ -937,11 +939,6 @@ qx.Class.define("osparc.data.model.Node", {
937939
return true;
938940
},
939941

940-
removeInputNode: function(inputNodeId) {
941-
const index = this.__inputNodes.indexOf(inputNodeId);
942-
this.__removeInputNodeByIndex(index);
943-
},
944-
945942
isInputNode: function(inputNodeId) {
946943
const index = this.__inputNodes.indexOf(inputNodeId);
947944
return (index > -1);
@@ -1466,7 +1463,13 @@ qx.Class.define("osparc.data.model.Node", {
14661463
} else if (op === "remove") {
14671464
// we don't have more information about the input node, so we just remove it by index
14681465
const index = path.split("/")[4];
1469-
this.__removeInputNodeByIndex(index);
1466+
// make sure index is valid
1467+
if (index > -1 || index < this.__inputNodes.length) {
1468+
this.fireDataEvent("removeEdge", {
1469+
nodeId1: this.__inputNodes[index],
1470+
nodeId2: this.getNodeId(),
1471+
});
1472+
}
14701473
}
14711474
break;
14721475
case "inputsRequired":

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
668668
const { nodeId1, nodeId2 } = data;
669669
this._createEdgeBetweenNodes(nodeId1, nodeId2, false);
670670
});
671+
node.addListener("removeEdge", e => {
672+
const data = e.getData();
673+
const { nodeId1, nodeId2 } = data;
674+
this.__removeEdgeBetweenNodes(nodeId1, nodeId2);
675+
});
671676
nodeUI.populateNodeLayout(this.__svgLayer);
672677
nodeUI.addListener("renameNode", e => this.__openNodeRenamer(e.getData()), this);
673678
nodeUI.addListener("markerClicked", e => this.__openMarkerEditor(e.getData()), this);
@@ -873,6 +878,25 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
873878
this.__svgLayer.addListener("mouseout", () => hint.exclude(), this);
874879
},
875880

881+
__getEdgeUIBetweenNodes: function(node1Id, node2Id) {
882+
const foundEdgeUI = this.__edgesUI.find(edgeUi => {
883+
const edgeObj = edgeUi.getEdge();
884+
const inputNode = edgeObj.getInputNode();
885+
const outputNode = edgeObj.getOutputNode();
886+
if (inputNode.getNodeId() === node1Id && outputNode.getNodeId() === node2Id) {
887+
return true;
888+
}
889+
});
890+
return foundEdgeUI;
891+
},
892+
893+
__removeEdgeBetweenNodes: function(node1Id, node2Id) {
894+
const edgeUI = this.__getEdgeUIBetweenNodes(node1Id, node2Id);
895+
if (edgeUI) {
896+
this.__removeEdge(edgeUI);
897+
}
898+
},
899+
876900
__updateAllEdges: function() {
877901
this.__nodesUI.forEach(nodeUI => {
878902
this.__updateNodeUIPos(nodeUI);

0 commit comments

Comments
 (0)