@@ -19,107 +19,107 @@ qx.Class.define("osparc.store.Templates", {
1919 type : "static" ,
2020
2121 statics : {
22- __templates : null ,
23- __templatesPromisesCached : null ,
2422 __tutorials : null ,
25- __tutorialsPromisesCached : null ,
23+ __tutorialsPromiseCached : null ,
2624 __hypertools : null ,
27- __hypertoolsPromisesCached : null ,
25+ __hypertoolsPromiseCached : null ,
2826
2927 __fetchTemplatesPaginated : function ( params , options ) {
28+ params [ "url" ] [ "templateType" ] = osparc . data . model . StudyUI . TEMPLATE_TYPE ;
3029 return osparc . data . Resources . fetch ( "templates" , "getPageFilteredSorted" , params , options )
31- . then ( resp => {
32- const templates = resp . data ;
33- // add them to the list
34- if ( this . __templates ) {
35- templates . forEach ( template => {
36- const index = this . __templates . findIndex ( t => t . uuid === template . uuid ) ;
37- if ( index === - 1 ) {
38- this . __templates . push ( template ) ;
39- } else {
40- this . __templates [ index ] = template ;
41- }
42- } ) ;
43- }
44- return resp ;
45- } )
4630 . catch ( err => osparc . FlashMessenger . logError ( err ) ) ;
4731 } ,
4832
4933 fetchTemplatesNonPublicPaginated : function ( params , options ) {
50- params [ "url" ] [ "templateType" ] = osparc . data . model . StudyUI . TEMPLATE_TYPE ;
5134 return this . __fetchTemplatesPaginated ( params , options ) ;
5235 } ,
5336
5437 fetchTemplatesPublicPaginated : function ( params , options ) {
55- params [ "url" ] [ "templateType" ] = osparc . data . model . StudyUI . TEMPLATE_TYPE ;
5638 return this . __fetchTemplatesPaginated ( params , options ) ;
5739 } ,
5840
59- __fetchAllTemplates : function ( ) {
60- return this . __templatesPromisesCached = osparc . data . Resources . getInstance ( ) . getAllPages ( "templates" )
61- . then ( templates => {
62- this . __templates = templates ;
63- return templates ;
41+ __fetchAllTutorials : function ( params ) {
42+ params [ "url" ] [ "templateType" ] = osparc . data . model . StudyUI . TUTORIAL_TYPE ;
43+ return this . __tutorialsPromiseCached = osparc . data . Resources . getInstance ( ) . getAllPages ( "templates" , params , "getPageFilteredSorted" )
44+ . then ( tutorials => {
45+ this . __tutorials = tutorials ;
46+ return tutorials ;
6447 } )
6548 . catch ( err => {
6649 osparc . FlashMessenger . logError ( err ) ;
6750 } )
6851 . finally ( ( ) => {
69- this . __templatesPromisesCached = null ;
52+ this . __tutorialsPromiseCached = null ;
7053 } ) ;
7154 } ,
7255
73- getTemplates : function ( useCache = true ) {
74- if ( this . __templatesPromisesCached ) {
75- // fetching templates already in progress
76- return this . __templatesPromisesCached ;
77- }
78-
79- if ( this . __templates === null ) {
80- // no templates cached, fetch them
81- return this . __fetchAllTemplates ( ) ;
82- }
83-
84- if ( useCache ) {
85- // templates already cached, return them
86- return new Promise ( resolve => resolve ( this . __templates ) ) ;
87- }
88- // templates cached but force a refresh
89- return this . __fetchAllTemplates ( ) ;
56+ __fetchAllHypertools : function ( params ) {
57+ params [ "url" ] [ "templateType" ] = osparc . data . model . StudyUI . HYPERTOOL_TYPE ;
58+ return this . __hypertoolsPromiseCached = osparc . data . Resources . getInstance ( ) . getAllPages ( "templates" , params , "getPageFilteredSorted" )
59+ . then ( hypertools => {
60+ this . __hypertools = hypertools ;
61+ return hypertools ;
62+ } )
63+ . catch ( err => {
64+ osparc . FlashMessenger . logError ( err ) ;
65+ } )
66+ . finally ( ( ) => {
67+ this . __hypertoolsPromiseCached = null ;
68+ } ) ;
9069 } ,
9170
92- getTutorials : function ( ) {
71+ getTutorials : function ( useCache = true ) {
9372 const params = {
9473 url : {
95- "templateType" : osparc . data . model . StudyUI . TUTORIAL_TYPE ,
9674 "orderBy" : JSON . stringify ( {
9775 field : "last_change_date" ,
9876 direction : "desc"
9977 } ) ,
10078 }
10179 } ;
102- return osparc . data . Resources . getInstance ( ) . getAllPages ( "templates" , params , "getPageFilteredSorted" ) ;
80+
81+ if ( this . __tutorialsPromiseCached ) {
82+ return this . __tutorialsPromiseCached ;
83+ }
84+
85+ if ( this . __tutorials === null ) {
86+ // no tutorials cached, fetch them
87+ return this . __fetchAllTutorials ( params ) ;
88+ }
89+
90+ if ( useCache ) {
91+ // tutorials already cached, return them
92+ return new Promise ( resolve => resolve ( this . __tutorials ) ) ;
93+ }
94+
95+ return this . __fetchAllTutorials ( params ) ;
10396 } ,
10497
105- getHypertools : function ( ) {
98+ getHypertools : function ( useCache = true ) {
10699 const params = {
107100 url : {
108- "templateType" : osparc . data . model . StudyUI . HYPERTOOL_TYPE ,
109101 "orderBy" : JSON . stringify ( {
110102 field : "last_change_date" ,
111103 direction : "desc"
112104 } ) ,
113105 }
114106 } ;
115- return osparc . data . Resources . getInstance ( ) . getAllPages ( "templates" , params , "getPageFilteredSorted" ) ;
116- } ,
117107
118- getTemplate : function ( templateId ) {
119- return this . getTemplates ( )
120- . then ( templates => {
121- return templates . find ( t => t . uuid === templateId ) ;
122- } ) ;
108+ if ( this . __hypertoolsPromiseCached ) {
109+ return this . __hypertoolsPromiseCached ;
110+ }
111+
112+ if ( this . __hypertools === null ) {
113+ // no hypertools cached, fetch them
114+ return this . __fetchAllHypertools ( params ) ;
115+ }
116+
117+ if ( useCache ) {
118+ // hypertools already cached, return them
119+ return new Promise ( resolve => resolve ( this . __hypertools ) ) ;
120+ }
121+
122+ return this . __fetchAllHypertools ( params ) ;
123123 } ,
124124 }
125125} ) ;
0 commit comments