Skip to content

Commit

Permalink
🐛 [Frontend] Fix App mode: Wait until the workbench is deserialized t…
Browse files Browse the repository at this point in the history
…o start (#6214)
  • Loading branch information
odeimaiz authored and matusdrobuliak66 committed Aug 21, 2024
1 parent 719aed9 commit 69bb0a6
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,70 +169,16 @@ qx.Class.define("osparc.desktop.StudyEditor", {
this.__workbenchView.setStudy(study);
this.__slideshowView.setStudy(study);

this.__attachSocketEventHandlers();

study.initStudy();

if (osparc.product.Utils.hasIdlingTrackerEnabled()) {
this.__startIdlingTracker();
}

// Count dynamic services.
// If it is larger than PROJECTS_MAX_NUM_RUNNING_DYNAMIC_NODES, dynamics won't start -> Flash Message
const maxNumber = osparc.store.StaticInfo.getInstance().getMaxNumberDyNodes();
const dontCheck = study.getDisableServiceAutoStart();
if (maxNumber && !dontCheck) {
const nodes = study.getWorkbench().getNodes();
const nDynamics = Object.values(nodes).filter(node => node.isDynamic()).length;
if (nDynamics > maxNumber) {
let msg = this.tr("The Study contains more than ") + maxNumber + this.tr(" Interactive services.");
msg += "<br>";
msg += this.tr("Please start them manually.");
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
}
}

osparc.data.Resources.get("organizations")
.then(() => {
if (osparc.data.model.Study.canIWrite(study.getAccessRights())) {
this.__startAutoSaveTimer();
} else {
const msg = this.self().READ_ONLY_TEXT;
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
// wait until the workbench is deserialized to move to the next step
if (study.getWorkbench().isDeserialized()) {
this.__initStudy(study);
} else {
study.getWorkbench().addListener("changeDeserialized", e => {
if (e.getData()) {
this.__initStudy(study);
}
});

const pageContext = study.getUi().getMode();
switch (pageContext) {
case "guided":
case "app":
this.__slideshowView.startSlides();
break;
default:
this.__workbenchView.openFirstNode();
break;
}, this);
}
this.addListener("changePageContext", e => {
const pageCxt = e.getData();
study.getUi().setMode(pageCxt);
});
this.setPageContext(pageContext);

const workbench = study.getWorkbench();
workbench.addListener("retrieveInputs", e => {
const data = e.getData();
const node = data["node"];
const portKey = data["portKey"];
this.__updatePipelineAndRetrieve(node, portKey);
}, this);

workbench.addListener("openNode", e => {
const nodeId = e.getData();
this.nodeSelected(nodeId);
}, this);

workbench.addListener("updateStudyDocument", () => this.updateStudyDocument());
workbench.addListener("restartAutoSaveTimer", () => this.__restartAutoSaveTimer());
})
.catch(err => {
console.error(err);
Expand All @@ -255,6 +201,73 @@ qx.Class.define("osparc.desktop.StudyEditor", {
this.__updatingStudy = 0;
},

__initStudy: function(study) {
this.__attachSocketEventHandlers();

study.initStudy();

if (osparc.product.Utils.hasIdlingTrackerEnabled()) {
this.__startIdlingTracker();
}

// Count dynamic services.
// If it is larger than PROJECTS_MAX_NUM_RUNNING_DYNAMIC_NODES, dynamics won't start -> Flash Message
const maxNumber = osparc.store.StaticInfo.getInstance().getMaxNumberDyNodes();
const dontCheck = study.getDisableServiceAutoStart();
if (maxNumber && !dontCheck) {
const nodes = study.getWorkbench().getNodes();
const nDynamics = Object.values(nodes).filter(node => node.isDynamic()).length;
if (nDynamics > maxNumber) {
let msg = this.tr("The Study contains more than ") + maxNumber + this.tr(" Interactive services.");
msg += "<br>";
msg += this.tr("Please start them manually.");
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
}
}

osparc.data.Resources.get("organizations")
.then(() => {
if (osparc.data.model.Study.canIWrite(study.getAccessRights())) {
this.__startAutoSaveTimer();
} else {
const msg = this.self().READ_ONLY_TEXT;
osparc.FlashMessenger.getInstance().logAs(msg, "WARNING");
}
});

const pageContext = study.getUi().getMode();
switch (pageContext) {
case "guided":
case "app":
this.__slideshowView.startSlides();
break;
default:
this.__workbenchView.openFirstNode();
break;
}
this.addListener("changePageContext", e => {
const pageCxt = e.getData();
study.getUi().setMode(pageCxt);
});
this.setPageContext(pageContext);

const workbench = study.getWorkbench();
workbench.addListener("retrieveInputs", e => {
const data = e.getData();
const node = data["node"];
const portKey = data["portKey"];
this.__updatePipelineAndRetrieve(node, portKey);
}, this);

workbench.addListener("openNode", e => {
const nodeId = e.getData();
this.nodeSelected(nodeId);
}, this);

workbench.addListener("updateStudyDocument", () => this.updateStudyDocument());
workbench.addListener("restartAutoSaveTimer", () => this.__restartAutoSaveTimer());
},

__setStudyDataInBackend: function(studyData) {
this.__studyDataInBackend = osparc.data.model.Study.deepCloneStudyObject(studyData, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,14 @@ qx.Class.define("osparc.viewer.NodeViewer", {
const study = new osparc.data.model.Study(studyData);
this.setStudy(study);

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");
}
}

if (study.getWorkbench().isDeserialized()) {
startPolling();
this.__initStudy(study, nodeId);
} else {
study.getWorkbench().addListener("changeDeserialized", e => {
if (e.getData()) {
startPolling();
this.__initStudy(study, nodeId);
}
});
}, this);
}
})
.catch(err => console.error(err));
Expand All @@ -90,6 +65,31 @@ qx.Class.define("osparc.viewer.NodeViewer", {
},

members: {
__initStudy: function(study, nodeId) {
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");
}
},

__iFrameChanged: function() {
this._removeAll();

Expand Down

0 comments on commit 69bb0a6

Please sign in to comment.