Skip to content

Commit 399afb6

Browse files
committed
refactor
1 parent b475016 commit 399afb6

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
790790
if (selectedPricingUnitId) {
791791
const nodeId = nodesIdsListed[idx];
792792
const pricingPlanId = nodePricingUnits.getPricingPlanId();
793-
promises.push(osparc.study.NodePricingUnits.patchPricingUnitSelection(studyId, nodeId, pricingPlanId, selectedPricingUnitId));
793+
promises.push(osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlanId, selectedPricingUnitId));
794794
}
795795
});
796796

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ qx.Class.define("osparc.node.TierSelectionView", {
9696
if (selection.length) {
9797
tierBox.setEnabled(false);
9898
const selectedUnitId = selection[0].getModel();
99-
osparc.study.NodePricingUnits.patchPricingUnitSelection(studyId, nodeId, pricingPlans["pricingPlanId"], selectedUnitId)
99+
osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlans["pricingPlanId"], selectedUnitId)
100100
.finally(() => {
101101
tierBox.setEnabled(true);
102102
showSelectedTier(selectedUnitId);

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,21 @@ qx.Class.define("osparc.store.Study", {
244244
pricingUnitId: selectedUnitId
245245
}
246246
};
247-
return osparc.data.Resources.fetch("studies", "putPricingUnit", params);
247+
return osparc.data.Resources.fetch("studies", "putPricingUnit", params)
248+
.then(() => {
249+
// update the cache
250+
if (!(studyId in this.__nodePricingUnit)) {
251+
this.__nodePricingUnit[studyId] = {};
252+
}
253+
const selectedPricingUnit = osparc.store.Pricing.getInstance().getPricingUnit(planId, selectedUnitId);
254+
if (selectedPricingUnit) {
255+
this.__nodePricingUnit[studyId][nodeId] = selectedUnitId;
256+
}
257+
})
258+
.catch(err => {
259+
console.error("Failed to update selected pricing unit:", err);
260+
throw err;
261+
});
248262
},
249263
}
250264
});

services/static-webserver/client/source/class/osparc/study/NodePricingUnits.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ qx.Class.define("osparc.study.NodePricingUnits", {
7272
},
7373
},
7474

75-
statics: {
76-
patchPricingUnitSelection: function(studyId, nodeId, planId, selectedUnitId) {
77-
return osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, planId, selectedUnitId);
78-
}
79-
},
80-
8175
members: {
8276
__nodeKey: null,
8377
__nodeVersion: null,
@@ -115,7 +109,7 @@ qx.Class.define("osparc.study.NodePricingUnits", {
115109
if (this.isPatchNode()) {
116110
pricingUnitTiers.setEnabled(false);
117111
const pricingPlanId = this.getPricingPlanId();
118-
this.self().patchPricingUnitSelection(studyId, nodeId, pricingPlanId, selectedPricingUnitId)
112+
osparc.store.Study.updateSelectedPricingUnit(studyId, nodeId, pricingPlanId, selectedPricingUnitId)
119113
.then(() => pricingUnitTiers.setSelectedUnitId(selectedPricingUnitId))
120114
.catch(err => osparc.FlashMessenger.logError(err, this.tr("Cannot change Tier")))
121115
.finally(() => pricingUnitTiers.setEnabled(true));

0 commit comments

Comments
 (0)