@@ -171,17 +171,30 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
171171 if (
172172 ! osparc . auth . Manager . getInstance ( ) . isLoggedIn ( ) ||
173173 ! osparc . utils . DisabledPlugins . isFoldersEnabled ( ) ||
174- this . getCurrentContext ( ) !== "studiesAndFolders " ||
174+ this . getCurrentContext ( ) === "workspaces " ||
175175 this . __loadingFolders
176176 ) {
177177 return ;
178178 }
179179
180- const workspaceId = this . getCurrentWorkspaceId ( ) ;
181- const folderId = this . getCurrentFolderId ( ) ;
182180 this . __loadingFolders = true ;
181+ let request = null ;
182+ switch ( this . getCurrentContext ( ) ) {
183+ case "search" : {
184+ const filterData = this . _searchBarFilter . getFilterData ( ) ;
185+ const text = filterData . text ? encodeURIComponent ( filterData . text ) : "" ; // name, description and uuid
186+ request = osparc . store . Folders . getInstance ( ) . searchFolders ( text , this . getOrderBy ( ) ) ;
187+ break ;
188+ }
189+ case "studiesAndFolders" : {
190+ const workspaceId = this . getCurrentWorkspaceId ( ) ;
191+ const folderId = this . getCurrentFolderId ( ) ;
192+ request = osparc . store . Folders . getInstance ( ) . fetchFolders ( folderId , workspaceId , this . getOrderBy ( ) ) ;
193+ break ;
194+ }
195+ }
183196 this . __setFoldersToList ( [ ] ) ;
184- osparc . store . Folders . getInstance ( ) . fetchFolders ( folderId , workspaceId , this . getOrderBy ( ) )
197+ request
185198 . then ( folders => {
186199 this . __setFoldersToList ( folders ) ;
187200 } )
@@ -384,7 +397,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
384397 } ,
385398
386399 _workspaceSelected : function ( workspaceId ) {
387- this . __changeContext ( "studiesAndFolders" , workspaceId , null ) ;
400+ this . _changeContext ( "studiesAndFolders" , workspaceId , null ) ;
388401 } ,
389402
390403 _workspaceUpdated : function ( ) {
@@ -444,7 +457,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
444457 } ,
445458
446459 _folderSelected : function ( folderId ) {
447- this . __changeContext ( "studiesAndFolders" , this . getCurrentWorkspaceId ( ) , folderId ) ;
460+ this . _changeContext ( "studiesAndFolders" , this . getCurrentWorkspaceId ( ) , folderId ) ;
448461 } ,
449462
450463 _folderUpdated : function ( ) {
@@ -653,17 +666,23 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
653666 const requestParams = { } ;
654667 requestParams . orderBy = JSON . stringify ( this . getOrderBy ( ) ) ;
655668
656- const filterData = this . _searchBarFilter . getFilterData ( ) ;
657- // Use the ``search`` functionality only if the user types some text
658- // tags should only be used to filter the current context (search context ot workspace/folder context)
659- if ( filterData . text ) {
660- requestParams . text = filterData . text ? encodeURIComponent ( filterData . text ) : "" ; // name, description and uuid
661- requestParams [ "tagIds" ] = filterData . tags . length ? filterData . tags . join ( "," ) : "" ;
662- return requestParams ;
669+ switch ( this . getCurrentContext ( ) ) {
670+ case "studiesAndFolders" :
671+ requestParams . workspaceId = this . getCurrentWorkspaceId ( ) ;
672+ requestParams . folderId = this . getCurrentFolderId ( ) ;
673+ break ;
674+ case "search" : {
675+ // Use the ``search`` functionality only if the user types some text
676+ // tags should only be used to filter the current context (search context ot workspace/folder context)
677+ const filterData = this . _searchBarFilter . getFilterData ( ) ;
678+ if ( filterData . text ) {
679+ requestParams . text = filterData . text ? encodeURIComponent ( filterData . text ) : "" ; // name, description and uuid
680+ requestParams [ "tagIds" ] = filterData . tags . length ? filterData . tags . join ( "," ) : "" ;
681+ }
682+ break ;
683+ }
663684 }
664685
665- requestParams . workspaceId = this . getCurrentWorkspaceId ( ) ;
666- requestParams . folderId = this . getCurrentFolderId ( ) ;
667686 return requestParams ;
668687 } ,
669688
@@ -688,10 +707,16 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
688707 resolveWResponse : true
689708 } ;
690709
691- if ( "text" in requestParams ) {
692- return osparc . data . Resources . fetch ( "studies" , "getPageSearch" , params , options ) ;
710+ let request = null ;
711+ switch ( this . getCurrentContext ( ) ) {
712+ case "search" :
713+ request = osparc . data . Resources . fetch ( "studies" , "getPageSearch" , params , options ) ;
714+ break ;
715+ case "studiesAndFolders" :
716+ request = osparc . data . Resources . fetch ( "studies" , "getPage" , params , options ) ;
717+ break ;
693718 }
694- return osparc . data . Resources . fetch ( "studies" , "getPage" , params , options ) ;
719+ return request ;
695720 } ,
696721
697722 invalidateStudies : function ( ) {
@@ -886,10 +911,11 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
886911 } ) ;
887912
888913 this . _resourcesContainer . addListener ( "changeSelection" , e => {
914+ const currentContext = this . getCurrentContext ( ) ;
889915 const selection = e . getData ( ) ;
890916
891917 studiesMoveButton . set ( {
892- visibility : selection . length ? "visible" : "excluded" ,
918+ visibility : selection . length && currentContext === "studiesAndFolders" ? "visible" : "excluded" ,
893919 label : selection . length > 1 ? this . tr ( "Move selected" ) + " (" + selection . length + ")" : this . tr ( "Move" )
894920 } ) ;
895921
@@ -910,35 +936,35 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
910936 header . addListener ( "locationChanged" , ( ) => {
911937 const workspaceId = header . getCurrentWorkspaceId ( ) ;
912938 const folderId = header . getCurrentFolderId ( ) ;
913- this . __changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
939+ this . _changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
914940 } , this ) ;
915941
916942 const workspacesAndFoldersTree = this . _resourceFilter . getWorkspacesAndFoldersTree ( ) ;
917943 workspacesAndFoldersTree . addListener ( "locationChanged" , e => {
918944 const context = e . getData ( ) ;
919945 const workspaceId = context [ "workspaceId" ] ;
920946 if ( workspaceId === - 1 ) {
921- this . __changeContext ( "workspaces" ) ;
947+ this . _changeContext ( "workspaces" ) ;
922948 } else {
923949 const folderId = context [ "folderId" ] ;
924- this . __changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
950+ this . _changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
925951 }
926952 } , this ) ;
927953
928954 this . _searchBarFilter . addListener ( "filterChanged" , e => {
929955 const filterData = e . getData ( ) ;
930956 if ( filterData . text ) {
931- this . __changeContext ( "search" ) ;
957+ this . _changeContext ( "search" ) ;
932958 } else {
933959 const workspaceId = this . getCurrentWorkspaceId ( ) ;
934960 const folderId = this . getCurrentFolderId ( ) ;
935- this . __changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
961+ this . _changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
936962 }
937963 } ) ;
938964 }
939965 } ,
940966
941- __changeContext : function ( context , workspaceId = null , folderId = null ) {
967+ _changeContext : function ( context , workspaceId = null , folderId = null ) {
942968 if ( osparc . utils . DisabledPlugins . isFoldersEnabled ( ) ) {
943969 if (
944970 context !== "search" && // reload studies for a new search
@@ -950,6 +976,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
950976 return ;
951977 }
952978
979+ osparc . store . Store . getInstance ( ) . setStudyBrowserContext ( context ) ;
953980 this . set ( {
954981 currentContext : context ,
955982 currentWorkspaceId : workspaceId ,
@@ -962,7 +989,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
962989 this . _resourcesContainer . setResourcesToList ( [ ] ) ;
963990
964991 if ( context === "search" ) {
965- this . __setFoldersToList ( [ ] ) ;
992+ this . __reloadFolders ( ) ;
966993 this . __reloadStudies ( ) ;
967994 } else if ( context === "workspaces" ) {
968995 this . _searchBarFilter . resetFilters ( ) ;
@@ -1342,7 +1369,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
13421369 __getOpenLocationMenuButton : function ( studyData ) {
13431370 const openLocationButton = new qx . ui . menu . Button ( this . tr ( "Open location" ) , "@FontAwesome5Solid/external-link-alt/12" ) ;
13441371 openLocationButton . addListener ( "execute" , ( ) => {
1345- this . __changeContext ( "studiesAndFolders" , studyData [ "workspaceId" ] , studyData [ "folderId" ] ) ;
1372+ this . _changeContext ( "studiesAndFolders" , studyData [ "workspaceId" ] , studyData [ "folderId" ] ) ;
13461373 } , this ) ;
13471374 return openLocationButton ;
13481375 } ,
0 commit comments