Skip to content

Commit 4d132f4

Browse files
authored
Merge branch 'master' into enh/show-hypertools-if-any
2 parents 7fb89cb + 2de3feb commit 4d132f4

File tree

12 files changed

+181
-94
lines changed

12 files changed

+181
-94
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,8 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
787787
if (selectedPricingUnitId) {
788788
const nodeId = nodesIdsListed[idx];
789789
const pricingPlanId = nodePricingUnits.getPricingPlanId();
790-
promises.push(osparc.study.NodePricingUnits.patchPricingUnitSelection(studyId, nodeId, pricingPlanId, selectedPricingUnitId));
790+
const selectedUnit = nodePricingUnits.getPricingUnits().getSelectedUnit();
791+
promises.push(osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlanId, selectedUnit));
791792
}
792793
});
793794

services/static-webserver/client/source/class/osparc/info/MergedLarge.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,7 @@ qx.Class.define("osparc.info.MergedLarge", {
317317
resourcesLayout.exclude();
318318
let promise = null;
319319
if (this.getNode().getNodeId()) {
320-
const params = {
321-
url: {
322-
studyId: this.getStudy().getUuid(),
323-
nodeId: this.getNode().getNodeId()
324-
}
325-
};
326-
promise = osparc.data.Resources.get("nodesInStudyResources", params);
320+
promise = osparc.store.Study.getNodeResources(this.getStudy().getUuid(), this.getNode().getNodeId());
327321
} else {
328322
promise = osparc.store.Services.getResources(this.getNode().getKey(), this.getNode().getVersion())
329323
}

services/static-webserver/client/source/class/osparc/info/ServiceLarge.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,7 @@ qx.Class.define("osparc.info.ServiceLarge", {
407407
resourcesLayout.exclude();
408408
let promise = null;
409409
if (this.getNodeId()) {
410-
const params = {
411-
url: {
412-
studyId: this.getStudyId(),
413-
nodeId: this.getNodeId()
414-
}
415-
};
416-
promise = osparc.data.Resources.get("nodesInStudyResources", params);
410+
promise = osparc.store.Study.getNodeResources(this.getStudyId(), this.getNodeId());
417411
} else {
418412
promise = osparc.store.Services.getResources(this.getService()["key"], this.getService()["version"])
419413
}

services/static-webserver/client/source/class/osparc/node/TierSelectionView.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ qx.Class.define("osparc.node.TierSelectionView", {
4646
tiersLayout.add(tierBox);
4747

4848
const node = this.getNode();
49-
osparc.store.Pricing.getInstance().fetchPricingPlansService(node.getKey(), node.getVersion())
49+
osparc.store.Services.getPricingPlan(node.getKey(), node.getVersion())
5050
.then(pricingPlans => {
5151
if (pricingPlans && "pricingUnits" in pricingPlans && pricingPlans["pricingUnits"].length) {
5252
const pricingUnits = pricingPlans["pricingUnits"].map(pricingUnitData => {
@@ -59,16 +59,10 @@ qx.Class.define("osparc.node.TierSelectionView", {
5959
});
6060
const studyId = node.getStudy().getUuid();
6161
const nodeId = node.getNodeId();
62-
const unitParams = {
63-
url: {
64-
studyId,
65-
nodeId
66-
}
67-
};
68-
osparc.data.Resources.fetch("studies", "getPricingUnit", unitParams)
69-
.then(preselectedPricingUnit => {
70-
if (preselectedPricingUnit && preselectedPricingUnit["pricingUnitId"]) {
71-
const tierFound = tierBox.getSelectables().find(t => t.getModel() === preselectedPricingUnit["pricingUnitId"]);
62+
osparc.store.Study.getSelectedPricingUnit(studyId, nodeId)
63+
.then(selectedPricingUnit => {
64+
if (selectedPricingUnit && selectedPricingUnit["pricingUnitId"]) {
65+
const tierFound = tierBox.getSelectables().find(t => t.getModel() === selectedPricingUnit["pricingUnitId"]);
7266
if (tierFound) {
7367
tierBox.setSelection([tierFound]);
7468
} else {
@@ -102,7 +96,8 @@ qx.Class.define("osparc.node.TierSelectionView", {
10296
if (selection.length) {
10397
tierBox.setEnabled(false);
10498
const selectedUnitId = selection[0].getModel();
105-
osparc.study.NodePricingUnits.patchPricingUnitSelection(studyId, nodeId, pricingPlans["pricingPlanId"], selectedUnitId)
99+
const selectedUnit = pricingUnits.find(pUnit => pUnit.getPricingUnitId() === selectedUnitId)
100+
osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlans["pricingPlanId"], selectedUnit)
106101
.finally(() => {
107102
tierBox.setEnabled(true);
108103
showSelectedTier(selectedUnitId);

services/static-webserver/client/source/class/osparc/node/UpdateResourceLimitsView.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ qx.Class.define("osparc.node.UpdateResourceLimitsView", {
4343
this._add(resourcesLayout);
4444

4545
const node = this.getNode();
46-
const params = {
47-
url: {
48-
studyId: node.getStudy().getUuid(),
49-
nodeId: node.getNodeId()
50-
}
51-
};
52-
osparc.data.Resources.get("nodesInStudyResources", params)
46+
osparc.store.Study.getNodeResources(node.getStudy().getUuid(), node.getNodeId())
5347
.then(serviceResources => {
5448
resourcesLayout.show();
5549
const gridLayout = resourcesLayout.getChildren()[1];
@@ -145,17 +139,8 @@ qx.Class.define("osparc.node.UpdateResourceLimitsView", {
145139
}
146140
});
147141
const node = this.getNode();
148-
const params = {
149-
url: {
150-
studyId: node.getStudy().getUuid(),
151-
nodeId: node.getNodeId()
152-
},
153-
data: updatedResources
154-
};
155-
osparc.data.Resources.fetch("nodesInStudyResources", "put", params)
156-
.then(() => {
157-
osparc.FlashMessenger.logAs(this.tr("Limits have been successfully updated"));
158-
})
142+
osparc.store.Study.updateNodeResources(node.getStudy().getUuid(), node.getNodeId(), updatedResources)
143+
.then(() => osparc.FlashMessenger.logAs(this.tr("Limits have been successfully updated")))
159144
.catch(err => osparc.FlashMessenger.logError(err, this.tr("Something went wrong while updating the limits")))
160145
.finally(() => {
161146
this.__saveBtn.setFetching(false);

services/static-webserver/client/source/class/osparc/service/PricingUnitsList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ qx.Class.define("osparc.service.PricingUnitsList", {
4747
},
4848

4949
__fetchUnits: function() {
50-
osparc.store.Pricing.getInstance().fetchPricingPlansService(this.__serviceMetadata["key"], this.__serviceMetadata["version"])
50+
osparc.store.Services.getPricingPlan(this.__serviceMetadata["key"], this.__serviceMetadata["version"])
5151
.then(data => this.__populateList(data["pricingUnits"]))
5252
.catch(err => {
5353
console.error(err);

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ qx.Class.define("osparc.store.Pricing", {
2222
construct: function() {
2323
this.base(arguments);
2424

25-
this.pricingPlansCached = [];
26-
},
27-
28-
events: {
29-
"pricingPlansChanged": "qx.event.type.Data",
25+
this.__pricingPlansCached = [];
3026
},
3127

3228
members: {
33-
pricingPlansCached: null,
29+
__pricingPlansCached: null,
3430

3531
fetchPricingPlans: function() {
3632
const resourceName = osparc.data.Permissions.getInstance().isAdmin() ? "adminPricingPlans" : "pricingPlans";
@@ -71,16 +67,6 @@ qx.Class.define("osparc.store.Pricing", {
7167
.catch(console.error);
7268
},
7369

74-
fetchPricingPlansService: function(serviceKey, serviceVersion) {
75-
const plansParams = {
76-
url: osparc.data.Resources.getServiceUrl(serviceKey, serviceVersion)
77-
};
78-
return osparc.data.Resources.fetch("services", "pricingPlans", plansParams)
79-
.then(pricingPlansData => {
80-
return pricingPlansData;
81-
});
82-
},
83-
8470
fetchPricingUnits: function(pricingPlanId) {
8571
if (this.getPricingPlan(pricingPlanId) && this.getPricingPlan(pricingPlanId).getPricingUnits().length !== 0) {
8672
return new Promise(resolve => resolve(this.getPricingPlan(pricingPlanId).getPricingUnits()));
@@ -136,11 +122,11 @@ qx.Class.define("osparc.store.Pricing", {
136122
},
137123

138124
getPricingPlans: function() {
139-
return this.pricingPlansCached;
125+
return this.__pricingPlansCached;
140126
},
141127

142128
getPricingPlan: function(pricingPlanId = null) {
143-
return this.pricingPlansCached.find(f => f.getPricingPlanId() === pricingPlanId);
129+
return this.__pricingPlansCached.find(f => f.getPricingPlanId() === pricingPlanId);
144130
},
145131

146132
getPricingUnits: function(pricingPlanId) {
@@ -160,7 +146,7 @@ qx.Class.define("osparc.store.Pricing", {
160146
},
161147

162148
__addToCache: function(pricingPlanData) {
163-
let pricingPlan = this.pricingPlansCached.find(f => f.getPricingPlanId() === pricingPlanData["pricingPlanId"]);
149+
let pricingPlan = this.__pricingPlansCached.find(f => f.getPricingPlanId() === pricingPlanData["pricingPlanId"]);
164150
if (pricingPlan) {
165151
// put
166152
pricingPlan.set({
@@ -173,7 +159,7 @@ qx.Class.define("osparc.store.Pricing", {
173159
} else {
174160
// get and post
175161
pricingPlan = new osparc.data.model.PricingPlan(pricingPlanData);
176-
this.pricingPlansCached.unshift(pricingPlan);
162+
this.__pricingPlansCached.unshift(pricingPlan);
177163
}
178164
return pricingPlan;
179165
},

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ qx.Class.define("osparc.store.Services", {
2222
__servicesCached: {},
2323
__servicesPromisesCached: {},
2424
__studyServicesPromisesCached: {},
25+
__pricingPlansCached: {},
2526

2627
getServicesLatest: function(useCache = true) {
2728
return new Promise(resolve => {
@@ -347,6 +348,24 @@ qx.Class.define("osparc.store.Services", {
347348
return msg;
348349
},
349350

351+
getPricingPlan: function(serviceKey, serviceVersion) {
352+
const serviceUrl = osparc.data.Resources.getServiceUrl(serviceKey, serviceVersion)
353+
// check if the service is already cached
354+
if (serviceUrl in this.__pricingPlansCached) {
355+
return Promise.resolve(this.__pricingPlansCached[serviceUrl]);
356+
}
357+
358+
const plansParams = {
359+
url: serviceUrl,
360+
};
361+
return osparc.data.Resources.fetch("services", "pricingPlans", plansParams)
362+
.then(pricingPlansData => {
363+
// store the fetched pricing plans in the cache
364+
this.__pricingPlansCached[serviceUrl] = pricingPlansData;
365+
return pricingPlansData;
366+
});
367+
},
368+
350369
getFilePicker: function() {
351370
return this.getLatest("simcore/services/frontend/file-picker");
352371
},

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ qx.Class.define("osparc.store.Study", {
1919
type: "static",
2020

2121
statics: {
22+
__nodeResources: null,
23+
__nodePricingUnit: null,
24+
2225
patchStudyData: function(studyData, fieldKey, value) {
2326
if (osparc.data.model.Study.OwnPatch.includes(fieldKey)) {
2427
console.error(fieldKey, "has it's own PATCH path");
@@ -143,5 +146,123 @@ qx.Class.define("osparc.store.Study", {
143146
});
144147
return Promise.all(promises);
145148
},
149+
150+
getNodeResources: function(studyId, nodeId) {
151+
// init nodeResources if it is null
152+
if (this.__nodeResources === null) {
153+
this.__nodeResources = {};
154+
}
155+
156+
// check if the resources for this node are already fetched
157+
if (
158+
studyId in this.__nodeResources &&
159+
nodeId in this.__nodeResources[studyId]
160+
) {
161+
return Promise.resolve(this.__nodeResources[studyId][nodeId]);
162+
}
163+
164+
const params = {
165+
url: {
166+
studyId,
167+
nodeId,
168+
}
169+
};
170+
return osparc.data.Resources.get("nodesInStudyResources", params)
171+
.then(resources => {
172+
// store the fetched resources in the cache
173+
if (!(studyId in this.__nodeResources)) {
174+
this.__nodeResources[studyId] = {};
175+
}
176+
this.__nodeResources[studyId][nodeId] = resources;
177+
return resources;
178+
})
179+
.catch(err => {
180+
console.error("Failed to fetch node resources:", err);
181+
throw err;
182+
});
183+
},
184+
185+
updateNodeResources: function(studyId, nodeId, updatedResources) {
186+
const params = {
187+
url: {
188+
studyId,
189+
nodeId,
190+
},
191+
data: updatedResources
192+
};
193+
return osparc.data.Resources.fetch("nodesInStudyResources", "put", params)
194+
.then(() => {
195+
// update the cache
196+
if (!(studyId in this.__nodeResources)) {
197+
this.__nodeResources[studyId] = {};
198+
}
199+
this.__nodeResources[studyId][nodeId] = updatedResources;
200+
});
201+
},
202+
203+
getSelectedPricingUnit: function(studyId, nodeId) {
204+
// init nodePricingUnit if it is null
205+
if (this.__nodePricingUnit === null) {
206+
this.__nodePricingUnit = {};
207+
}
208+
209+
// check if the pricing unit for this node is already fetched
210+
if (
211+
studyId in this.__nodePricingUnit &&
212+
nodeId in this.__nodePricingUnit[studyId]
213+
) {
214+
return Promise.resolve(this.__nodePricingUnit[studyId][nodeId]);
215+
}
216+
217+
const params = {
218+
url: {
219+
studyId,
220+
nodeId
221+
}
222+
};
223+
return osparc.data.Resources.fetch("studies", "getPricingUnit", params)
224+
.then(selectedPricingUnit => {
225+
// store the fetched pricing unit in the cache
226+
if (!(studyId in this.__nodePricingUnit)) {
227+
this.__nodePricingUnit[studyId] = {};
228+
}
229+
this.__nodePricingUnit[studyId][nodeId] = selectedPricingUnit;
230+
return selectedPricingUnit;
231+
})
232+
.catch(err => {
233+
console.error("Failed to fetch pricing units:", err);
234+
throw err;
235+
});
236+
},
237+
238+
updateSelectedPricingUnit: function(studyId, nodeId, planId, selectedPricingUnit) {
239+
let pricingUnit = null;
240+
if (selectedPricingUnit instanceof osparc.data.model.PricingUnit) {
241+
// convert to JSON if it's a model instance
242+
pricingUnit = JSON.parse(qx.util.Serializer.toJson(selectedPricingUnit));
243+
} else {
244+
pricingUnit = osparc.utils.Utils.deepCloneObject(selectedPricingUnit);
245+
}
246+
const params = {
247+
url: {
248+
studyId,
249+
nodeId,
250+
pricingPlanId: planId,
251+
pricingUnitId: pricingUnit["pricingUnitId"],
252+
}
253+
};
254+
return osparc.data.Resources.fetch("studies", "putPricingUnit", params)
255+
.then(() => {
256+
// update the cache
257+
if (!(studyId in this.__nodePricingUnit)) {
258+
this.__nodePricingUnit[studyId] = {};
259+
}
260+
this.__nodePricingUnit[studyId][nodeId] = pricingUnit;
261+
})
262+
.catch(err => {
263+
console.error("Failed to update selected pricing unit:", err);
264+
throw err;
265+
});
266+
},
146267
}
147268
});

0 commit comments

Comments
 (0)