Skip to content

Commit 3fb8edd

Browse files
authored
🐛 [Frontend] FIXES: Add nodes (#8312)
1 parent 920710a commit 3fb8edd

File tree

6 files changed

+121
-88
lines changed

6 files changed

+121
-88
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ qx.Class.define("osparc.data.model.NodeStatus", {
2626
construct: function(node) {
2727
this.base(arguments);
2828

29+
const lockState = new osparc.data.model.NodeLockState();
30+
this.setLockState(lockState);
31+
2932
this.setNode(node);
3033
},
3134

@@ -151,11 +154,7 @@ qx.Class.define("osparc.data.model.NodeStatus", {
151154
const progressSequence = new osparc.data.model.NodeProgressSequence();
152155
this.setProgressSequence(progressSequence);
153156
}
154-
155-
const lockState = new osparc.data.model.NodeLockState();
156-
this.setLockState(lockState);
157157
};
158-
159158
if (node.getMetadata()) {
160159
initNode();
161160
} else {

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

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -497,36 +497,43 @@ qx.Class.define("osparc.data.model.Workbench", {
497497
return;
498498
}
499499

500-
const requesterNode = this.getNode(nodeId);
501-
const freePos = this.getFreePosition(requesterNode);
502-
filePicker.setPosition(freePos);
500+
const populateNewNode = () => {
501+
const requesterNode = this.getNode(nodeId);
502+
const freePos = this.getFreePosition(requesterNode);
503+
filePicker.setPosition(freePos);
503504

504-
// create connection
505-
const filePickerId = filePicker.getNodeId();
506-
requesterNode.addInputNode(filePickerId);
507-
// reload also before port connection happens
508-
this.fireEvent("reloadModel");
509-
requesterNode.addPortLink(portId, filePickerId, "outFile")
510-
.then(success => {
511-
if (success) {
512-
if (file) {
513-
const fileObj = file.data;
514-
osparc.file.FilePicker.setOutputValueFromStore(
515-
filePicker,
516-
fileObj.getLocation(),
517-
fileObj.getDatasetId(),
518-
fileObj.getFileId(),
519-
fileObj.getLabel()
520-
);
505+
// create connection
506+
const filePickerId = filePicker.getNodeId();
507+
requesterNode.addInputNode(filePickerId);
508+
// reload also before port connection happens
509+
this.fireEvent("reloadModel");
510+
requesterNode.addPortLink(portId, filePickerId, "outFile")
511+
.then(success => {
512+
if (success) {
513+
if (file) {
514+
const fileObj = file.data;
515+
osparc.file.FilePicker.setOutputValueFromStore(
516+
filePicker,
517+
fileObj.getLocation(),
518+
fileObj.getDatasetId(),
519+
fileObj.getFileId(),
520+
fileObj.getLabel()
521+
);
522+
}
523+
this.fireDataEvent("openNode", filePicker.getNodeId());
524+
this.fireEvent("reloadModel");
525+
} else {
526+
this.removeNode(filePickerId);
527+
const msg = qx.locale.Manager.tr("File couldn't be assigned");
528+
osparc.FlashMessenger.logError(msg);
521529
}
522-
this.fireDataEvent("openNode", filePicker.getNodeId());
523-
this.fireEvent("reloadModel");
524-
} else {
525-
this.removeNode(filePickerId);
526-
const msg = qx.locale.Manager.tr("File couldn't be assigned");
527-
osparc.FlashMessenger.logError(msg);
528-
}
529-
});
530+
});
531+
};
532+
if (filePicker.getMetadata()) {
533+
populateNewNode();
534+
} else {
535+
filePicker.addListenerOnce("changeMetadata", () => populateNewNode(), this);
536+
}
530537
},
531538

532539
__parameterNodeRequested: async function(nodeId, portId) {
@@ -541,20 +548,27 @@ qx.Class.define("osparc.data.model.Workbench", {
541548
return;
542549
}
543550

544-
// do not overlap the new Parameter Node with other nodes
545-
const freePos = this.getFreePosition(requesterNode);
546-
parameterNode.setPosition(freePos);
547-
548-
// create connection
549-
const pmId = parameterNode.getNodeId();
550-
requesterNode.addInputNode(pmId);
551-
// bypass the compatibility check
552-
if (requesterNode.getPropsForm().addPortLink(portId, pmId, "out_1") !== true) {
553-
this.removeNode(pmId);
554-
const msg = qx.locale.Manager.tr("Parameter couldn't be assigned");
555-
osparc.FlashMessenger.logError(msg);
551+
const populateNewNode = () => {
552+
// do not overlap the new Parameter Node with other nodes
553+
const freePos = this.getFreePosition(requesterNode);
554+
parameterNode.setPosition(freePos);
555+
556+
// create connection
557+
const pmId = parameterNode.getNodeId();
558+
requesterNode.addInputNode(pmId);
559+
// bypass the compatibility check
560+
if (requesterNode.getPropsForm().addPortLink(portId, pmId, "out_1") !== true) {
561+
this.removeNode(pmId);
562+
const msg = qx.locale.Manager.tr("Parameter couldn't be assigned");
563+
osparc.FlashMessenger.logError(msg);
564+
}
565+
this.fireEvent("reloadModel");
566+
};
567+
if (parameterNode.getMetadata()) {
568+
populateNewNode();
569+
} else {
570+
parameterNode.addListenerOnce("changeMetadata", () => populateNewNode(), this);
556571
}
557-
this.fireEvent("reloadModel");
558572
}
559573
},
560574

@@ -571,22 +585,29 @@ qx.Class.define("osparc.data.model.Workbench", {
571585
return;
572586
}
573587

574-
probeNode.setLabel(requesterPortMD.label);
588+
const populateNewNode = () => {
589+
probeNode.setLabel(requesterPortMD.label);
575590

576-
// do not overlap the new Parameter Node with other nodes
577-
const freePos = this.getFreePosition(requesterNode, false);
578-
probeNode.setPosition(freePos);
591+
// do not overlap the new Parameter Node with other nodes
592+
const freePos = this.getFreePosition(requesterNode, false);
593+
probeNode.setPosition(freePos);
579594

580-
// create connection
581-
const probeId = probeNode.getNodeId();
582-
probeNode.addInputNode(nodeId);
583-
// bypass the compatibility check
584-
if (probeNode.getPropsForm().addPortLink("in_1", nodeId, portId) !== true) {
585-
this.removeNode(probeId);
586-
const msg = qx.locale.Manager.tr("Probe couldn't be assigned");
587-
osparc.FlashMessenger.logError(msg);
595+
// create connection
596+
const probeId = probeNode.getNodeId();
597+
probeNode.addInputNode(nodeId);
598+
// bypass the compatibility check
599+
if (probeNode.getPropsForm().addPortLink("in_1", nodeId, portId) !== true) {
600+
this.removeNode(probeId);
601+
const msg = qx.locale.Manager.tr("Probe couldn't be assigned");
602+
osparc.FlashMessenger.logError(msg);
603+
}
604+
this.fireEvent("reloadModel");
605+
};
606+
if (probeNode.getMetadata()) {
607+
populateNewNode();
608+
} else {
609+
probeNode.addListenerOnce("changeMetadata", () => populateNewNode(), this);
588610
}
589-
this.fireEvent("reloadModel");
590611
}
591612
},
592613

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
7070
const msg = qx.locale.Manager.tr("Project not found");
7171
throw new Error(msg);
7272
}
73-
this.loadStudy(studyData);
73+
return this.loadStudy(studyData); // return so errors propagate
7474
})
7575
.catch(err => {
7676
osparc.FlashMessenger.logError(err);
@@ -104,7 +104,7 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
104104
this.setLoadingPageHeader(qx.locale.Manager.tr("Loading ") + studyData.name);
105105
this.showLoadingPage();
106106

107-
osparc.store.Services.getStudyServicesMetadata(studyData)
107+
return osparc.store.Services.getStudyServicesMetadata(studyData)
108108
.finally(() => {
109109
const inaccessibleServices = osparc.store.Services.getInaccessibleServices(studyData["workbench"]);
110110
if (inaccessibleServices.length) {

services/static-webserver/client/source/class/osparc/form/renderer/PropForm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ qx.Class.define("osparc.form.renderer.PropForm", {
358358
const inputNodeIDs = thisNode.getInputNodes();
359359
inputNodeIDs.forEach(inputNodeId => {
360360
const inputNode = this.getStudy().getWorkbench().getNode(inputNodeId);
361-
if (inputNode) {
361+
if (inputNode && inputNode.getMetadata()) {
362362
for (const outputKey in inputNode.getOutputs()) {
363363
const paramButton = new qx.ui.menu.Button();
364364
inputNode.bind("label", paramButton, "label", {
@@ -400,7 +400,7 @@ qx.Class.define("osparc.form.renderer.PropForm", {
400400
menu.removeAll();
401401

402402
const inputNode = this.getStudy().getWorkbench().getNode(inputNodeId);
403-
if (inputNode) {
403+
if (inputNode && inputNode.getMetadata()) {
404404
for (const outputKey in inputNode.getOutputs()) {
405405
osparc.utils.Ports.arePortsCompatible(inputNode, outputKey, this.getNode(), targetPortId)
406406
.then(compatible => {

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ qx.Class.define("osparc.workbench.NodeUI", {
168168
"nodeMovingStop": "qx.event.type.Event",
169169
"updateNodeDecorator": "qx.event.type.Event",
170170
"requestOpenLogger": "qx.event.type.Event",
171+
"highlightEdge": "qx.event.type.Data",
171172
},
172173

173174
members: {
@@ -236,6 +237,8 @@ qx.Class.define("osparc.workbench.NodeUI", {
236237
let nodeType = this.getNode().getMetadata().type;
237238
if (this.getNode().isIterator()) {
238239
nodeType = "iterator";
240+
} else if (this.getNode().isParameter()) {
241+
nodeType = "parameter";
239242
} else if (this.getNode().isProbe()) {
240243
nodeType = "probe";
241244
}
@@ -308,14 +311,15 @@ qx.Class.define("osparc.workbench.NodeUI", {
308311
},
309312

310313
__resetNodeUILayout: function() {
311-
this.set({
312-
width: this.self(arguments).NODE_WIDTH,
313-
maxWidth: this.self(arguments).NODE_WIDTH,
314-
minWidth: this.self(arguments).NODE_WIDTH
315-
});
314+
this.__setNodeUIWidth(this.self().NODE_WIDTH);
316315
this.resetThumbnail();
317316

318-
this.__createContentLayout();
317+
// make sure metadata is ready
318+
if (this.getNode().getMetadata()) {
319+
this.__createContentLayout();
320+
} else {
321+
this.getNode().addListenerOnce("changeMetadata", () => this.__createContentLayout(), this);
322+
}
319323
},
320324

321325
__createContentLayout: function() {
@@ -330,7 +334,7 @@ qx.Class.define("osparc.workbench.NodeUI", {
330334
}
331335
},
332336

333-
populateNodeLayout: function(svgWorkbenchCanvas) {
337+
__populateNodeLayout: function(svgWorkbenchCanvas) {
334338
const node = this.getNode();
335339
node.bind("label", this, "caption", {
336340
onUpdate: () => {
@@ -364,6 +368,18 @@ qx.Class.define("osparc.workbench.NodeUI", {
364368
this.addListener("resize", () => {
365369
setTimeout(() => this.fireEvent("updateNodeDecorator"), 50);
366370
});
371+
372+
if (node.getPropsForm()) {
373+
node.getPropsForm().addListener("highlightEdge", e => this.fireDataEvent("highlightEdge", e.getData()), this);
374+
}
375+
},
376+
377+
populateNodeLayout: function(svgWorkbenchCanvas) {
378+
if (this.getNode().getMetadata()) {
379+
this.__populateNodeLayout(svgWorkbenchCanvas);
380+
} else {
381+
this.getNode().addListenerOnce("changeMetadata", () => this.__populateNodeLayout(svgWorkbenchCanvas), this);
382+
}
367383
},
368384

369385
__applyNode: function(node) {
@@ -576,7 +592,7 @@ qx.Class.define("osparc.workbench.NodeUI", {
576592
},
577593

578594
__turnIntoParameterUI: function() {
579-
const width = 100;
595+
const width = 120;
580596
this.__setNodeUIWidth(width);
581597

582598
const label = new qx.ui.basic.Label().set({

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -689,25 +689,22 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
689689
nodeUI.addListener("markerClicked", e => this.__openMarkerEditor(e.getData()), this);
690690
nodeUI.addListener("infoNode", e => this.__openNodeInfo(e.getData()), this);
691691
nodeUI.addListener("removeNode", e => this.fireDataEvent("removeNode", e.getData()), this);
692-
693-
if (nodeUI.getNode().getPropsForm()) {
694-
nodeUI.getNode().getPropsForm().addListener("highlightEdge", e => {
695-
const {
696-
highlight,
697-
fromNodeId,
698-
toNodeId,
699-
} = e.getData();
700-
const edgeFound = this.__edgesUI.find(edgeUI => {
701-
const edge = edgeUI.getEdge();
702-
const inputNode = edge.getInputNode();
703-
const outputNode = edge.getOutputNode();
704-
return (inputNode.getNodeId() === fromNodeId && outputNode.getNodeId() === toNodeId)
705-
});
706-
if (edgeFound) {
707-
edgeFound.setHighlighted(highlight);
708-
}
692+
nodeUI.addListener("highlightEdge", e => {
693+
const {
694+
highlight,
695+
fromNodeId,
696+
toNodeId,
697+
} = e.getData();
698+
const edgeFound = this.__edgesUI.find(edgeUI => {
699+
const edge = edgeUI.getEdge();
700+
const inputNode = edge.getInputNode();
701+
const outputNode = edge.getOutputNode();
702+
return (inputNode.getNodeId() === fromNodeId && outputNode.getNodeId() === toNodeId)
709703
});
710-
}
704+
if (edgeFound) {
705+
edgeFound.setHighlighted(highlight);
706+
}
707+
});
711708

712709
return nodeUI;
713710
},

0 commit comments

Comments
 (0)