@@ -84,40 +84,29 @@ qx.Class.define("osparc.store.Data", {
8484 return null ;
8585 } ,
8686
87- getDatasetsByLocation : function ( locationId ) {
87+ getDatasetsByLocation : async function ( locationId ) {
8888 const data = {
8989 location : locationId ,
9090 items : [ ]
9191 } ;
92- return new Promise ( ( resolve , reject ) => {
93- if ( locationId === 1 && ! osparc . data . Permissions . getInstance ( ) . canDo ( "storage.datcore.read" ) ) {
94- reject ( data ) ;
95- }
92+ if ( locationId === 1 && ! osparc . data . Permissions . getInstance ( ) . canDo ( "storage.datcore.read" ) ) {
93+ return data ;
94+ }
9695
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- } ) ;
96+ const cachedData = this . getDatasetsByLocationCached ( locationId ) ;
97+ if ( cachedData ) {
98+ return cachedData ;
99+ }
100+
101+ try {
102+ const allItems = await this . __getAllItems ( locationId ) ;
103+ this . __datasetsByLocationCached [ locationId ] = allItems ;
104+ data [ "items" ] = allItems ;
105+ return data ;
106+ } catch ( err ) {
107+ console . error ( err ) ;
108+ return data ;
109+ }
121110 } ,
122111
123112 getItemsByLocationAndPath : async function ( locationId , path ) {
@@ -141,23 +130,35 @@ qx.Class.define("osparc.store.Data", {
141130 osparc . FlashMessenger . logAs ( msg , "WARNING" ) ;
142131 return allItems ;
143132 }
133+
144134 const params = {
145135 url : {
146136 locationId,
147- path,
148137 }
149138 } ;
139+ if ( path ) {
140+ params [ "url" ] [ "path" ] = path ;
141+ }
150142 if ( cursor ) {
151143 params [ "url" ] [ "cursor" ] = cursor ;
152144 }
153- const pagResp = await osparc . data . Resources . fetch ( "storagePaths" , cursor ? "getPathsPage" : "getPaths" , params ) ;
154- if ( pagResp [ "items" ] ) {
155- allItems . push ( ...pagResp [ "items" ] ) ;
145+ let pagResp = null ;
146+ if ( path ) {
147+ pagResp = await osparc . data . Resources . fetch ( "storagePaths" , cursor ? "getPathsPage" : "getPaths" , params ) ;
148+ } else {
149+ pagResp = await osparc . data . Resources . fetch ( "storagePaths" , cursor ? "getDatasetsPage" : "getDatasets" , params ) ;
156150 }
151+
157152 let nextCursor = null ;
158- if ( pagResp [ "next_page" ] ) {
159- nextCursor = pagResp [ "next_page" ] ;
153+ if ( pagResp ) {
154+ if ( pagResp [ "items" ] ) {
155+ allItems . push ( ...pagResp [ "items" ] ) ;
156+ }
157+ if ( pagResp [ "next_page" ] ) {
158+ nextCursor = pagResp [ "next_page" ] ;
159+ }
160160 }
161+
161162 if ( nextCursor ) {
162163 return this . __getAllItems ( locationId , path , nextCursor , allItems ) ;
163164 }
0 commit comments