@@ -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 } ) ;
0 commit comments