diff --git a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js index 4571dfba125..1110d55b736 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Workbench.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Workbench.js @@ -66,6 +66,13 @@ qx.Class.define("osparc.data.model.Workbench", { init: null, nullable: false, event: "changeStudy" + }, + + deserialized: { + check: "Boolean", + init: false, + nullable: false, + event: "changeDeserialized" } }, @@ -662,6 +669,7 @@ qx.Class.define("osparc.data.model.Workbench", { this.__deserializeEdges(workbenchInitData); workbenchInitData = null; workbenchUIInitData = null; + this.setDeserialized(true); }); }, diff --git a/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js b/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js index 7c7a9ac8d06..face09ef10f 100644 --- a/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js +++ b/services/static-webserver/client/source/class/osparc/viewer/NodeViewer.js @@ -25,43 +25,51 @@ qx.Class.define("osparc.viewer.NodeViewer", { this._setLayout(new qx.ui.layout.VBox()); - let studyData = null; - this.self().openStudy(studyId) - .then(resp => { - studyData = resp; - if (studyData["workbench"] && nodeId in studyData["workbench"]) { - const nodeData = studyData["workbench"][nodeId]; - return osparc.service.Store.getService(nodeData.key, nodeData.version) - } - throw new Error("Node data not found in Study"); - }) - .then(metadata => { + const params = { + url: { + studyId + }, + data: osparc.utils.Utils.getClientSessionID() + }; + osparc.data.Resources.fetch("studies", "open", params) + .then(studyData => { // create study const study = new osparc.data.model.Study(studyData); this.setStudy(study); - // create node - const node = new osparc.data.model.Node(study, metadata, nodeId); - this.setNode(node); - - node.addListener("retrieveInputs", e => { - const data = e.getData(); - const portKey = data["portKey"]; - node.retrieveInputs(portKey); - }, this); - - node.initIframeHandler(); - - const iframeHandler = node.getIframeHandler(); - if (iframeHandler) { - iframeHandler.startPolling(); - iframeHandler.addListener("iframeChanged", () => this.__iFrameChanged(), this); - iframeHandler.getIFrame().addListener("load", () => this.__iFrameChanged(), this); - this.__iFrameChanged(); + const startPolling = () => { + const node = study.getWorkbench().getNode(nodeId); + this.setNode(node); + + node.addListener("retrieveInputs", e => { + const data = e.getData(); + const portKey = data["portKey"]; + node.retrieveInputs(portKey); + }, this); + + node.initIframeHandler(); + + const iframeHandler = node.getIframeHandler(); + if (iframeHandler) { + iframeHandler.startPolling(); + iframeHandler.addListener("iframeChanged", () => this.__iFrameChanged(), this); + iframeHandler.getIFrame().addListener("load", () => this.__iFrameChanged(), this); + this.__iFrameChanged(); + + this.__attachSocketEventHandlers(); + } else { + console.error(node.getLabel() + " iframe handler not ready"); + } + } - this.__attachSocketEventHandlers(); + if (study.getWorkbench().isDeserialized()) { + startPolling(); } else { - console.error(node.getLabel() + " iframe handler not ready"); + study.getWorkbench().addListener("changeDeserialized", e => { + if (e.getData()) { + startPolling(); + } + }); } }) .catch(err => console.error(err)); @@ -81,18 +89,6 @@ qx.Class.define("osparc.viewer.NodeViewer", { } }, - statics: { - openStudy: function(studyId) { - const params = { - url: { - "studyId": studyId - }, - data: osparc.utils.Utils.getClientSessionID() - }; - return osparc.data.Resources.fetch("studies", "open", params); - } - }, - members: { __iFrameChanged: function() { this._removeAll();