Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
if (plusButtonConfig["categories"]) {
this.__addCategories(plusButtonConfig["categories"]);
}
plusButtonConfig["resources"].forEach(newStudyData => {
if (newStudyData["showDisabled"]) {
this.__addDisabledButton(newStudyData);
} else if (newStudyData["resourceType"] === "study") {
this.__addEmptyStudyButton(newStudyData);
} else if (newStudyData["resourceType"] === "template") {
this.__addFromTemplateButton(newStudyData, templates);
} else if (newStudyData["resourceType"] === "service") {
this.__addFromServiceButton(newStudyData);
plusButtonConfig["resources"].forEach(buttonConfig => {
if (buttonConfig["showDisabled"]) {
this.__addDisabledButton(buttonConfig);
} else if (buttonConfig["resourceType"] === "study") {
this.__addEmptyStudyButton(buttonConfig);
} else if (buttonConfig["resourceType"] === "template") {
this.__addFromTemplateButton(buttonConfig, templates);
} else if (buttonConfig["resourceType"] === "service") {
this.__addFromServiceButton(buttonConfig);
}
});
});
Expand Down Expand Up @@ -241,55 +241,55 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
}
},

__addDisabledButton: function(newStudyData) {
const menuButton = this.self().createMenuButton(null, newStudyData["title"], newStudyData["reason"]);
osparc.utils.Utils.setIdToWidget(menuButton, newStudyData["idToWidget"]);
__addDisabledButton: function(buttonConfig) {
const menuButton = this.self().createMenuButton(null, buttonConfig["title"], buttonConfig["reason"]);
osparc.utils.Utils.setIdToWidget(menuButton, buttonConfig["idToWidget"]);
menuButton.setEnabled(false);

this.__addIcon(menuButton, newStudyData);
this.__addFromResourceButton(menuButton, newStudyData["category"]);
this.__addIcon(menuButton, buttonConfig);
this.__addFromResourceButton(menuButton, buttonConfig["category"]);
},

__addEmptyStudyButton: function(newStudyData) {
const menuButton = this.self().createMenuButton(null, newStudyData["title"]);
osparc.utils.Utils.setIdToWidget(menuButton, newStudyData["idToWidget"]);
__addEmptyStudyButton: function(buttonConfig) {
const menuButton = this.self().createMenuButton(null, buttonConfig["title"]);
osparc.utils.Utils.setIdToWidget(menuButton, buttonConfig["idToWidget"]);

menuButton.addListener("tap", () => {
this.fireDataEvent("newEmptyStudyClicked", {
newStudyLabel: newStudyData["newStudyLabel"],
newStudyLabel: buttonConfig["newStudyLabel"],
});
});

this.__addIcon(menuButton, newStudyData);
this.__addFromResourceButton(menuButton, newStudyData["category"]);
this.__addIcon(menuButton, buttonConfig);
this.__addFromResourceButton(menuButton, buttonConfig["category"]);
},

__addFromTemplateButton: function(newStudyData, templates) {
const menuButton = this.self().createMenuButton(null, newStudyData["title"]);
osparc.utils.Utils.setIdToWidget(menuButton, newStudyData["idToWidget"]);
__addFromTemplateButton: function(buttonConfig, templates) {
const menuButton = this.self().createMenuButton(null, buttonConfig["title"]);
osparc.utils.Utils.setIdToWidget(menuButton, buttonConfig["idToWidget"]);
// disable it until found in templates store
menuButton.setEnabled(false);

let templateMetadata = templates.find(t => t.name === newStudyData["expectedTemplateLabel"]);
let templateMetadata = templates.find(t => t.name === buttonConfig["expectedTemplateLabel"]);
if (templateMetadata) {
menuButton.setEnabled(true);
menuButton.addListener("tap", () => {
this.fireDataEvent("newStudyFromTemplateClicked", {
templateData: templateMetadata,
newStudyLabel: newStudyData["newStudyLabel"],
newStudyLabel: buttonConfig["newStudyLabel"],
});
});
this.__addIcon(menuButton, newStudyData, templateMetadata);
this.__addFromResourceButton(menuButton, newStudyData["category"]);
this.__addIcon(menuButton, buttonConfig, templateMetadata);
this.__addFromResourceButton(menuButton, buttonConfig["category"]);
}
},

__addFromServiceButton: function(newStudyData) {
__addFromServiceButton: function(buttonConfig) {
const addListenerToButton = (menuButton, latestMetadata) => {
menuButton.addListener("tap", () => {
this.fireDataEvent("newStudyFromServiceClicked", {
serviceMetadata: latestMetadata,
newStudyLabel: newStudyData["newStudyLabel"],
newStudyLabel: buttonConfig["newStudyLabel"],
});
});

Expand All @@ -299,30 +299,38 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
e.stopPropagation();
latestMetadata["resourceType"] = "service";
const resourceDetails = new osparc.dashboard.ResourceDetails(latestMetadata);
osparc.dashboard.ResourceDetails.popUpInWindow(resourceDetails);
const win = osparc.dashboard.ResourceDetails.popUpInWindow(resourceDetails);
resourceDetails.addListener("openService", ev => {
win.close();
const openServiceData = ev.getData();
this.fireDataEvent("newStudyFromServiceClicked", {
serviceMetadata: openServiceData,
newStudyLabel: buttonConfig["newStudyLabel"],
});
});
}
const infoButton = new osparc.ui.basic.IconButton(osparc.ui.hint.InfoHint.INFO_ICON + "/16", cb);
// where the shortcut is supposed to go
// eslint-disable-next-line no-underscore-dangle
menuButton._add(infoButton, {column: 2});
};

if ("expectedKey" in newStudyData) {
const menuButton = this.self().createMenuButton(null, newStudyData["title"]);
osparc.utils.Utils.setIdToWidget(menuButton, newStudyData["idToWidget"]);
if ("expectedKey" in buttonConfig) {
const menuButton = this.self().createMenuButton(null, buttonConfig["title"]);
osparc.utils.Utils.setIdToWidget(menuButton, buttonConfig["idToWidget"]);
// disable it until found in services store
menuButton.setEnabled(false);

const key = newStudyData["expectedKey"];
const key = buttonConfig["expectedKey"];
const latestMetadata = osparc.store.Services.getLatest(key);
if (!latestMetadata) {
return;
}
menuButton.setEnabled(true);
this.__addIcon(menuButton, newStudyData, latestMetadata);
this.__addFromResourceButton(menuButton, newStudyData["category"]);
this.__addIcon(menuButton, buttonConfig, latestMetadata);
this.__addFromResourceButton(menuButton, buttonConfig["category"]);
addListenerToButton(menuButton, latestMetadata);
} else if ("myMostUsed" in newStudyData) {
} else if ("myMostUsed" in buttonConfig) {
const excludeFrontend = true;
const excludeDeprecated = true
osparc.store.Services.getServicesLatestList(excludeFrontend, excludeDeprecated)
Expand All @@ -331,7 +339,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
"sort": "hits",
"order": "down"
});
for (let i=0; i<newStudyData["myMostUsed"]; i++) {
for (let i=0; i<buttonConfig["myMostUsed"]; i++) {
const latestMetadata = servicesList[i];
if (latestMetadata && latestMetadata["hits"] > 0) {
const menuButton = new qx.ui.menu.Button().set({
Expand All @@ -340,7 +348,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
allowGrowX: true,
});
this.__addIcon(menuButton, null, latestMetadata);
this.__addFromResourceButton(menuButton, newStudyData["category"]);
this.__addFromResourceButton(menuButton, buttonConfig["category"]);
addListenerToButton(menuButton, latestMetadata);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
this.addListener("appear", () => this._moreResourcesRequired());
},

properties: {
multiSelection: {
check: "Boolean",
init: false,
nullable: false,
event: "changeMultiSelection",
apply: "_applyMultiSelection"
},
},

events: {
"changeTab": "qx.event.type.Data",
"publishTemplate": "qx.event.type.Data"
Expand Down Expand Up @@ -491,12 +501,147 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
this.self().startStudyById(studyId, openCB, cancelCB, isStudyCreation);
},

_createStudyFromTemplate: function() {
throw new Error("Abstract method called!");
_createStudyFromTemplate: function(templateData) {
if (!this._checkLoggedIn()) {
return;
}

const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true});
this._showLoadingPage(this.tr("Creating ") + (templateData.name || studyAlias));

if (osparc.desktop.credits.Utils.areWalletsEnabled()) {
const studyOptions = new osparc.study.StudyOptions();
// they will be patched once the study is created
studyOptions.setPatchStudy(false);
studyOptions.setStudyData(templateData);
studyOptions.getChildControl("open-button").setLabel(this.tr("New"));
const win = osparc.study.StudyOptions.popUpInWindow(studyOptions);
win.moveItUp();
const cancelStudyOptions = () => {
this._hideLoadingPage();
win.close();
}
win.addListener("cancel", () => cancelStudyOptions());
studyOptions.addListener("cancel", () => cancelStudyOptions());
studyOptions.addListener("startStudy", () => {
const newName = studyOptions.getChildControl("title-field").getValue();
const walletSelection = studyOptions.getChildControl("wallet-selector").getSelection();
const nodesPricingUnits = studyOptions.getChildControl("study-pricing-units").getNodePricingUnits();
win.close();

this._showLoadingPage(this.tr("Creating ") + (newName || studyAlias));
osparc.study.Utils.createStudyFromTemplate(templateData, this._loadingPage)
.then(newStudyData => {
const studyId = newStudyData["uuid"];
const openCB = () => {
this._hideLoadingPage();
};
const cancelCB = () => {
this._hideLoadingPage();
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "delete", params);
};

const promises = [];
// patch the name
if (newStudyData["name"] !== newName) {
promises.push(osparc.study.StudyOptions.updateName(newStudyData, newName));
}
// patch the wallet
if (walletSelection.length && walletSelection[0]["walletId"]) {
const walletId = walletSelection[0]["walletId"];
promises.push(osparc.study.StudyOptions.updateWallet(newStudyData["uuid"], walletId));
}
// patch the pricing units
// the nodeIds are coming from the original template, they need to be mapped to the newStudy
const workbench = newStudyData["workbench"];
const nodesIdsListed = [];
Object.keys(workbench).forEach(nodeId => {
const nodeData = workbench[nodeId];
if (osparc.study.StudyPricingUnits.includeInList(nodeData)) {
nodesIdsListed.push(nodeId);
}
});
nodesPricingUnits.forEach((nodePricingUnits, idx) => {
const selectedPricingUnitId = nodePricingUnits.getPricingUnits().getSelectedUnitId();
if (selectedPricingUnitId) {
const nodeId = nodesIdsListed[idx];
const pricingPlanId = nodePricingUnits.getPricingPlanId();
promises.push(osparc.study.NodePricingUnits.patchPricingUnitSelection(studyId, nodeId, pricingPlanId, selectedPricingUnitId));
}
});

Promise.all(promises)
.then(() => {
win.close();
const showStudyOptions = false;
this._startStudyById(studyId, openCB, cancelCB, showStudyOptions);
});
})
.catch(err => {
this._hideLoadingPage();
osparc.FlashMessenger.logError(err);
});
});
} else {
osparc.study.Utils.createStudyFromTemplate(templateData, this._loadingPage)
.then(newStudyData => {
const studyId = newStudyData["uuid"];
const openCB = () => this._hideLoadingPage();
const cancelCB = () => {
this._hideLoadingPage();
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "delete", params);
};
const isStudyCreation = true;
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);
})
.catch(err => {
this._hideLoadingPage();
osparc.FlashMessenger.logError(err);
});
}
},

_createStudyFromService: function() {
throw new Error("Abstract method called!");
_createStudyFromService: function(key, version) {
if (!this._checkLoggedIn()) {
return;
}

const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true});
this._showLoadingPage(this.tr("Creating ") + studyAlias);

osparc.study.Utils.createStudyFromService(key, version)
.then(studyId => {
const openCB = () => this._hideLoadingPage();
const cancelCB = () => {
this._hideLoadingPage();
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "delete", params);
};
const isStudyCreation = true;
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);
})
.catch(err => {
this._hideLoadingPage();
osparc.FlashMessenger.logError(err);
});
},

