@@ -119,7 +119,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
119119 const isStudyCreation = false ;
120120 this . _startStudyById ( loadStudyId , null , cancelCB , isStudyCreation ) ;
121121 } else {
122- this . __reloadFolders ( ) ;
123122 this . reloadResources ( ) ;
124123 }
125124 // "Starting..." page
@@ -151,12 +150,17 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
151150 osparc . data . Permissions . getInstance ( ) . canDo ( "studies.user.read" ) &&
152151 osparc . auth . Manager . getInstance ( ) . isLoggedIn ( )
153152 ) {
153+ this . __reloadFolders ( ) ;
154154 this . __reloadStudies ( ) ;
155155 } else {
156156 this . __resetStudiesList ( ) ;
157157 }
158158 } ,
159159
160+ reloadMoreResources : function ( ) {
161+ this . __reloadStudies ( ) ;
162+ } ,
163+
160164 __reloadWorkspaces : function ( ) {
161165 this . __setWorkspacesToList ( [ ] ) ;
162166 osparc . store . Workspaces . getInstance ( ) . fetchWorkspaces ( )
@@ -223,21 +227,11 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
223227 this . _loadingResourcesBtn . setVisibility ( "visible" ) ;
224228 this . __getNextStudiesRequest ( )
225229 . then ( resp => {
226- const urlParams = resp [ "params" ] [ "url" ] ;
227230 // Context might have been changed while waiting for the response.
228231 // The new call is on the way, therefore this response can be ignored.
229- if ( "workspaceId" in urlParams ) {
230- if (
231- urlParams . workspaceId !== this . getCurrentWorkspaceId ( ) ||
232- urlParams . folderId !== this . getCurrentFolderId ( )
233- ) {
234- return ;
235- }
236- } else if ( "text" in urlParams ) {
237- const currentFilterData = this . _searchBarFilter . getFilterData ( ) ;
238- if ( currentFilterData . text && urlParams . text !== encodeURIComponent ( currentFilterData . text ) ) {
239- return ;
240- }
232+ const contextChanged = this . __didContextChange ( resp [ "params" ] [ "url" ] ) ;
233+ if ( contextChanged ) {
234+ return ;
241235 }
242236
243237 const studies = resp [ "data" ] ;
@@ -615,26 +609,67 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
615609 } , this ) ;
616610 } ,
617611
612+ __didContextChange : function ( reqParams ) {
613+ // not needed for the comparison
614+ delete reqParams [ "type" ] ;
615+ delete reqParams [ "limit" ] ;
616+ delete reqParams [ "offset" ] ;
617+
618+ // check the entries in currentParams are the same as the reqParams
619+ const currentParams = this . __getRequestParams ( ) ;
620+ let sameContext = true ;
621+ Object . entries ( currentParams ) . forEach ( ( [ key , value ] ) => {
622+ sameContext &= key in reqParams && reqParams [ key ] === value ;
623+ } ) ;
624+ return ! sameContext ;
625+ } ,
626+
618627 __getNextPageParams : function ( ) {
619- if ( "nextRequest" in this . _resourcesContainer . getFlatList ( ) &&
620- this . _resourcesContainer . getFlatList ( ) . nextRequest !== null &&
621- osparc . utils . Utils . hasParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "offset" ) &&
622- osparc . utils . Utils . hasParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "limit" )
623- ) {
624- return {
625- offset : osparc . utils . Utils . getParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "offset" ) ,
626- limit : osparc . utils . Utils . getParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "limit" )
627- } ;
628+ if ( this . _resourcesContainer . getFlatList ( ) && this . _resourcesContainer . getFlatList ( ) . nextRequest ) {
629+ // Context might have been changed while waiting for the response.
630+ // The new call is on the way, therefore this response can be ignored.
631+ const url = new URL ( this . _resourcesContainer . getFlatList ( ) . nextRequest ) ;
632+ const urlSearchParams = new URLSearchParams ( url . search ) ;
633+ const urlParams = { } ;
634+ for ( const [ snakeKey , value ] of urlSearchParams . entries ( ) ) {
635+ const key = osparc . utils . Utils . snakeToCamel ( snakeKey ) ;
636+ urlParams [ key ] = value === "null" ? null : value ;
637+ }
638+ const contextChanged = this . __didContextChange ( urlParams ) ;
639+ if (
640+ ! contextChanged &&
641+ osparc . utils . Utils . hasParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "offset" ) &&
642+ osparc . utils . Utils . hasParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "limit" )
643+ ) {
644+ return {
645+ offset : osparc . utils . Utils . getParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "offset" ) ,
646+ limit : osparc . utils . Utils . getParamFromURL ( this . _resourcesContainer . getFlatList ( ) . nextRequest , "limit" )
647+ } ;
648+ }
628649 }
629650 return null ;
630651 } ,
631652
653+ __getRequestParams : function ( ) {
654+ const requestParams = { } ;
655+ requestParams . orderBy = JSON . stringify ( this . getOrderBy ( ) ) ;
656+
657+ const filterData = this . _searchBarFilter . getFilterData ( ) ;
658+ if ( filterData . text ) {
659+ requestParams . text = encodeURIComponent ( filterData . text ) ; // name, description and uuid
660+ return requestParams ;
661+ }
662+
663+ requestParams . workspaceId = this . getCurrentWorkspaceId ( ) ;
664+ requestParams . folderId = this . getCurrentFolderId ( ) ;
665+ return requestParams ;
666+ } ,
667+
632668 __getNextStudiesRequest : function ( ) {
633669 const params = {
634670 url : {
635671 offset : 0 ,
636672 limit : osparc . dashboard . ResourceBrowserBase . PAGINATED_STUDIES ,
637- orderBy : JSON . stringify ( this . getOrderBy ( ) ) ,
638673 }
639674 } ;
640675
@@ -647,14 +682,13 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
647682 resolveWResponse : true
648683 } ;
649684
650- const filterData = this . _searchBarFilter . getFilterData ( ) ;
651- if ( filterData . text ) {
652- params . url . text = encodeURIComponent ( filterData . text ) ; // name, description and uuid
685+ const requestParams = this . __getRequestParams ( ) ;
686+ Object . entries ( requestParams ) . forEach ( ( [ key , value ] ) => {
687+ params . url [ key ] = value ;
688+ } ) ;
689+ if ( "text" in requestParams ) {
653690 return osparc . data . Resources . fetch ( "studies" , "getPageSearch" , params , undefined , options ) ;
654691 }
655-
656- params . url . workspaceId = this . getCurrentWorkspaceId ( ) ;
657- params . url . folderId = this . getCurrentFolderId ( ) ;
658692 return osparc . data . Resources . fetch ( "studies" , "getPage" , params , undefined , options ) ;
659693 } ,
660694
0 commit comments