diff --git a/services/static-webserver/client/source/class/osparc/dashboard/NewPlusMenu.js b/services/static-webserver/client/source/class/osparc/dashboard/NewPlusMenu.js index d0a107114bcd..6d8c391fb934 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/NewPlusMenu.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/NewPlusMenu.js @@ -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); } }); }); @@ -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"], }); }); @@ -299,7 +299,15 @@ 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 @@ -307,22 +315,22 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", { 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) @@ -331,7 +339,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", { "sort": "hits", "order": "down" }); - for (let i=0; i 0) { const menuButton = new qx.ui.menu.Button().set({ @@ -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); } } diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ResourceBrowserBase.js b/services/static-webserver/client/source/class/osparc/dashboard/ResourceBrowserBase.js index bdba8cdf59ab..8d36a43bc7b7 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ResourceBrowserBase.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ResourceBrowserBase.js @@ -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" @@ -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) { diff --git a/services/static-webserver/client/source/class/osparc/dashboard/ServiceBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/ServiceBrowser.js index 0d6ece141027..6c29b754cf62 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/ServiceBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/ServiceBrowser.js @@ -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, @@ -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(); diff --git a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js index a2a7eb15b1a4..010225e27eff 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js @@ -69,14 +69,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { event: "changeCurrentFolderId" }, - multiSelection: { - check: "Boolean", - init: false, - nullable: false, - event: "changeMultiSelection", - apply: "__applyMultiSelection" - }, - // Ordering by Possibilities: // field: type | uuid | name | description | prj_owner | creation_date | last_change_date // direction: asc | desc @@ -1411,7 +1403,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", { return selectButton; }, - __applyMultiSelection: function(value) { + // override + _applyMultiSelection: function(value) { this._resourcesContainer.getCards().forEach(studyItem => { if (osparc.dashboard.ResourceBrowserBase.isCardButtonItem(studyItem)) { studyItem.setMultiSelectionMode(value); diff --git a/services/static-webserver/client/source/class/osparc/dashboard/TemplateBrowser.js b/services/static-webserver/client/source/class/osparc/dashboard/TemplateBrowser.js index 33331b6f590b..c009635307c9 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/TemplateBrowser.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/TemplateBrowser.js @@ -23,16 +23,6 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", { this.base(arguments); }, - properties: { - multiSelection: { - check: "Boolean", - init: false, - nullable: false, - event: "changeMultiSelection", - apply: "__applyMultiSelection" - } - }, - members: { __updateAllButton: null, @@ -131,116 +121,6 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", { this.resetSelection(); }, - _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); - }); - } - }, - // LAYOUT // _createLayout: function() { this._createSearchBar(); diff --git a/tests/e2e/tests/testsToRunSequentially.test.js b/tests/e2e/tests/testsToRunSequentially.test.js index d8b6d24c519f..b7f989e28bc6 100644 --- a/tests/e2e/tests/testsToRunSequentially.test.js +++ b/tests/e2e/tests/testsToRunSequentially.test.js @@ -1,12 +1,10 @@ const { checkUrl } = require('./url.js'); const { checkMetadata } = require('./title'); -const { registerAndLogOut } = require('./register'); const { startupCalls } = require('./startupCalls'); describe('Sequentially run tests', () => { checkUrl(); checkMetadata(); - registerAndLogOut(); startupCalls(); });