Skip to content

Commit ac7d8d7

Browse files
committed
refactor
1 parent e373cdc commit ac7d8d7

File tree

5 files changed

+54
-58
lines changed

5 files changed

+54
-58
lines changed

services/static-webserver/client/source/class/osparc/dashboard/NewPlusMenu.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
118118
__addNewStudyItems: async function() {
119119
await osparc.data.Resources.get("templates")
120120
.then(templates => {
121-
const newStudiesData = osparc.store.Products.getInstance().getPlusButtonUiConfig();
122-
if (newStudiesData["categories"]) {
123-
this.__addCategories(newStudiesData["categories"]);
121+
const plusButtonConfig = osparc.store.Products.getInstance().getPlusButtonUiConfig();
122+
if (plusButtonConfig["categories"]) {
123+
this.__addCategories(plusButtonConfig["categories"]);
124124
}
125-
newStudiesData["resources"].forEach(newStudyData => {
125+
plusButtonConfig["resources"].forEach(newStudyData => {
126126
if (newStudyData["showDisabled"]) {
127127
this.__addDisabledButton(newStudyData);
128128
} else if (newStudyData["resourceType"] === "study") {

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
1616
************************************************************************ */
1717

18-
/**
19-
* @asset(osparc/ui_config.json")
20-
*/
21-
2218
/**
2319
* Widget that shows lists user's studies.
2420
*
@@ -979,39 +975,36 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
979975
this._resourcesContainer.addNonResourceCard(newPlansBtn);
980976
newPlansBtn.setEnabled(false);
981977

982-
osparc.utils.Utils.fetchJSON("/resource/osparc/ui_config.json")
983-
.then(newStudiesData => {
984-
const product = osparc.product.Utils.getProductName()
985-
if (product in newStudiesData) {
986-
newPlansBtn.setEnabled(true);
987-
988-
newPlansBtn.addListener("tap", () => {
989-
osparc.data.Resources.get("templates")
990-
.then(templates => {
991-
if (templates) {
992-
const newStudies = new osparc.dashboard.NewStudies(newStudiesData[product]);
993-
newStudies.addListener("templatesLoaded", () => {
994-
newStudies.setGroupBy("category");
995-
const winTitle = this.tr("New Plan");
996-
const win = osparc.ui.window.Window.popUpInWindow(newStudies, winTitle, osparc.dashboard.NewStudies.WIDTH+40, 300).set({
997-
clickAwayClose: false,
998-
resizable: true
999-
});
1000-
newStudies.addListener("newStudyClicked", e => {
1001-
win.close();
1002-
const templateInfo = e.getData();
1003-
const templateData = templates.find(t => t.name === templateInfo.expectedTemplateLabel);
1004-
if (templateData) {
1005-
this.__newPlanBtnClicked(templateData, templateInfo.newStudyLabel);
1006-
}
1007-
});
1008-
osparc.utils.Utils.setIdToWidget(win, "newStudiesWindow");
1009-
});
1010-
}
978+
const newStudiesData = osparc.store.Products.getInstance().getNewStudiesUiConfig();
979+
if (newStudiesData) {
980+
newPlansBtn.setEnabled(true);
981+
982+
newPlansBtn.addListener("tap", () => {
983+
osparc.data.Resources.get("templates")
984+
.then(templates => {
985+
if (templates) {
986+
const newStudies = new osparc.dashboard.NewStudies(newStudiesData);
987+
newStudies.addListener("templatesLoaded", () => {
988+
newStudies.setGroupBy("category");
989+
const winTitle = this.tr("New Plan");
990+
const win = osparc.ui.window.Window.popUpInWindow(newStudies, winTitle, osparc.dashboard.NewStudies.WIDTH+40, 300).set({
991+
clickAwayClose: false,
992+
resizable: true
993+
});
994+
newStudies.addListener("newStudyClicked", e => {
995+
win.close();
996+
const templateInfo = e.getData();
997+
const templateData = templates.find(t => t.name === templateInfo.expectedTemplateLabel);
998+
if (templateData) {
999+
this.__newPlanBtnClicked(templateData, templateInfo.newStudyLabel);
1000+
}
1001+
});
1002+
osparc.utils.Utils.setIdToWidget(win, "newStudiesWindow");
10111003
});
1004+
}
10121005
});
1013-
}
10141006
});
1007+
}
10151008
},
10161009

10171010
// Used in S4L products
@@ -1042,16 +1035,13 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
10421035

10431036
__addPlusButtonsFromServices: function() {
10441037
// add new plus buttons if key services exists
1045-
osparc.utils.Utils.fetchJSON("/resource/osparc/ui_config.json")
1046-
.then(newStudiesData => {
1047-
const product = osparc.product.Utils.getProductName()
1048-
if (product in newStudiesData) {
1049-
const newButtonsInfo = newStudiesData[product].resources;
1050-
newButtonsInfo.forEach(newButtonInfo => {
1051-
this.__addNewStudyFromServiceButtons(newButtonInfo.expectedKey, newButtonInfo);
1052-
});
1053-
}
1038+
const newStudiesData = osparc.store.Products.getInstance().getNewStudiesUiConfig();
1039+
if (newStudiesData) {
1040+
const newButtonsInfo = newStudiesData["resources"];
1041+
newButtonsInfo.forEach(newButtonInfo => {
1042+
this.__addNewStudyFromServiceButtons(newButtonInfo.expectedKey, newButtonInfo);
10541043
});
1044+
}
10551045
},
10561046

10571047
// LAYOUT //

services/static-webserver/client/source/class/osparc/desktop/MainPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ qx.Class.define("osparc.desktop.MainPage", {
6767
}
6868
preloadPromises.push(store.getAllClassifiers(true));
6969
preloadPromises.push(osparc.store.Tags.getInstance().fetchTags());
70-
preloadPromises.push(osparc.store.Products.getInstance().fetchPlusButtonUiConfig());
70+
preloadPromises.push(osparc.store.Products.getInstance().fetchUiConfig());
7171
Promise.all(preloadPromises)
7272
.then(() => {
7373
const mainStack = this.__createMainStack();

services/static-webserver/client/source/class/osparc/store/Products.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,35 @@
1515
1616
************************************************************************ */
1717

18+
/**
19+
* @asset(osparc/ui_config.json")
20+
*/
21+
1822
qx.Class.define("osparc.store.Products", {
1923
extend: qx.core.Object,
2024
type: "singleton",
2125

2226
members: {
23-
__plusButtonUiConfig: null,
27+
__uiConfig: null,
2428

25-
fetchPlusButtonUiConfig: function() {
29+
fetchUiConfig: function() {
2630
return osparc.utils.Utils.fetchJSON("/resource/osparc/ui_config.json")
2731
.then(uiConfig => {
2832
const product = osparc.product.Utils.getProductName()
29-
if (product in uiConfig && "plusButton" in uiConfig[product]) {
30-
this.__plusButtonUiConfig = uiConfig[product]["plusButton"];
31-
} else {
32-
this.__plusButtonUiConfig = false;
33+
if (product in uiConfig) {
34+
this.__uiConfig = uiConfig[product];
3335
}
34-
return this.__plusButtonUiConfig;
36+
return this.__uiConfig;
3537
})
3638
.catch(console.error);
3739
},
3840

3941
getPlusButtonUiConfig: function() {
40-
return this.__plusButtonUiConfig;
42+
return this.__uiConfig["plusButton"];
43+
},
44+
45+
getNewStudiesUiConfig: function() {
46+
return this.__uiConfig["newStudies"];
4147
},
4248
}
4349
});

services/static-webserver/client/source/resource/osparc/ui_config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"tis": {
3-
"NO_plusButton": {
3+
"newStudies": {
44
"categories": [{
55
"id": "precomputed",
66
"title": "Precomputed"
@@ -55,7 +55,7 @@
5555
}
5656
},
5757
"tiplite": {
58-
"NO_plusButton": {
58+
"newStudies": {
5959
"categories": [{
6060
"id": "precomputed",
6161
"title": "Precomputed"

0 commit comments

Comments
 (0)