Skip to content

Commit fbcf000

Browse files
committed
Templates store
1 parent e51ad6a commit fbcf000

File tree

5 files changed

+94
-54
lines changed

5 files changed

+94
-54
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ qx.Class.define("osparc.dashboard.Dashboard", {
182182
const groupsStore = osparc.store.Groups.getInstance();
183183
preResourcePromises.push(groupsStore.fetchGroupsAndMembers());
184184
preResourcePromises.push(osparc.store.Services.getServicesLatest(false));
185+
preResourcePromises.push(osparc.store.Templates.getInstance().fetchAllTemplates());
185186
Promise.all(preResourcePromises)
186187
.then(() => {
187188
[

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,32 +158,30 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
158158
return control || this.base(arguments, id);
159159
},
160160

161-
__addItems: async function() {
162-
await this.__addNewStudyItems();
161+
__addItems: function() {
162+
this.__addNewStudyItems();
163163
this.__addMoreMenu();
164164
this.getChildControl("new-folder");
165165
},
166166

167-
__addNewStudyItems: async function() {
167+
__addNewStudyItems: function() {
168168
const plusButtonConfig = osparc.store.Products.getInstance().getPlusButtonUiConfig();
169169
if (plusButtonConfig) {
170-
await osparc.data.Resources.get("templates")
171-
.then(templates => {
172-
if (plusButtonConfig["categories"]) {
173-
this.__addCategories(plusButtonConfig["categories"]);
174-
}
175-
plusButtonConfig["resources"].forEach(buttonConfig => {
176-
if (buttonConfig["showDisabled"]) {
177-
this.__addDisabledButton(buttonConfig);
178-
} else if (buttonConfig["resourceType"] === "study") {
179-
this.__addEmptyStudyButton(buttonConfig);
180-
} else if (buttonConfig["resourceType"] === "template") {
181-
this.__addFromTemplateButton(buttonConfig, templates);
182-
} else if (buttonConfig["resourceType"] === "service") {
183-
this.__addFromServiceButton(buttonConfig);
184-
}
185-
});
186-
});
170+
const templates = osparc.store.Templates.getInstance().getTemplates()
171+
if (plusButtonConfig["categories"]) {
172+
this.__addCategories(plusButtonConfig["categories"]);
173+
}
174+
plusButtonConfig["resources"].forEach(buttonConfig => {
175+
if (buttonConfig["showDisabled"]) {
176+
this.__addDisabledButton(buttonConfig);
177+
} else if (buttonConfig["resourceType"] === "study") {
178+
this.__addEmptyStudyButton(buttonConfig);
179+
} else if (buttonConfig["resourceType"] === "template") {
180+
this.__addFromTemplateButton(buttonConfig, templates);
181+
} else if (buttonConfig["resourceType"] === "service") {
182+
this.__addFromServiceButton(buttonConfig);
183+
}
184+
});
187185
}
188186
},
189187

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ qx.Class.define("osparc.dashboard.NewStudies", {
3636
});
3737
this._add(this.__flatList);
3838

39-
osparc.data.Resources.get("templates")
40-
.then(templates => {
41-
const displayTemplates = newButtonsInfo.filter(newButtonInfo => {
42-
if (newButtonInfo.showDisabled) {
43-
return true;
44-
}
45-
return templates.find(t => t.name === newButtonInfo.expectedTemplateLabel);
46-
});
47-
this.__newStudies = displayTemplates;
48-
})
49-
.catch(console.error)
50-
.finally(() => this.fireEvent("templatesLoaded"));
39+
const templates = osparc.store.Templates.getInstance().getTemplates()
40+
this.__newStudies = newButtonsInfo.filter(newButtonInfo => {
41+
if (newButtonInfo.showDisabled) {
42+
return true;
43+
}
44+
return templates.find(t => t.name === newButtonInfo.expectedTemplateLabel);
45+
});
46+
this.fireEvent("templatesLoaded");
5147
},
5248

5349
properties: {

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -973,29 +973,27 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
973973
newPlansBtn.setEnabled(true);
974974

975975
newPlansBtn.addListener("tap", () => {
976-
osparc.data.Resources.get("templates")
977-
.then(templates => {
978-
if (templates) {
979-
const newStudies = new osparc.dashboard.NewStudies(newStudiesConfig);
980-
newStudies.addListener("templatesLoaded", () => {
981-
newStudies.setGroupBy("category");
982-
const winTitle = this.tr("New Plan");
983-
const win = osparc.ui.window.Window.popUpInWindow(newStudies, winTitle, osparc.dashboard.NewStudies.WIDTH+40, 300).set({
984-
clickAwayClose: false,
985-
resizable: true
986-
});
987-
newStudies.addListener("newStudyClicked", e => {
988-
win.close();
989-
const templateInfo = e.getData();
990-
const templateData = templates.find(t => t.name === templateInfo.expectedTemplateLabel);
991-
if (templateData) {
992-
this.__newPlanBtnClicked(templateData, templateInfo.newStudyLabel);
993-
}
994-
});
995-
osparc.utils.Utils.setIdToWidget(win, "newStudiesWindow");
996-
});
997-
}
976+
const templates = osparc.store.Templates.getInstance().getTemplates();
977+
if (templates) {
978+
const newStudies = new osparc.dashboard.NewStudies(newStudiesConfig);
979+
newStudies.addListener("templatesLoaded", () => {
980+
newStudies.setGroupBy("category");
981+
const winTitle = this.tr("New Plan");
982+
const win = osparc.ui.window.Window.popUpInWindow(newStudies, winTitle, osparc.dashboard.NewStudies.WIDTH+40, 300).set({
983+
clickAwayClose: false,
984+
resizable: true
985+
});
986+
newStudies.addListener("newStudyClicked", e => {
987+
win.close();
988+
const templateInfo = e.getData();
989+
const templateData = templates.find(t => t.name === templateInfo.expectedTemplateLabel);
990+
if (templateData) {
991+
this.__newPlanBtnClicked(templateData, templateInfo.newStudyLabel);
992+
}
993+
});
994+
osparc.utils.Utils.setIdToWidget(win, "newStudiesWindow");
998995
});
996+
}
999997
});
1000998
}
1001999
},
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2025 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.store.Templates", {
19+
extend: qx.core.Object,
20+
type: "singleton",
21+
22+
construct: function() {
23+
this.base(arguments);
24+
25+
this.__templates = [];
26+
},
27+
28+
members: {
29+
__templates: null,
30+
31+
fetchAllTemplates: function() {
32+
if (this.__templates.length) {
33+
return new Promise(resolve => resolve(this.__templates));
34+
}
35+
36+
return osparc.data.Resources.getInstance().getAllPages("templates")
37+
.then(templates => {
38+
this.__templates = templates;
39+
return templates;
40+
});
41+
},
42+
43+
getTemplates: function() {
44+
return this.__templates;
45+
},
46+
}
47+
});

0 commit comments

Comments
 (0)