@@ -169,80 +169,83 @@ qx.Class.define("osparc.study.Utils", {
169169
170170 createStudyFromTemplate : function ( templateData , loadingPage , contextProps = { } ) {
171171 return new Promise ( ( resolve , reject ) => {
172- const inaccessibleServices = osparc . store . Services . getInaccessibleServices ( templateData [ "workbench" ] ) ;
173- if ( inaccessibleServices . length ) {
174- const msg = osparc . store . Services . getInaccessibleServicesMsg ( inaccessibleServices , templateData [ "workbench" ] ) ;
175- reject ( {
176- message : msg
172+ osparc . store . Services . getStudyServicesMetadata ( templateData )
173+ . finally ( ( ) => {
174+ const inaccessibleServices = osparc . store . Services . getInaccessibleServices ( templateData [ "workbench" ] ) ;
175+ if ( inaccessibleServices . length ) {
176+ const msg = osparc . store . Services . getInaccessibleServicesMsg ( inaccessibleServices , templateData [ "workbench" ] ) ;
177+ reject ( {
178+ message : msg
179+ } ) ;
180+ return ;
181+ }
182+ // context props, otherwise Study will be created in the root folder of my personal workspace
183+ const minStudyData = Object . assign ( osparc . data . model . Study . createMinStudyObject ( ) , contextProps ) ;
184+ minStudyData [ "name" ] = templateData [ "name" ] ;
185+ minStudyData [ "description" ] = templateData [ "description" ] ;
186+ minStudyData [ "thumbnail" ] = templateData [ "thumbnail" ] ;
187+ const params = {
188+ url : {
189+ templateId : templateData [ "uuid" ]
190+ } ,
191+ data : minStudyData
192+ } ;
193+ const options = {
194+ pollTask : true
195+ } ;
196+ const fetchPromise = osparc . data . Resources . fetch ( "studies" , "postNewStudyFromTemplate" , params , options ) ;
197+ const pollTasks = osparc . data . PollTasks . getInstance ( ) ;
198+ const interval = 1000 ;
199+ pollTasks . createPollingTask ( fetchPromise , interval )
200+ . then ( task => {
201+ const title = qx . locale . Manager . tr ( "CREATING " ) + osparc . product . Utils . getStudyAlias ( { allUpperCase : true } ) + " ..." ;
202+ const progressSequence = new osparc . widget . ProgressSequence ( title ) . set ( {
203+ minHeight : 180 // four tasks
204+ } ) ;
205+ progressSequence . addOverallProgressBar ( ) ;
206+ loadingPage . clearMessages ( ) ;
207+ loadingPage . addWidgetToMessages ( progressSequence ) ;
208+ task . addListener ( "updateReceived" , e => {
209+ const updateData = e . getData ( ) ;
210+ if ( "task_progress" in updateData && loadingPage ) {
211+ const progress = updateData [ "task_progress" ] ;
212+ const message = progress [ "message" ] ;
213+ const percent = progress [ "percent" ] ? parseFloat ( progress [ "percent" ] . toFixed ( 3 ) ) : progress [ "percent" ] ;
214+ progressSequence . setOverallProgress ( percent ) ;
215+ const existingTask = progressSequence . getTask ( message ) ;
216+ if ( existingTask ) {
217+ // update task
218+ osparc . widget . ProgressSequence . updateTaskProgress ( existingTask , {
219+ value : percent ,
220+ progressLabel : parseFloat ( ( percent * 100 ) . toFixed ( 2 ) ) + "%"
221+ } ) ;
222+ } else {
223+ // new task
224+ // all the previous steps to 100%
225+ progressSequence . getTasks ( ) . forEach ( tsk => osparc . widget . ProgressSequence . updateTaskProgress ( tsk , {
226+ value : 1 ,
227+ progressLabel : "100%"
228+ } ) ) ;
229+ // and move to the next new task
230+ const subTask = progressSequence . addNewTask ( message ) ;
231+ osparc . widget . ProgressSequence . updateTaskProgress ( subTask , {
232+ value : percent ,
233+ progressLabel : "0%"
234+ } ) ;
235+ }
236+ }
237+ } , this ) ;
238+ task . addListener ( "resultReceived" , e => {
239+ const studyData = e . getData ( ) ;
240+ resolve ( studyData ) ;
241+ } , this ) ;
242+ task . addListener ( "pollingError" , e => {
243+ const err = e . getData ( ) ;
244+ reject ( err ) ;
245+ } , this ) ;
246+ } )
247+ . catch ( err => reject ( err ) ) ;
177248 } ) ;
178- return ;
179- }
180- // context props, otherwise Study will be created in the root folder of my personal workspace
181- const minStudyData = Object . assign ( osparc . data . model . Study . createMinStudyObject ( ) , contextProps ) ;
182- minStudyData [ "name" ] = templateData [ "name" ] ;
183- minStudyData [ "description" ] = templateData [ "description" ] ;
184- minStudyData [ "thumbnail" ] = templateData [ "thumbnail" ] ;
185- const params = {
186- url : {
187- templateId : templateData [ "uuid" ]
188- } ,
189- data : minStudyData
190- } ;
191- const options = {
192- pollTask : true
193- } ;
194- const fetchPromise = osparc . data . Resources . fetch ( "studies" , "postNewStudyFromTemplate" , params , options ) ;
195- const pollTasks = osparc . data . PollTasks . getInstance ( ) ;
196- const interval = 1000 ;
197- pollTasks . createPollingTask ( fetchPromise , interval )
198- . then ( task => {
199- const title = qx . locale . Manager . tr ( "CREATING " ) + osparc . product . Utils . getStudyAlias ( { allUpperCase : true } ) + " ..." ;
200- const progressSequence = new osparc . widget . ProgressSequence ( title ) . set ( {
201- minHeight : 180 // four tasks
202- } ) ;
203- progressSequence . addOverallProgressBar ( ) ;
204- loadingPage . clearMessages ( ) ;
205- loadingPage . addWidgetToMessages ( progressSequence ) ;
206- task . addListener ( "updateReceived" , e => {
207- const updateData = e . getData ( ) ;
208- if ( "task_progress" in updateData && loadingPage ) {
209- const progress = updateData [ "task_progress" ] ;
210- const message = progress [ "message" ] ;
211- const percent = progress [ "percent" ] ? parseFloat ( progress [ "percent" ] . toFixed ( 3 ) ) : progress [ "percent" ] ;
212- progressSequence . setOverallProgress ( percent ) ;
213- const existingTask = progressSequence . getTask ( message ) ;
214- if ( existingTask ) {
215- // update task
216- osparc . widget . ProgressSequence . updateTaskProgress ( existingTask , {
217- value : percent ,
218- progressLabel : parseFloat ( ( percent * 100 ) . toFixed ( 2 ) ) + "%"
219- } ) ;
220- } else {
221- // new task
222- // all the previous steps to 100%
223- progressSequence . getTasks ( ) . forEach ( tsk => osparc . widget . ProgressSequence . updateTaskProgress ( tsk , {
224- value : 1 ,
225- progressLabel : "100%"
226- } ) ) ;
227- // and move to the next new task
228- const subTask = progressSequence . addNewTask ( message ) ;
229- osparc . widget . ProgressSequence . updateTaskProgress ( subTask , {
230- value : percent ,
231- progressLabel : "0%"
232- } ) ;
233- }
234- }
235- } , this ) ;
236- task . addListener ( "resultReceived" , e => {
237- const studyData = e . getData ( ) ;
238- resolve ( studyData ) ;
239- } , this ) ;
240- task . addListener ( "pollingError" , e => {
241- const err = e . getData ( ) ;
242- reject ( err ) ;
243- } , this ) ;
244- } )
245- . catch ( err => reject ( err ) ) ;
246249 } ) ;
247250 } ,
248251
0 commit comments