_applyMultiSelection: function(value) {
return;
},

_deleteResourceRequested: function(resourceId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ qx.Class.define("osparc.dashboard.ServiceBrowser", {
this.__sortBy = osparc.service.SortServicesButtons.DefaultSorting;
},

properties: {
multiSelection: {
check: "Boolean",
init: false,
nullable: false,
event: "changeMultiSelection",
apply: "__applyMultiSelection"
}
},

members: {
__sortBy: null,

Expand Down Expand Up @@ -113,35 +103,6 @@ qx.Class.define("osparc.dashboard.ServiceBrowser", {
this.resetSelection();
},

_createStudyFromService: function(key, version) {
if (!this._checkLoggedIn()) {
return;
}

const studyAlias = osparc.product.Utils.getStudyAlias({firstUpperCase: true});
this._showLoadingPage(this.tr("Creating ") + studyAlias);

osparc.study.Utils.createStudyFromService(key, version)
.then(studyId => {
const openCB = () => this._hideLoadingPage();
const cancelCB = () => {
this._hideLoadingPage();
const params = {
url: {
studyId
}
};
osparc.data.Resources.fetch("studies", "delete", params);
};
const isStudyCreation = true;
this._startStudyById(studyId, openCB, cancelCB, isStudyCreation);
})
.catch(err => {
this._hideLoadingPage();
osparc.FlashMessenger.logError(err);
});
},

// LAYOUT //
_createLayout: function() {
this._createSearchBar();
Expand Down
Loading
Loading