Skip to content

Commit bd32496

Browse files
committed
refactoring
1 parent a56f929 commit bd32496

File tree

2 files changed

+57
-30
lines changed

2 files changed

+57
-30
lines changed

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

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,13 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
142142
if (newStudiesData["categories"]) {
143143
this.__addCategories(newStudiesData["categories"]);
144144
}
145-
if (newStudiesData["linkedResource"] === "templates") {
146-
newStudiesData["resources"].forEach(templateData => {
147-
this.__addFromTemplateButton(templateData, templates);
148-
});
149-
}
145+
newStudiesData["resources"].forEach(resourceData => {
146+
if (resourceData["resourceType"] === "template") {
147+
this.__addFromTemplateButton(resourceData, templates);
148+
} else if (resourceData["resourceType"] === "service") {
149+
this.__addFromServiceButton(resourceData);
150+
}
151+
});
150152
});
151153
},
152154

@@ -169,10 +171,36 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
169171
});
170172
},
171173

174+
__createFromResourceButton: function(resourceData) {
175+
const icon = "icon" in resourceData ? resourceData["icon"] : null;
176+
const menuButton = this.self().createMenuButton(resourceData.title, icon);
177+
osparc.utils.Utils.setIdToWidget(menuButton, resourceData.idToWidget);
178+
return menuButton;
179+
},
180+
181+
__addFromResourceButton: function(menuButton, resourceData) {
182+
if (menuButton.getIcon()) {
183+
menuButton.getChildControl("icon").set({
184+
scale: true,
185+
maxWidth: 22,
186+
maxHeight: 22,
187+
})
188+
}
189+
190+
let idx = null;
191+
if (resourceData.category) {
192+
idx = this.__getLastIdxFromCategory(resourceData.category);
193+
}
194+
if (idx) {
195+
menuButton["categoryId"] = resourceData.category;
196+
this.addAt(menuButton, idx+1);
197+
} else {
198+
this.add(menuButton);
199+
}
200+
},
201+
172202
__addFromTemplateButton: function(templateData, templates) {
173-
const icon = "icon" in templateData ? templateData["icon"] : null;
174-
const menuButton = this.self().createMenuButton(templateData.title, icon);
175-
osparc.utils.Utils.setIdToWidget(menuButton, templateData.idToWidget);
203+
const menuButton = this.__createFromResourceButton(templateData);
176204

177205
if (templateData.showDisabled) {
178206
menuButton.set({
@@ -194,24 +222,13 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
194222
}
195223
}
196224

197-
if (menuButton.getIcon()) {
198-
menuButton.getChildControl("icon").set({
199-
scale: true,
200-
maxWidth: 22,
201-
maxHeight: 22,
202-
})
203-
}
225+
this.__addFromResourceButton(menuButton, templateData);
226+
},
204227

205-
let idx = null;
206-
if (templateData.category) {
207-
idx = this.__getLastIdxFromCategory(templateData.category);
208-
}
209-
if (idx) {
210-
menuButton["categoryId"] = templateData.category;
211-
this.addAt(menuButton, idx+1);
212-
} else {
213-
this.add(menuButton);
214-
}
228+
__addFromServiceButton: function(serviceData) {
229+
const menuButton = this.__createFromResourceButton(serviceData);
230+
231+
this.__addFromResourceButton(menuButton, serviceData);
215232
},
216233

217234
__createNewFolder: function() {

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,32 @@
88
"title": "Personalized",
99
"description": "In the process, TIP will launch simulations on AWS.<br>The associated resource costs will be deduced from your Credits."
1010
}],
11-
"linkedResource": "templates",
1211
"resources": [{
12+
"resourceType": "template",
1313
"expectedTemplateLabel": "TI Planning Tool",
1414
"title": "Classic TI",
1515
"description": "",
1616
"newStudyLabel": "Classic TI",
1717
"category": "precomputed",
1818
"idToWidget": "newTIPlanButton"
1919
}, {
20+
"resourceType": "template",
2021
"expectedTemplateLabel": "mcTI Planning Tool",
2122
"title": "Multichannel TI",
2223
"description": "",
2324
"newStudyLabel": "Multichannel TI",
2425
"category": "precomputed",
2526
"idToWidget": "newMTIPlanButton"
2627
}, {
28+
"resourceType": "template",
2729
"expectedTemplateLabel": "pmTI Planning Tool",
2830
"title": "Phase-modulation TI",
2931
"description": "",
3032
"newStudyLabel": "Phase-modulation TI",
3133
"category": "precomputed",
3234
"idToWidget": "newPMTIPlanButton"
3335
}, {
36+
"resourceType": "template",
3437
"expectedTemplateLabel": "personalized TI Planning Tool",
3538
"title": "Personalized<br>Classic TI",
3639
"description": "",
@@ -39,6 +42,7 @@
3942
"idToWidget": "personalizationNewTIPlanButton",
4043
"billable": true
4144
}, {
45+
"resourceType": "template",
4246
"expectedTemplateLabel": "personalized mcTI Planning Tool",
4347
"title": "Personalized<br>Multichannel TI",
4448
"description": "",
@@ -47,6 +51,7 @@
4751
"idToWidget": "personalizationNewMTIPlanButton",
4852
"billable": true
4953
}, {
54+
"resourceType": "template",
5055
"expectedTemplateLabel": "personalized pmTI Planning Tool",
5156
"title": "Personalized<br>Phase-modulation TI",
5257
"description": "",
@@ -65,8 +70,8 @@
6570
"title": "Personalized",
6671
"description": "In the process, TIP will launch simulations on AWS.<br>The associated resource costs will be deduced from your Credits."
6772
}],
68-
"linkedResource": "templates",
6973
"resources": [{
74+
"resourceType": "template",
7075
"expectedTemplateLabel": "TI Planning Tool",
7176
"title": "Classic TI",
7277
"description": "",
@@ -75,6 +80,7 @@
7580
"idToWidget": "newTIPlanButton"
7681
}, {
7782
"showDisabled": true,
83+
"resourceType": "template",
7884
"expectedTemplateLabel": "mcTI Planning Tool",
7985
"title": "Multichannel TI",
8086
"description": "Not available in ${replace_me_product_name}",
@@ -83,6 +89,7 @@
8389
"idToWidget": "newMTIPlanButton"
8490
}, {
8591
"showDisabled": true,
92+
"resourceType": "template",
8693
"expectedTemplateLabel": "pmTI Planning Tool",
8794
"title": "Phase-modulation TI",
8895
"description": "Not available in ${replace_me_product_name}",
@@ -91,6 +98,7 @@
9198
"idToWidget": "newPMTIPlanButton"
9299
}, {
93100
"showDisabled": true,
101+
"resourceType": "template",
94102
"expectedTemplateLabel": "personalized TI Planning Tool",
95103
"title": "Personalized<br>Classic TI",
96104
"description": "Not available in ${replace_me_product_name}",
@@ -100,6 +108,7 @@
100108
"billable": true
101109
}, {
102110
"showDisabled": true,
111+
"resourceType": "template",
103112
"expectedTemplateLabel": "personalized mcTI Planning Tool",
104113
"title": "Personalized<br>Multichannel TI",
105114
"description": "Not available in ${replace_me_product_name}",
@@ -109,6 +118,7 @@
109118
"billable": true
110119
}, {
111120
"showDisabled": true,
121+
"resourceType": "template",
112122
"expectedTemplateLabel": "personalized pmTI Planning Tool",
113123
"title": "Personalized<br>Phase-modulation TI",
114124
"description": "Not available in ${replace_me_product_name}",
@@ -119,8 +129,8 @@
119129
}]
120130
},
121131
"s4l": {
122-
"linkedResource": "services",
123132
"resources": [{
133+
"resourceType": "service",
124134
"expectedKey": "simcore/services/dynamic/s4l-ui",
125135
"title": "Start Sim4Life",
126136
"description": "New Sim4Life project",
@@ -129,8 +139,8 @@
129139
}]
130140
},
131141
"s4lacad": {
132-
"linkedResource": "services",
133142
"resources": [{
143+
"resourceType": "service",
134144
"expectedKey": "simcore/services/dynamic/s4l-ui",
135145
"title": "Start Sim4Life",
136146
"description": "New Sim4Life project",
@@ -139,8 +149,8 @@
139149
}]
140150
},
141151
"s4llite": {
142-
"linkedResource": "services",
143152
"resources": [{
153+
"resourceType": "service",
144154
"expectedKey": "simcore/services/dynamic/s4l-ui-lite",
145155
"title": "Start ${replace_me_product_name}",
146156
"description": "New project",

0 commit comments

Comments
 (0)