@@ -35,6 +35,45 @@ qx.Class.define("osparc.store.Data", {
35
35
"fileCopied" : "qx.event.type.Data" ,
36
36
} ,
37
37
38
+ statics : {
39
+ getAllItems : async function ( locationId , path , cursor , allItems = [ ] ) {
40
+ if ( allItems . length >= 10000 ) {
41
+ const msg = qx . locale . Manager . tr ( "Oops... more than 10.000 items to be listed here. Maybe it's time to make a folder :)." ) ;
42
+ osparc . FlashMessenger . logAs ( msg , "WARNING" ) ;
43
+ return allItems ;
44
+ }
45
+
46
+ const params = {
47
+ url : {
48
+ locationId,
49
+ path : path || null ,
50
+ cursor : cursor || null ,
51
+ }
52
+ } ;
53
+ let pagResp = null ;
54
+ if ( path ) {
55
+ pagResp = await osparc . data . Resources . fetch ( "storagePaths" , cursor ? "getPathsPage" : "getPaths" , params ) ;
56
+ } else {
57
+ pagResp = await osparc . data . Resources . fetch ( "storagePaths" , cursor ? "getDatasetsPage" : "getDatasets" , params ) ;
58
+ }
59
+
60
+ let nextCursor = null ;
61
+ if ( pagResp ) {
62
+ if ( pagResp [ "items" ] ) {
63
+ allItems . push ( ...pagResp [ "items" ] ) ;
64
+ }
65
+ if ( pagResp [ "next_page" ] ) {
66
+ nextCursor = pagResp [ "next_page" ] ;
67
+ }
68
+ }
69
+
70
+ if ( nextCursor ) {
71
+ return this . getAllItems ( locationId , path , nextCursor , allItems ) ;
72
+ }
73
+ return allItems ;
74
+ } ,
75
+ } ,
76
+
38
77
members : {
39
78
__locationsCached : null ,
40
79
__datasetsByLocationCached : null ,
@@ -84,68 +123,44 @@ qx.Class.define("osparc.store.Data", {
84
123
return null ;
85
124
} ,
86
125
87
- getDatasetsByLocation : function ( locationId ) {
126
+ getDatasetsByLocation : async function ( locationId ) {
88
127
const data = {
89
128
location : locationId ,
90
129
items : [ ]
91
130
} ;
92
- return new Promise ( ( resolve , reject ) => {
93
- if ( locationId === 1 && ! osparc . data . Permissions . getInstance ( ) . canDo ( "storage.datcore.read" ) ) {
94
- reject ( data ) ;
95
- }
131
+ if ( locationId === 1 && ! osparc . data . Permissions . getInstance ( ) . canDo ( "storage.datcore.read" ) ) {
132
+ return data ;
133
+ }
96
134
97
- const cachedData = this . getDatasetsByLocationCached ( locationId ) ;
98
- if ( cachedData ) {
99
- resolve ( cachedData ) ;
100
- } else {
101
- const params = {
102
- url : {
103
- locationId
104
- }
105
- } ;
106
- osparc . data . Resources . fetch ( "storagePaths" , "getDatasets" , params )
107
- . then ( pagResp => {
108
- if ( pagResp [ "items" ] && pagResp [ "items" ] . length > 0 ) {
109
- data . items = pagResp [ "items" ] ;
110
- }
111
- // Add it to cache
112
- this . __datasetsByLocationCached [ locationId ] = data . items ;
113
- resolve ( data ) ;
114
- } )
115
- . catch ( err => {
116
- console . error ( err ) ;
117
- reject ( data ) ;
118
- } ) ;
119
- }
120
- } ) ;
135
+ const cachedData = this . getDatasetsByLocationCached ( locationId ) ;
136
+ if ( cachedData ) {
137
+ return cachedData ;
138
+ }
139
+
140
+ try {
141
+ const allItems = await this . self ( ) . getAllItems ( locationId ) ;
142
+ this . __datasetsByLocationCached [ locationId ] = allItems ;
143
+ data [ "items" ] = allItems ;
144
+ return data ;
145
+ } catch ( err ) {
146
+ console . error ( err ) ;
147
+ return data ;
148
+ }
121
149
} ,
122
150
123
- getItemsByLocationAndPath : function ( locationId , path ) {
124
- return new Promise ( ( resolve , reject ) => {
125
- // Get list of file meta data
126
- if ( locationId === 1 && ! osparc . data . Permissions . getInstance ( ) . canDo ( "storage.datcore.read" ) ) {
127
- reject ( [ ] ) ;
128
- }
151
+ getItemsByLocationAndPath : async function ( locationId , path ) {
152
+ // Get list of file meta data
153
+ if ( locationId === 1 && ! osparc . data . Permissions . getInstance ( ) . canDo ( "storage.datcore.read" ) ) {
154
+ return [ ] ;
155
+ }
129
156
130
- const params = {
131
- url : {
132
- locationId,
133
- path,
134
- }
135
- } ;
136
- osparc . data . Resources . fetch ( "storagePaths" , "getPaths" , params )
137
- . then ( pagResp => {
138
- if ( pagResp [ "items" ] && pagResp [ "items" ] . length > 0 ) {
139
- resolve ( pagResp [ "items" ] ) ;
140
- } else {
141
- resolve ( [ ] ) ;
142
- }
143
- } )
144
- . catch ( err => {
145
- console . error ( err ) ;
146
- reject ( [ ] ) ;
147
- } ) ;
148
- } ) ;
157
+ try {
158
+ const allItems = await this . self ( ) . getAllItems ( locationId , path ) ;
159
+ return allItems ;
160
+ } catch ( err ) {
161
+ console . error ( err ) ;
162
+ return [ ] ;
163
+ }
149
164
} ,
150
165
151
166
getPresignedLink : function ( download = true , locationId , fileUuid , fileSize ) {
0 commit comments