@@ -39,57 +39,15 @@ qx.Class.define("osparc.dashboard.DataBrowser", {
39
39
} ,
40
40
41
41
members : {
42
- __filesTree : null ,
43
- __folderViewer : null ,
44
- __selectedFileLayout : null ,
45
-
46
42
_createChildControlImpl : function ( id ) {
47
43
let control ;
48
44
switch ( id ) {
49
- case "reload-button" :
50
- control = new qx . ui . form . Button ( ) . set ( {
51
- label : this . tr ( "Reload" ) ,
52
- font : "text-14" ,
53
- icon : "@FontAwesome5Solid/sync-alt/14" ,
54
- allowGrowX : false
55
- } ) ;
56
- this . _addToLayout ( control ) ;
57
- break ;
58
- case "tree-folder-layout" :
59
- control = new qx . ui . splitpane . Pane ( "horizontal" ) ;
60
- control . getChildControl ( "splitter" ) . set ( {
61
- width : 2 ,
62
- backgroundColor : "scrollbar-passive"
63
- } ) ;
45
+ case "tree-folder-view" :
46
+ control = new osparc . file . TreeFolderView ( ) ;
64
47
this . _addToLayout ( control , {
65
48
flex : 1
66
49
} ) ;
67
50
break ;
68
- case "files-tree" : {
69
- const treeFolderLayout = this . getChildControl ( "tree-folder-layout" ) ;
70
- control = new osparc . file . FilesTree ( ) . set ( {
71
- showLeafs : false ,
72
- minWidth : 150 ,
73
- width : 250
74
- } ) ;
75
- treeFolderLayout . add ( control , 0 ) ;
76
- break ;
77
- }
78
- case "folder-viewer" : {
79
- const treeFolderLayout = this . getChildControl ( "tree-folder-layout" ) ;
80
- control = new osparc . file . FolderViewer ( ) ;
81
- treeFolderLayout . add ( control , 1 ) ;
82
- break ;
83
- }
84
- case "selected-file-layout" :
85
- control = new osparc . file . FileLabelWithActions ( ) . set ( {
86
- alignY : "middle"
87
- } ) ;
88
- break ;
89
- case "actions-toolbar" :
90
- control = new qx . ui . toolbar . ToolBar ( ) ;
91
- this . _addToLayout ( control ) ;
92
- break ;
93
51
}
94
52
95
53
return control || this . base ( arguments , id ) ;
@@ -101,8 +59,9 @@ qx.Class.define("osparc.dashboard.DataBrowser", {
101
59
this . __buildLayout ( ) ;
102
60
103
61
this . addListener ( "appear" , ( ) => {
104
- this . getChildControl ( "files-tree" ) . populateTree ( ) ;
105
- this . getChildControl ( "folder-viewer" ) . setFolder ( this . getChildControl ( "files-tree" ) . getModel ( ) ) ;
62
+ const treeFolderView = this . getChildControl ( "tree-folder-view" ) ;
63
+ treeFolderView . getChildControl ( "folder-tree" ) . populateTree ( ) ;
64
+ treeFolderView . getChildControl ( "folder-viewer" ) . setFolder ( treeFolderView . getChildControl ( "folder-tree" ) . getModel ( ) ) ;
106
65
} , this ) ;
107
66
} ,
108
67
@@ -111,64 +70,53 @@ qx.Class.define("osparc.dashboard.DataBrowser", {
111
70
marginTop : 20
112
71
} ) ;
113
72
114
- // button for refetching data
115
- const reloadBtn = this . getChildControl ( "reload-button" ) ;
116
- reloadBtn . addListener ( "execute" , ( ) => {
117
- this . getChildControl ( "files-tree" ) . resetCache ( ) ;
118
- this . getChildControl ( "files-tree" ) . populateTree ( ) ;
119
- } , this ) ;
73
+ const treeFolderView = this . getChildControl ( "tree-folder-view" ) ;
120
74
121
- const filesTree = this . getChildControl ( "files-tree " ) ;
122
- const folderViewer = this . getChildControl ( "folder-viewer" ) ;
75
+ const reloadButton = treeFolderView . getChildControl ( "reload-button " ) ;
76
+ reloadButton . addListener ( "execute" , ( ) => this . __reloadTree ( ) , this ) ;
123
77
124
- const actionsToolbar = this . getChildControl ( "actions-toolbar" ) ;
125
- const fileActions = new qx . ui . toolbar . Part ( ) ;
126
- const addFile = new qx . ui . toolbar . Part ( ) ;
127
- actionsToolbar . add ( fileActions ) ;
128
- actionsToolbar . addSpacer ( ) ;
129
- actionsToolbar . add ( addFile ) ;
78
+ const selectedFileLayout = treeFolderView . getChildControl ( "selected-file-layout" ) ;
79
+ selectedFileLayout . addListener ( "fileDeleted" , e => this . __fileDeleted ( e . getData ( ) ) , this ) ;
80
+ } ,
130
81
131
- const selectedFileLayout = this . __selectedFileLayout = this . getChildControl ( "selected-file-layout" ) ;
82
+ __reloadTree : function ( ) {
83
+ const treeFolderView = this . getChildControl ( "tree-folder-view" ) ;
132
84
133
- filesTree . addListener ( "selectionChanged" , ( ) => {
134
- const selectionData = filesTree . getSelectedItem ( ) ;
135
- this . __selectionChanged ( selectionData ) ;
136
- if ( osparc . file . FilesTree . isDir ( selectionData ) || ( selectionData . getChildren && selectionData . getChildren ( ) . length ) ) {
137
- folderViewer . setFolder ( selectionData ) ;
138
- }
139
- } , this ) ;
85
+ const foldersTree = treeFolderView . getChildControl ( "folder-tree" ) ;
86
+ foldersTree . resetCache ( ) ;
87
+ foldersTree . populateTree ( ) ;
140
88
141
- folderViewer . addListener ( "selectionChanged" , e => {
142
- const selectionData = e . getData ( ) ;
143
- this . __selectionChanged ( selectionData ) ;
144
- } , this ) ;
145
- folderViewer . addListener ( "itemSelected" , e => {
146
- const data = e . getData ( ) ;
147
- filesTree . openNodeAndParents ( data ) ;
148
- filesTree . setSelection ( new qx . data . Array ( [ data ] ) ) ;
149
- } , this ) ;
150
- folderViewer . addListener ( "folderUp" , e => {
151
- const currentFolder = e . getData ( ) ;
152
- const parent = filesTree . getParent ( currentFolder ) ;
153
- if ( parent ) {
154
- filesTree . setSelection ( new qx . data . Array ( [ parent ] ) ) ;
155
- folderViewer . setFolder ( parent ) ;
156
- }
157
- } , this ) ;
158
- folderViewer . addListener ( "requestDatasetFiles" , e => {
159
- const data = e . getData ( ) ;
160
- filesTree . requestDatasetFiles ( data . locationId , data . datasetId ) ;
161
- } , this ) ;
162
-
163
- selectedFileLayout . addListener ( "fileDeleted" , e => {
164
- const fileMetadata = e . getData ( ) ;
165
- this . getChildControl ( "files-tree" ) . populateTree ( fileMetadata [ "locationId" ] ) ;
166
- } , this ) ;
167
- fileActions . add ( selectedFileLayout ) ;
89
+ const folderViewer = treeFolderView . getChildControl ( "folder-viewer" ) ;
90
+ folderViewer . resetFolder ( ) ;
168
91
} ,
169
92
170
- __selectionChanged : function ( selectedItem ) {
171
- this . __selectedFileLayout . setItemSelected ( selectedItem ) ;
93
+ __fileDeleted : function ( fileMetadata ) {
94
+ // After deleting a file, try to keep the user in the same folder.
95
+ // If the folder doesn't longer exist, open the closest available parent
96
+
97
+ const path = fileMetadata [ "fileUuid" ] . split ( "/" ) ;
98
+
99
+ const treeFolderView = this . getChildControl ( "tree-folder-view" ) ;
100
+ const foldersTree = treeFolderView . getChildControl ( "folder-tree" ) ;
101
+ const folderViewer = treeFolderView . getChildControl ( "folder-viewer" ) ;
102
+
103
+ const openSameFolder = ( ) => {
104
+ // drop last, which is the file
105
+ path . pop ( ) ;
106
+ treeFolderView . openPath ( path ) ;
107
+ } ;
108
+
109
+ folderViewer . resetFolder ( ) ;
110
+ const locationId = fileMetadata [ "locationId" ] ;
111
+ const datasetId = path [ 0 ] ;
112
+ foldersTree . resetCache ( ) ;
113
+ foldersTree . populateTree ( )
114
+ . then ( datasetPromises => {
115
+ Promise . all ( datasetPromises )
116
+ . then ( ( ) => foldersTree . requestDatasetFiles ( locationId , datasetId ) )
117
+ . then ( ( ) => openSameFolder ( ) ) ;
118
+ } )
119
+ . catch ( err => console . error ( err ) ) ;
172
120
}
173
121
}
174
122
} ) ;
0 commit comments