Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 [Frontend] Check all linked nodes exist before loading Study #6762

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,19 @@ qx.Class.define("osparc.data.model.Node", {
return outputs[outputKey]["value"];
}
return null;
}
},

getLinkedNodeIds: function(nodeData) {
const linkedNodeIds = new Set([]);
if ("inputs" in nodeData) {
Object.values(nodeData["inputs"]).forEach(link => {
if (link && typeof link === "object" && "nodeUuid" in link) {
linkedNodeIds.add(link["nodeUuid"]);
}
});
}
return Array.from(linkedNodeIds);
},
},

members: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,18 @@ qx.Class.define("osparc.data.model.Study", {
"STARTED",
"RETRY"
].includes(state);
}
},

__isAnyLinkedNodeMissing: function(studyData) {
const existingNodeIds = Object.keys(studyData["workbench"]);
const linkedNodeIds = osparc.data.model.Workbench.getLinkedNodeIds(studyData["workbench"]);
const allExist = linkedNodeIds.every(linkedNodeId => existingNodeIds.includes(linkedNodeId));
return !allExist;
},

isCorrupt: function(studyData) {
return this.__isAnyLinkedNodeMissing(studyData);
},
},

members: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ qx.Class.define("osparc.data.model.Workbench", {

statics: {
CANT_ADD_NODE: qx.locale.Manager.tr("Nodes can't be added while the pipeline is running"),
CANT_DELETE_NODE: qx.locale.Manager.tr("Nodes can't be deleted while the pipeline is running")
CANT_DELETE_NODE: qx.locale.Manager.tr("Nodes can't be deleted while the pipeline is running"),

getLinkedNodeIds: function(workbenchData) {
const linkedNodeIDs = new Set([]);
Object.values(workbenchData).forEach(nodeData => {
const linkedNodes = osparc.data.model.Node.getLinkedNodeIds(nodeData);
linkedNodes.forEach(linkedNodeID => linkedNodeIDs.add(linkedNodeID))
});
return Array.from(linkedNodeIDs);
},
},

members: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,29 @@ qx.Class.define("osparc.desktop.MainPageHandler", {
},

loadStudy: function(studyData) {
const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true});
// check if it's locked
let locked = false;
let lockedBy = false;
if ("state" in studyData && "locked" in studyData["state"]) {
locked = studyData["state"]["locked"]["value"];
lockedBy = studyData["state"]["locked"]["owner"];
}
if (locked && lockedBy["user_id"] !== osparc.auth.Data.getInstance().getUserId()) {
const msg = `${qx.locale.Manager.tr("Study is already open by ")} ${
const msg = `${studyAlias} ${qx.locale.Manager.tr("is already open by")} ${
"first_name" in lockedBy && lockedBy["first_name"] != null ?
lockedBy["first_name"] :
qx.locale.Manager.tr("another user.")
}`;
throw new Error(msg);
}

// check if it's corrupt
if (osparc.data.model.Study.isCorrupt(studyData)) {
const msg = `${qx.locale.Manager.tr("We encountered an issue with the")} ${studyAlias} <br>${qx.locale.Manager.tr("Please contact support.")}`;
throw new Error(msg);
}

this.setLoadingPageHeader(qx.locale.Manager.tr("Loading ") + studyData.name);
this.showLoadingPage();
const inaccessibleServices = osparc.study.Utils.getInaccessibleServices(studyData["workbench"])
Expand Down
Loading