25
25
qx . Class . define ( "osparc.dashboard.ExploreBrowser" , {
26
26
extend : osparc . dashboard . ResourceBrowserBase ,
27
27
28
- statics : {
29
- sortTemplateList : function ( studyList ) {
30
- let sortByProperty = function ( prop ) {
31
- return function ( a , b ) {
32
- if ( prop === "lastChangeDate" ) {
33
- return new Date ( b [ prop ] ) - new Date ( a [ prop ] ) ;
34
- }
35
- if ( typeof a [ prop ] == "number" ) {
36
- return a [ prop ] - b [ prop ] ;
37
- }
38
- if ( a [ prop ] < b [ prop ] ) {
39
- return - 1 ;
40
- } else if ( a [ prop ] > b [ prop ] ) {
41
- return 1 ;
42
- }
43
- return 0 ;
44
- } ;
45
- } ;
46
- studyList . sort ( sortByProperty ( "lastChangeDate" ) ) ;
47
- }
48
- } ,
49
-
50
28
members : {
51
- __templatesContainer : null ,
52
29
__servicesContainer : null ,
53
30
__templates : null ,
54
31
__services : null ,
@@ -57,8 +34,8 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
57
34
* Function that resets the selected item
58
35
*/
59
36
resetSelection : function ( ) {
60
- if ( this . __templatesContainer ) {
61
- this . __templatesContainer . resetSelection ( ) ;
37
+ if ( this . _studiesContainer ) {
38
+ this . _studiesContainer . resetSelection ( ) ;
62
39
}
63
40
if ( this . __servicesContainer ) {
64
41
this . __servicesContainer . resetSelection ( ) ;
@@ -102,15 +79,9 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
102
79
/**
103
80
* Function that asks the backend for the list of template studies and sets it
104
81
*/
105
- reloadTemplates : function ( ) {
82
+ reloadStudies : function ( ) {
106
83
if ( osparc . data . Permissions . getInstance ( ) . canDo ( "studies.templates.read" ) ) {
107
- osparc . data . Resources . get ( "templates" )
108
- . then ( templates => {
109
- this . _resetTemplatesList ( templates ) ;
110
- } )
111
- . catch ( err => {
112
- console . error ( err ) ;
113
- } ) ;
84
+ this . _requestStudies ( true ) ;
114
85
} else {
115
86
this . _resetTemplatesList ( [ ] ) ;
116
87
}
@@ -137,27 +108,27 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
137
108
138
109
// overriden
139
110
_initResources : function ( ) {
140
- this . _showLoadingPage ( this . tr ( "Discovering Templates and Apps " ) ) ;
111
+ this . _showLoadingPage ( this . tr ( "Starting... " ) ) ;
141
112
142
113
this . __templates = [ ] ;
143
114
this . __services = [ ] ;
144
- const servicesTags = this . __getTags ( ) ;
115
+ const resourcePromises = [ ] ;
145
116
const store = osparc . store . Store . getInstance ( ) ;
146
- const servicesPromise = store . getServicesDAGs ( true ) ;
117
+ resourcePromises . push ( store . getServicesDAGs ( true ) ) ;
118
+ if ( osparc . data . Permissions . getInstance ( ) . canDo ( "study.tag" ) ) {
119
+ resourcePromises . push ( osparc . data . Resources . get ( "tags" ) ) ;
120
+ }
147
121
148
- Promise . all ( [
149
- servicesTags ,
150
- servicesPromise
151
- ] )
122
+ Promise . all ( resourcePromises )
152
123
. then ( ( ) => {
153
- this . _hideLoadingPage ( ) ;
154
124
this . __createResourcesLayout ( ) ;
155
125
this . __reloadResources ( ) ;
126
+ this . _hideLoadingPage ( ) ;
156
127
} ) ;
157
128
} ,
158
129
159
130
__reloadResources : function ( ) {
160
- this . reloadTemplates ( ) ;
131
+ this . reloadStudies ( ) ;
161
132
this . __reloadServices ( ) ;
162
133
} ,
163
134
@@ -168,18 +139,6 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
168
139
} ) ;
169
140
} ,
170
141
171
- __getTags : function ( ) {
172
- return new Promise ( ( resolve , reject ) => {
173
- if ( osparc . data . Permissions . getInstance ( ) . canDo ( "study.tag" ) ) {
174
- osparc . data . Resources . get ( "tags" )
175
- . catch ( console . error )
176
- . finally ( ( ) => resolve ( ) ) ;
177
- } else {
178
- resolve ( ) ;
179
- }
180
- } ) ;
181
- } ,
182
-
183
142
__createResourcesLayout : function ( ) {
184
143
const exploreBrowserLayout = new qx . ui . container . Composite ( new qx . ui . layout . VBox ( 16 ) ) ;
185
144
@@ -194,6 +153,10 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
194
153
this . _add ( scrollStudies , {
195
154
flex : 1
196
155
} ) ;
156
+
157
+ scrollStudies . getChildControl ( "pane" ) . addListener ( "scrollY" , ( ) => {
158
+ this . _moreStudiesRequired ( ) ;
159
+ } , this ) ;
197
160
} ,
198
161
199
162
__createButtonsLayout : function ( title , content ) {
@@ -207,9 +170,17 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
207
170
} ,
208
171
209
172
__createTemplatesLayout : function ( ) {
210
- const templateStudyContainer = this . __templatesContainer = this . __createResourceListLayout ( ) ;
173
+ const templateStudyContainer = this . _studiesContainer = this . __createResourceListLayout ( ) ;
211
174
osparc . utils . Utils . setIdToWidget ( templateStudyContainer , "templateStudiesList" ) ;
212
175
const tempStudyLayout = this . __createButtonsLayout ( this . tr ( "Templates" ) , templateStudyContainer ) ;
176
+
177
+ const loadingTemplatesBtn = this . _loadingStudiesBtn = new osparc . dashboard . StudyBrowserButtonLoadMore ( ) ;
178
+ templateStudyContainer . add ( loadingTemplatesBtn ) ;
179
+
180
+ templateStudyContainer . addListener ( "changeVisibility" , e => {
181
+ this . _moreStudiesRequired ( ) ;
182
+ } , this ) ;
183
+
213
184
return tempStudyLayout ;
214
185
} ,
215
186
@@ -345,8 +316,8 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
345
316
346
317
_resetTemplatesList : function ( tempStudyList ) {
347
318
this . __templates = tempStudyList ;
348
- this . __templatesContainer . removeAll ( ) ;
349
- this . self ( ) . sortTemplateList ( tempStudyList ) ;
319
+ this . _studiesContainer . removeAll ( ) ;
320
+ osparc . dashboard . ResourceBrowserBase . sortStudyList ( tempStudyList ) ;
350
321
tempStudyList . forEach ( tempStudy => {
351
322
tempStudy [ "resourceType" ] = "template" ;
352
323
const templateItem = this . __createStudyItem ( tempStudy ) ;
@@ -355,8 +326,32 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
355
326
updatedTemplateData [ "resourceType" ] = "template" ;
356
327
this . _resetTemplateItem ( updatedTemplateData ) ;
357
328
} , this ) ;
358
- this . __templatesContainer . add ( templateItem ) ;
329
+ this . _studiesContainer . add ( templateItem ) ;
330
+ } ) ;
331
+ osparc . component . filter . UIFilterController . dispatch ( "sideSearchFilter" ) ;
332
+ } ,
333
+
334
+ _addStudiesToList : function ( newTemplatesList ) {
335
+ osparc . dashboard . ResourceBrowserBase . sortStudyList ( newTemplatesList ) ;
336
+ const templatesList = this . _studiesContainer . getChildren ( ) ;
337
+ newTemplatesList . forEach ( template => {
338
+ if ( this . __templates . indexOf ( template ) === - 1 ) {
339
+ this . __templates . push ( template ) ;
340
+ }
341
+
342
+ template [ "resourceType" ] = "template" ;
343
+ const idx = templatesList . findIndex ( card => card instanceof osparc . dashboard . StudyBrowserButtonItem && card . getUuid ( ) === template [ "uuid" ] ) ;
344
+ if ( idx !== - 1 ) {
345
+ return ;
346
+ }
347
+ const templateItem = this . __createStudyItem ( template ) ;
348
+ this . _studiesContainer . add ( templateItem ) ;
359
349
} ) ;
350
+ osparc . dashboard . ResourceBrowserBase . sortStudyList ( templatesList . filter ( card => card instanceof osparc . dashboard . StudyBrowserButtonItem ) ) ;
351
+ const idx = templatesList . findIndex ( card => card instanceof osparc . dashboard . StudyBrowserButtonLoadMore ) ;
352
+ if ( idx !== - 1 ) {
353
+ templatesList . push ( templatesList . splice ( idx , 1 ) [ 0 ] ) ;
354
+ }
360
355
osparc . component . filter . UIFilterController . dispatch ( "sideSearchFilter" ) ;
361
356
} ,
362
357
@@ -388,7 +383,7 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
388
383
} ,
389
384
390
385
__removeFromStudyList : function ( studyId ) {
391
- const studyContainer = this . __templatesContainer ;
386
+ const studyContainer = this . _studiesContainer ;
392
387
const items = studyContainer . getChildren ( ) ;
393
388
for ( let i = 0 ; i < items . length ; i ++ ) {
394
389
const item = items [ i ] ;
0 commit comments