@@ -49,6 +49,13 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
4949 } ,
5050
5151 properties : {
52+ currentContext : {
53+ check : [ "studiesAndFolders" , "workspaces" , "search" ] ,
54+ nullable : false ,
55+ init : "studiesAndFolders" ,
56+ event : "changeCurrentContext"
57+ } ,
58+
5259 currentWorkspaceId : {
5360 check : "Number" ,
5461 nullable : true ,
@@ -101,7 +108,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
101108
102109 members : {
103110 __dontShowTutorial : null ,
104- __workspaceHeader : null ,
111+ __header : null ,
105112 __workspacesList : null ,
106113 __foldersList : null ,
107114 __loadingFolders : null ,
@@ -174,17 +181,16 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
174181 if (
175182 ! osparc . auth . Manager . getInstance ( ) . isLoggedIn ( ) ||
176183 ! osparc . utils . DisabledPlugins . isFoldersEnabled ( ) ||
177- this . __loadingFolders ) {
178- return ;
179- }
180- const workspaceId = this . getCurrentWorkspaceId ( ) ;
181- if ( workspaceId === - 1 || workspaceId === - 2 ) {
184+ this . getCurrentContext ( ) !== "studiesAndFolders" ||
185+ this . __loadingFolders
186+ ) {
182187 return ;
183188 }
184189
190+ const workspaceId = this . getCurrentWorkspaceId ( ) ;
191+ const folderId = this . getCurrentFolderId ( ) ;
185192 this . __loadingFolders = true ;
186193 this . __setFoldersToList ( [ ] ) ;
187- const folderId = this . getCurrentFolderId ( ) ;
188194 osparc . store . Folders . getInstance ( ) . fetchFolders ( folderId , workspaceId , this . getOrderBy ( ) )
189195 . then ( folders => {
190196 this . __setFoldersToList ( folders ) ;
@@ -194,10 +200,9 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
194200 } ,
195201
196202 __reloadStudies : function ( ) {
197- const workspaceId = this . getCurrentWorkspaceId ( ) ;
198203 if (
199204 ! osparc . auth . Manager . getInstance ( ) . isLoggedIn ( ) ||
200- workspaceId === - 1 || // listing workspaces
205+ this . getCurrentContext ( ) === "workspaces" ||
201206 this . _loadingResourcesBtn . isFetching ( )
202207 ) {
203208 return ;
@@ -388,7 +393,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
388393 } ,
389394
390395 _workspaceSelected : function ( workspaceId ) {
391- this . __changeContext ( workspaceId , null ) ;
396+ this . __changeContext ( "studiesAndFolders" , workspaceId , null ) ;
392397 } ,
393398
394399 _workspaceUpdated : function ( ) {
@@ -418,7 +423,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
418423 __addNewFolderButton : function ( ) {
419424 const currentWorkspaceId = this . getCurrentWorkspaceId ( ) ;
420425 if ( currentWorkspaceId ) {
421- if ( currentWorkspaceId === - 1 || currentWorkspaceId === - 2 ) {
426+ if ( this . getCurrentContext ( ) !== "studiesAndFolders" ) {
422427 return ;
423428 }
424429 const currentWorkspace = osparc . store . Workspaces . getInstance ( ) . getWorkspace ( this . getCurrentWorkspaceId ( ) ) ;
@@ -448,7 +453,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
448453 } ,
449454
450455 _folderSelected : function ( folderId ) {
451- this . __changeContext ( this . getCurrentWorkspaceId ( ) , folderId ) ;
456+ this . __changeContext ( "studiesAndFolders" , this . getCurrentWorkspaceId ( ) , folderId ) ;
452457 } ,
453458
454459 _folderUpdated : function ( ) {
@@ -705,11 +710,11 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
705710 } ,
706711
707712 __addNewStudyButtons : function ( ) {
713+ if ( this . getCurrentContext ( ) !== "studiesAndFolders" ) {
714+ return ;
715+ }
708716 const currentWorkspaceId = this . getCurrentWorkspaceId ( ) ;
709717 if ( currentWorkspaceId ) {
710- if ( currentWorkspaceId === - 2 ) {
711- return ;
712- }
713718 const currentWorkspace = osparc . store . Workspaces . getInstance ( ) . getWorkspace ( currentWorkspaceId ) ;
714719 if ( currentWorkspace && ! currentWorkspace . getMyAccessRights ( ) [ "write" ] ) {
715720 // If user can't write in workspace, do not show plus buttons
@@ -835,8 +840,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
835840 this . _createSearchBar ( ) ;
836841
837842 if ( osparc . utils . DisabledPlugins . isFoldersEnabled ( ) ) {
838- const workspaceHeader = this . __workspaceHeader = new osparc . dashboard . WorkspaceHeader ( ) ;
839- this . _addToLayout ( workspaceHeader ) ;
843+ const header = this . __header = new osparc . dashboard . StudyBrowserHeader ( ) ;
844+ this . _addToLayout ( header ) ;
840845 }
841846
842847 this . _createResourcesLayout ( ) ;
@@ -908,72 +913,76 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
908913
909914 __connectContexts : function ( ) {
910915 if ( osparc . utils . DisabledPlugins . isFoldersEnabled ( ) ) {
911- const workspaceHeader = this . __workspaceHeader ;
912- workspaceHeader . addListener ( "contextChanged " , ( ) => {
913- const workspaceId = workspaceHeader . getCurrentWorkspaceId ( ) ;
914- const folderId = workspaceHeader . getCurrentFolderId ( ) ;
915- this . __changeContext ( workspaceId , folderId ) ;
916+ const header = this . __header ;
917+ header . addListener ( "locationChanged " , ( ) => {
918+ const workspaceId = header . getCurrentWorkspaceId ( ) ;
919+ const folderId = header . getCurrentFolderId ( ) ;
920+ this . __changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
916921 } , this ) ;
917922
918923 const workspacesAndFoldersTree = this . _resourceFilter . getWorkspacesAndFoldersTree ( ) ;
919- workspacesAndFoldersTree . addListener ( "contextChanged " , e => {
924+ workspacesAndFoldersTree . addListener ( "locationChanged " , e => {
920925 const context = e . getData ( ) ;
921926 const workspaceId = context [ "workspaceId" ] ;
922- const folderId = context [ "folderId" ] ;
923- this . __changeContext ( workspaceId , folderId ) ;
927+ if ( workspaceId === - 1 ) {
928+ this . __changeContext ( "workspaces" ) ;
929+ } else {
930+ const folderId = context [ "folderId" ] ;
931+ this . __changeContext ( "studiesAndFolders" , workspaceId , folderId ) ;
932+ }
924933 } , this ) ;
925934
926935 this . _searchBarFilter . addListener ( "filterChanged" , e => {
927936 const filterData = e . getData ( ) ;
928937 if ( filterData . text ) {
929- this . __changeContext ( - 2 , null ) ;
938+ this . __changeContext ( "search" ) ;
930939 } else {
931940 // Back to My Workspace
932- this . __changeContext ( null , null ) ;
941+ this . __changeContext ( "studiesAndFolders" , null , null ) ;
933942 }
934943 } ) ;
935944 }
936945 } ,
937946
938- __changeContext : function ( workspaceId , folderId ) {
947+ __changeContext : function ( context , workspaceId = null , folderId = null ) {
939948 if ( osparc . utils . DisabledPlugins . isFoldersEnabled ( ) ) {
940949 if (
941- workspaceId !== - 2 && // reload studies for a new search
950+ context !== "search" && // reload studies for a new search
951+ context === this . getCurrentContext ( ) &&
942952 workspaceId === this . getCurrentWorkspaceId ( ) &&
943953 folderId === this . getCurrentFolderId ( )
944954 ) {
945955 // didn't really change
946956 return ;
947957 }
948958
949- this . _loadingResourcesBtn . setFetching ( false ) ;
950- this . resetSelection ( ) ;
951- this . setMultiSelection ( false ) ;
952959 this . set ( {
960+ currentContext : context ,
953961 currentWorkspaceId : workspaceId ,
954962 currentFolderId : folderId ,
955963 } ) ;
964+ this . _loadingResourcesBtn . setFetching ( false ) ;
965+ this . resetSelection ( ) ;
966+ this . setMultiSelection ( false ) ;
956967 this . invalidateStudies ( ) ;
957968 this . _resourcesContainer . setResourcesToList ( [ ] ) ;
958969
959- if ( workspaceId === - 2 ) {
960- // Search result: no folders, just studies
970+ if ( context === "search" ) {
961971 this . __setFoldersToList ( [ ] ) ;
962972 this . __reloadStudies ( ) ;
963- } else if ( workspaceId === - 1 ) {
964- // Workspaces
973+ } else if ( context === "workspaces" ) {
965974 this . _searchBarFilter . resetFilters ( ) ;
966975 this . __reloadWorkspaces ( ) ;
967- } else {
968- // Actual workspace
976+ } else if ( context === "studiesAndFolders" ) {
969977 this . _searchBarFilter . resetFilters ( ) ;
970978 this . __reloadFolders ( ) ;
971979 this . __reloadStudies ( ) ;
972980 }
973981
974- // notify workspaceHeader
975- const workspaceHeader = this . __workspaceHeader ;
976- workspaceHeader . set ( {
982+ // notify header
983+ const header = this . __header ;
984+ header . set ( {
985+ currentContext : context ,
977986 currentWorkspaceId : workspaceId ,
978987 currentFolderId : folderId ,
979988 } ) ;
@@ -984,7 +993,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
984993 currentWorkspaceId : workspaceId ,
985994 currentFolderId : folderId ,
986995 } ) ;
987- workspacesAndFoldersTree . contextChanged ( workspaceId , folderId ) ;
996+ workspacesAndFoldersTree . contextChanged ( context ) ;
988997 }
989998 } ,
990999
@@ -1130,8 +1139,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
11301139 } ) )
11311140 } ) ;
11321141 this . bind ( "multiSelection" , selectButton , "value" ) ;
1133- this . bind ( "currentWorkspaceId " , selectButton , "visibility" , {
1134- converter : currentWorkspaceId => [ - 2 , - 1 ] . includes ( currentWorkspaceId ) ? "excluded " : "visible "
1142+ this . bind ( "currentContext " , selectButton , "visibility" , {
1143+ converter : currentContext => currentContext === "studiesAndFolders" ? "visible " : "excluded "
11351144 } ) ;
11361145 return selectButton ;
11371146 } ,
0 commit comments