@@ -118,7 +118,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
118118 osparc . data . Resources . fetch ( "studies" , "getActive" , params )
119119 . then ( studyData => {
120120 if ( studyData ) {
121- this . _startStudy ( studyData ) ;
121+ this . __startStudy ( studyData ) ;
122122 } else {
123123 osparc . store . Store . getInstance ( ) . setCurrentStudyId ( null ) ;
124124 }
@@ -129,13 +129,39 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
129129 } ,
130130
131131 __createNewStudyButton : function ( mode = "grid" ) {
132- const newStudyBtn = this . __newStudyBtn = ( mode === "grid" ) ? new osparc . dashboard . GridButtonNew ( ) : new osparc . dashboard . ListButtonNew ( ) ;
132+ const newStudyBtn = ( mode === "grid" ) ? new osparc . dashboard . GridButtonNew ( ) : new osparc . dashboard . ListButtonNew ( ) ;
133133 newStudyBtn . subscribeToFilterGroup ( "searchBarFilter" ) ;
134134 osparc . utils . Utils . setIdToWidget ( newStudyBtn , "newStudyBtn" ) ;
135- newStudyBtn . addListener ( "execute" , ( ) => this . __createStudyBtnClkd ( ) ) ;
135+ newStudyBtn . addListener ( "execute" , ( ) => this . __newStudyBtnClicked ( ) ) ;
136+ if ( this . _resourcesContainer . getMode ( ) === "list" ) {
137+ const width = this . _resourcesContainer . getBounds ( ) . width - 15 ;
138+ newStudyBtn . setWidth ( width ) ;
139+ }
140+ if ( osparc . utils . Utils . isProduct ( "tis" ) ) {
141+ this . __replaceNewStudyWithNewPlanButton ( mode ) ;
142+ }
136143 return newStudyBtn ;
137144 } ,
138145
146+ __replaceNewStudyWithNewPlanButton : function ( mode = "grid" ) {
147+ osparc . data . Resources . get ( "templates" )
148+ . then ( templates => {
149+ // replace if a "TI Planning Tool" template exists
150+ const templateData = templates . find ( t => t . name === "TI Planning Tool" ) ;
151+ if ( templateData ) {
152+ this . _resourcesContainer . remove ( this . __newStudyBtn ) ;
153+ const newPlanButton = ( mode === "grid" ) ? new osparc . dashboard . GridButtonNewPlan ( ) : new osparc . dashboard . ListButtonNewPlan ( ) ;
154+ newPlanButton . addListener ( "execute" , ( ) => this . __newPlanBtnClicked ( templateData ) ) ;
155+ this . __newStudyBtn = newPlanButton ;
156+ if ( this . _resourcesContainer . getMode ( ) === "list" ) {
157+ const width = this . _resourcesContainer . getBounds ( ) . width - 15 ;
158+ newPlanButton . setWidth ( width ) ;
159+ }
160+ this . _resourcesContainer . addAt ( newPlanButton , 0 ) ;
161+ }
162+ } ) ;
163+ } ,
164+
139165 _createLayout : function ( ) {
140166 this . _createResourcesLayout ( "study" ) ;
141167
@@ -159,7 +185,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
159185
160186 osparc . utils . Utils . setIdToWidget ( this . _resourcesContainer , "studiesList" ) ;
161187
162- const newStudyButton = this . __createNewStudyButton ( ) ;
188+ const newStudyButton = this . __newStudyBtn = this . __createNewStudyButton ( ) ;
163189 this . _resourcesContainer . add ( newStudyButton ) ;
164190
165191 const loadingStudiesBtn = this . _createLoadMoreButton ( "studiesLoading" ) ;
@@ -184,16 +210,12 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
184210 this . _resetResourcesList ( ) ;
185211
186212 const studyItems = this . _resourcesContainer . getChildren ( ) ;
187- studyItems . forEach ( ( studyItem , i ) => {
213+ studyItems . forEach ( studyItem => {
188214 if ( ! osparc . dashboard . ResourceBrowserBase . isCardButtonItem ( studyItem ) ) {
189215 if ( studyItem === this . __newStudyBtn ) {
190216 this . _resourcesContainer . remove ( studyItem ) ;
191- const newBtn = this . __createNewStudyButton ( this . _resourcesContainer . getMode ( ) ) ;
192- this . _resourcesContainer . addAt ( newBtn , i ) ;
193- if ( this . _resourcesContainer . getMode ( ) === "list" ) {
194- const width = this . _resourcesContainer . getBounds ( ) . width - 15 ;
195- newBtn . setWidth ( width ) ;
196- }
217+ const newBtn = this . __newStudyBtn = this . __createNewStudyButton ( this . _resourcesContainer . getMode ( ) ) ;
218+ this . _resourcesContainer . addAt ( newBtn , 0 ) ;
197219 }
198220
199221 if ( studyItem === this . _loadingResourcesBtn ) {
@@ -293,7 +315,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
293315 } ;
294316 osparc . data . Resources . getOne ( "studies" , params )
295317 . then ( studyData => {
296- this . _startStudy ( studyData ) ;
318+ this . __startStudy ( studyData ) ;
297319 } )
298320 . catch ( ( ) => {
299321 const msg = this . tr ( "Study unavailable or inaccessible" ) ;
@@ -343,7 +365,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
343365 } , this ) ;
344366 } ,
345367
346- __createStudyBtnClkd : function ( ) {
368+ __newStudyBtnClicked : function ( ) {
347369 this . __newStudyBtn . setValue ( false ) ;
348370 const minStudyData = osparc . data . model . Study . createMyNewStudyObject ( ) ;
349371 let title = minStudyData . name ;
@@ -360,6 +382,20 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
360382 this . __createStudy ( minStudyData , null ) ;
361383 } ,
362384
385+ __newPlanBtnClicked : function ( templateData ) {
386+ this . _showLoadingPage ( this . tr ( "Creating " ) + ( templateData . name || this . tr ( "Study" ) ) ) ;
387+ osparc . utils . Study . createStudyFromTemplate ( templateData )
388+ . then ( studyId => {
389+ this . _hideLoadingPage ( ) ;
390+ this . __getStudyAndStart ( studyId ) ;
391+ } )
392+ . catch ( err => {
393+ this . _hideLoadingPage ( ) ;
394+ osparc . component . message . FlashMessenger . getInstance ( ) . logAs ( err . message , "ERROR" ) ;
395+ console . error ( err ) ;
396+ } ) ;
397+ } ,
398+
363399 __createStudy : function ( minStudyData ) {
364400 this . _showLoadingPage ( this . tr ( "Creating " ) + ( minStudyData . name || this . tr ( "Study" ) ) ) ;
365401
@@ -369,14 +405,14 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
369405 osparc . data . Resources . fetch ( "studies" , "post" , params )
370406 . then ( studyData => {
371407 this . _hideLoadingPage ( ) ;
372- this . _startStudy ( studyData ) ;
408+ this . __startStudy ( studyData ) ;
373409 } )
374410 . catch ( err => {
375411 console . error ( err ) ;
376412 } ) ;
377413 } ,
378414
379- _startStudy : function ( studyData , pageContext ) {
415+ __startStudy : function ( studyData , pageContext ) {
380416 if ( pageContext === undefined ) {
381417 pageContext = osparc . data . model . Study . getUiMode ( studyData ) || "workbench" ;
382418 }
@@ -595,7 +631,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
595631
596632 if ( ! item . isMultiSelectionMode ( ) ) {
597633 const studyData = this . __getStudyData ( item . getUuid ( ) , false ) ;
598- this . _startStudy ( studyData ) ;
634+ this . __startStudy ( studyData ) ;
599635 }
600636 } ,
601637
0 commit comments