Skip to content

Commit 1cb6011

Browse files
committed
mapping
1 parent 8b39ccc commit 1cb6011

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
140140
this._showLoadingPage(this.tr("Creating ") + (templateData.name || osparc.product.Utils.getStudyAlias({firstUpperCase: true})));
141141

142142
const studyOptions = new osparc.study.StudyOptions();
143+
// they will be patched once the study is created
143144
studyOptions.setPatchStudy(false);
144145
studyOptions.setStudyData(templateData);
145146
const win = osparc.study.StudyOptions.popUpInWindow(studyOptions);
@@ -156,8 +157,8 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
156157
const nodesPricingUnits = studyOptions.getChildControl("study-pricing-units").getNodePricingUnits();
157158
win.close();
158159
osparc.study.Utils.createStudyFromTemplate(templateData, this._loadingPage)
159-
.then(studyData => {
160-
const studyId = studyData["uuid"];
160+
.then(newStudyData => {
161+
const studyId = newStudyData["uuid"];
161162
const openCB = () => {
162163
this._hideLoadingPage();
163164
};
@@ -172,18 +173,30 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
172173
};
173174

174175
const promises = [];
175-
if (studyData["name"] !== titleSelection) {
176-
promises.push(osparc.study.StudyOptions.updateName(studyData, titleSelection));
176+
// patch the name
177+
if (newStudyData["name"] !== titleSelection) {
178+
promises.push(osparc.study.StudyOptions.updateName(newStudyData, titleSelection));
177179
}
180+
// patch the wallet
178181
if (walletSelection.length && walletSelection[0]["walletId"]) {
179182
const walletId = walletSelection[0]["walletId"];
180-
promises.push(osparc.study.StudyOptions.updateWallet(studyData["uuid"], walletId));
183+
promises.push(osparc.study.StudyOptions.updateWallet(newStudyData["uuid"], walletId));
181184
}
182-
nodesPricingUnits.forEach(nodePricingUnits => {
183-
const nodeId = nodePricingUnits.getNodeId();
184-
const pricingPlanId = nodePricingUnits.getPricingPlanId();
185+
// patch the pricing units
186+
// the nodeIds are coming from the original template, they need to be mapped to the newStudy
187+
const workbench = newStudyData["workbench"];
188+
const nodesIdsListed = [];
189+
Object.keys(workbench).forEach(nodeId => {
190+
const node = workbench[nodeId];
191+
if (osparc.study.StudyPricingUnits.includeInList(node)) {
192+
nodesIdsListed.push(nodeId);
193+
}
194+
});
195+
nodesPricingUnits.forEach((nodePricingUnits, idx) => {
185196
const selectedPricingUnitId = nodePricingUnits.getPricingUnits().getSelectedUnitId();
186197
if (selectedPricingUnitId) {
198+
const nodeId = nodesIdsListed[idx];
199+
const pricingPlanId = nodePricingUnits.getPricingPlanId();
187200
promises.push(osparc.study.NodePricingUnits.patchPricingUnitSelection(studyId, nodeId, pricingPlanId, selectedPricingUnitId));
188201
}
189202
});

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ qx.Class.define("osparc.study.StudyPricingUnits", {
3737
"unitsReady": "qx.event.type.Event"
3838
},
3939

40+
statics: {
41+
includeInList: function(node) {
42+
return !osparc.data.model.Node.isFrontend(node);
43+
},
44+
},
45+
4046
members: {
4147
__studyData: null,
4248
__nodePricingUnits: null,
@@ -56,13 +62,12 @@ qx.Class.define("osparc.study.StudyPricingUnits", {
5662
const workbench = this.__studyData["workbench"];
5763
Object.keys(workbench).forEach(nodeId => {
5864
const node = workbench[nodeId];
59-
if (osparc.data.model.Node.isFrontend(node)) {
60-
return;
65+
if (this.self().includeInList(node)) {
66+
const nodePricingUnits = new osparc.study.NodePricingUnits(this.__studyData["uuid"], nodeId, node);
67+
this.__nodePricingUnits.push(nodePricingUnits);
68+
this._add(nodePricingUnits);
69+
promises.push(nodePricingUnits.showPricingUnits());
6170
}
62-
const nodePricingUnits = new osparc.study.NodePricingUnits(this.__studyData["uuid"], nodeId, node);
63-
this.__nodePricingUnits.push(nodePricingUnits);
64-
this._add(nodePricingUnits);
65-
promises.push(nodePricingUnits.showPricingUnits());
6671
});
6772
}
6873
Promise.all(promises)

0 commit comments

Comments
 (0)