@@ -140,30 +140,89 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
140140 const studyAlias = osparc . product . Utils . getStudyAlias ( { firstUpperCase : true } ) ;
141141 this . _showLoadingPage ( this . tr ( "Creating " ) + ( templateData . name || studyAlias ) ) ;
142142
143- const studyOptions = new osparc . study . StudyOptions ( ) ;
144- // they will be patched once the study is created
145- studyOptions . setPatchStudy ( false ) ;
146- studyOptions . setStudyData ( templateData ) ;
147- const win = osparc . study . StudyOptions . popUpInWindow ( studyOptions ) ;
148- win . moveItUp ( ) ;
149- const cancelStudyOptions = ( ) => {
150- this . _hideLoadingPage ( ) ;
151- win . close ( ) ;
152- }
153- win . addListener ( "cancel" , ( ) => cancelStudyOptions ( ) ) ;
154- studyOptions . addListener ( "cancel" , ( ) => cancelStudyOptions ( ) ) ;
155- studyOptions . addListener ( "startStudy" , ( ) => {
156- const newName = studyOptions . getChildControl ( "title-field" ) . getValue ( ) ;
157- const walletSelection = studyOptions . getChildControl ( "wallet-selector" ) . getSelection ( ) ;
158- const nodesPricingUnits = studyOptions . getChildControl ( "study-pricing-units" ) . getNodePricingUnits ( ) ;
159- win . close ( ) ;
160- this . _showLoadingPage ( this . tr ( "Creating " ) + ( newName || studyAlias ) ) ;
143+ if ( osparc . desktop . credits . Utils . areWalletsEnabled ( ) ) {
144+ const studyOptions = new osparc . study . StudyOptions ( ) ;
145+ // they will be patched once the study is created
146+ studyOptions . setPatchStudy ( false ) ;
147+ studyOptions . setStudyData ( templateData ) ;
148+ const win = osparc . study . StudyOptions . popUpInWindow ( studyOptions ) ;
149+ win . moveItUp ( ) ;
150+ const cancelStudyOptions = ( ) => {
151+ this . _hideLoadingPage ( ) ;
152+ win . close ( ) ;
153+ }
154+ win . addListener ( "cancel" , ( ) => cancelStudyOptions ( ) ) ;
155+ studyOptions . addListener ( "cancel" , ( ) => cancelStudyOptions ( ) ) ;
156+ studyOptions . addListener ( "startStudy" , ( ) => {
157+ const newName = studyOptions . getChildControl ( "title-field" ) . getValue ( ) ;
158+ const walletSelection = studyOptions . getChildControl ( "wallet-selector" ) . getSelection ( ) ;
159+ const nodesPricingUnits = studyOptions . getChildControl ( "study-pricing-units" ) . getNodePricingUnits ( ) ;
160+ win . close ( ) ;
161+
162+ this . _showLoadingPage ( this . tr ( "Creating " ) + ( newName || studyAlias ) ) ;
163+ osparc . study . Utils . createStudyFromTemplate ( templateData , this . _loadingPage )
164+ . then ( newStudyData => {
165+ const studyId = newStudyData [ "uuid" ] ;
166+ const openCB = ( ) => {
167+ this . _hideLoadingPage ( ) ;
168+ } ;
169+ const cancelCB = ( ) => {
170+ this . _hideLoadingPage ( ) ;
171+ const params = {
172+ url : {
173+ studyId
174+ }
175+ } ;
176+ osparc . data . Resources . fetch ( "studies" , "delete" , params ) ;
177+ } ;
178+
179+ const promises = [ ] ;
180+ // patch the name
181+ if ( newStudyData [ "name" ] !== newName ) {
182+ promises . push ( osparc . study . StudyOptions . updateName ( newStudyData , newName ) ) ;
183+ }
184+ // patch the wallet
185+ if ( walletSelection . length && walletSelection [ 0 ] [ "walletId" ] ) {
186+ const walletId = walletSelection [ 0 ] [ "walletId" ] ;
187+ promises . push ( osparc . study . StudyOptions . updateWallet ( newStudyData [ "uuid" ] , walletId ) ) ;
188+ }
189+ // patch the pricing units
190+ // the nodeIds are coming from the original template, they need to be mapped to the newStudy
191+ const workbench = newStudyData [ "workbench" ] ;
192+ const nodesIdsListed = [ ] ;
193+ Object . keys ( workbench ) . forEach ( nodeId => {
194+ const node = workbench [ nodeId ] ;
195+ if ( osparc . study . StudyPricingUnits . includeInList ( node ) ) {
196+ nodesIdsListed . push ( nodeId ) ;
197+ }
198+ } ) ;
199+ nodesPricingUnits . forEach ( ( nodePricingUnits , idx ) => {
200+ const selectedPricingUnitId = nodePricingUnits . getPricingUnits ( ) . getSelectedUnitId ( ) ;
201+ if ( selectedPricingUnitId ) {
202+ const nodeId = nodesIdsListed [ idx ] ;
203+ const pricingPlanId = nodePricingUnits . getPricingPlanId ( ) ;
204+ promises . push ( osparc . study . NodePricingUnits . patchPricingUnitSelection ( studyId , nodeId , pricingPlanId , selectedPricingUnitId ) ) ;
205+ }
206+ } ) ;
207+
208+ Promise . all ( promises )
209+ . then ( ( ) => {
210+ win . close ( ) ;
211+ const showStudyOptions = false ;
212+ this . _startStudyById ( studyId , openCB , cancelCB , showStudyOptions ) ;
213+ } ) ;
214+ } )
215+ . catch ( err => {
216+ this . _hideLoadingPage ( ) ;
217+ osparc . FlashMessenger . getInstance ( ) . logAs ( err . message , "ERROR" ) ;
218+ console . error ( err ) ;
219+ } ) ;
220+ } ) ;
221+ } else {
161222 osparc . study . Utils . createStudyFromTemplate ( templateData , this . _loadingPage )
162223 . then ( newStudyData => {
163224 const studyId = newStudyData [ "uuid" ] ;
164- const openCB = ( ) => {
165- this . _hideLoadingPage ( ) ;
166- } ;
225+ const openCB = ( ) => this . _hideLoadingPage ( ) ;
167226 const cancelCB = ( ) => {
168227 this . _hideLoadingPage ( ) ;
169228 const params = {
@@ -173,49 +232,15 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
173232 } ;
174233 osparc . data . Resources . fetch ( "studies" , "delete" , params ) ;
175234 } ;
176-
177- const promises = [ ] ;
178- // patch the name
179- if ( newStudyData [ "name" ] !== newName ) {
180- promises . push ( osparc . study . StudyOptions . updateName ( newStudyData , newName ) ) ;
181- }
182- // patch the wallet
183- if ( walletSelection . length && walletSelection [ 0 ] [ "walletId" ] ) {
184- const walletId = walletSelection [ 0 ] [ "walletId" ] ;
185- promises . push ( osparc . study . StudyOptions . updateWallet ( newStudyData [ "uuid" ] , walletId ) ) ;
186- }
187- // patch the pricing units
188- // the nodeIds are coming from the original template, they need to be mapped to the newStudy
189- const workbench = newStudyData [ "workbench" ] ;
190- const nodesIdsListed = [ ] ;
191- Object . keys ( workbench ) . forEach ( nodeId => {
192- const node = workbench [ nodeId ] ;
193- if ( osparc . study . StudyPricingUnits . includeInList ( node ) ) {
194- nodesIdsListed . push ( nodeId ) ;
195- }
196- } ) ;
197- nodesPricingUnits . forEach ( ( nodePricingUnits , idx ) => {
198- const selectedPricingUnitId = nodePricingUnits . getPricingUnits ( ) . getSelectedUnitId ( ) ;
199- if ( selectedPricingUnitId ) {
200- const nodeId = nodesIdsListed [ idx ] ;
201- const pricingPlanId = nodePricingUnits . getPricingPlanId ( ) ;
202- promises . push ( osparc . study . NodePricingUnits . patchPricingUnitSelection ( studyId , nodeId , pricingPlanId , selectedPricingUnitId ) ) ;
203- }
204- } ) ;
205-
206- Promise . all ( promises )
207- . then ( ( ) => {
208- win . close ( ) ;
209- const showStudyOptions = false ;
210- this . _startStudyById ( studyId , openCB , cancelCB , showStudyOptions ) ;
211- } ) ;
235+ const isStudyCreation = true ;
236+ this . _startStudyById ( studyId , openCB , cancelCB , isStudyCreation ) ;
212237 } )
213238 . catch ( err => {
214239 this . _hideLoadingPage ( ) ;
215240 osparc . FlashMessenger . getInstance ( ) . logAs ( err . message , "ERROR" ) ;
216241 console . error ( err ) ;
217242 } ) ;
218- } ) ;
243+ }
219244 } ,
220245
221246 // LAYOUT //
0 commit comments