@@ -22,13 +22,13 @@ qx.Class.define("qxapp.component.widget.FileManager", {
22
22
treesLayout . add ( nodeTree , {
23
23
flex : 1
24
24
} ) ;
25
- nodeTree . getSelection ( ) . addListener ( "change" , this . __itemSelected , this ) ;
25
+ nodeTree . getSelection ( ) . addListener ( "change" , this . __nodeItemSelected , this ) ;
26
26
27
27
let userTree = this . __userTree = this . _createChildControlImpl ( "userTree" ) ;
28
28
treesLayout . add ( userTree , {
29
29
flex : 1
30
30
} ) ;
31
- userTree . getSelection ( ) . addListener ( "change" , this . __itemSelected , this ) ;
31
+ userTree . getSelection ( ) . addListener ( "change" , this . __userItemSelected , this ) ;
32
32
33
33
let selectedFileLayout = this . _createChildControlImpl ( "selectedFileLayout" ) ;
34
34
{
@@ -116,7 +116,7 @@ qx.Class.define("qxapp.component.widget.FileManager", {
116
116
117
117
__reloadNodeTree : function ( ) {
118
118
let filesTreePopulator = new qxapp . utils . FilesTreePopulator ( this . __nodeTree ) ;
119
- filesTreePopulator . populateNodeFiles ( ) ;
119
+ filesTreePopulator . populateNodeFiles ( this . getNodeModel ( ) . getNodeId ( ) ) ;
120
120
121
121
let that = this ;
122
122
let delegate = this . __nodeTree . getDelegate ( ) ;
@@ -190,30 +190,59 @@ qx.Class.define("qxapp.component.widget.FileManager", {
190
190
if ( e . supportsType ( "osparc-filePath" ) ) {
191
191
const from = e . getRelatedTarget ( ) ;
192
192
const to = e . getCurrentTarget ( ) ;
193
+ let store = qxapp . data . Store . getInstance ( ) ;
193
194
console . log ( "Copy" , from . getFileId ( ) , "to" , to . getPath ( ) ) ;
195
+ store . copyFile ( from . getLocation ( ) , from . getFileId ( ) , to . getLocation ( ) , to . getPath ( ) ) ;
196
+ store . addListenerOnce ( "FileCopied" , ev => {
197
+ this . __reloadUserTree ( ) ;
198
+ } , this ) ;
194
199
}
195
200
} , this ) ;
196
201
} ,
197
202
198
- __itemSelected : function ( ) {
203
+ __nodeItemSelected : function ( ) {
199
204
let selectedItem = this . __nodeTree . getSelection ( ) ;
200
205
if ( selectedItem . length < 1 ) {
201
206
return ;
202
207
}
208
+ this . __userTree . resetSelection ( ) ;
203
209
selectedItem = selectedItem . toArray ( ) ;
204
- if ( this . __isFile ( selectedItem [ 0 ] ) ) {
205
- this . __selection = selectedItem [ 0 ] . getFileId ( ) ;
206
- this . __selectedLabel . setValue ( selectedItem [ 0 ] . getFileId ( ) ) ;
210
+ this . __itemSelected ( selectedItem [ 0 ] ) ;
211
+ } ,
212
+
213
+ __userItemSelected : function ( ) {
214
+ let selectedItem = this . __userTree . getSelection ( ) ;
215
+ if ( selectedItem . length < 1 ) {
216
+ return ;
217
+ }
218
+ this . __nodeTree . resetSelection ( ) ;
219
+ selectedItem = selectedItem . toArray ( ) ;
220
+ this . __itemSelected ( selectedItem [ 0 ] ) ;
221
+ } ,
222
+
223
+ __itemSelected : function ( selectedItem ) {
224
+ if ( this . __isFile ( selectedItem ) ) {
225
+ this . __selection = selectedItem ;
226
+ this . __selectedLabel . setValue ( selectedItem . getFileId ( ) ) ;
207
227
} else {
208
228
this . __selection = null ;
209
229
this . __selectedLabel . setValue ( "" ) ;
210
230
}
211
231
} ,
212
232
233
+ __getItemSelected : function ( ) {
234
+ let selectedItem = this . __selection ;
235
+ if ( selectedItem && this . __isFile ( selectedItem ) ) {
236
+ return selectedItem ;
237
+ }
238
+ return null ;
239
+ } ,
240
+
213
241
// Request to the server an download
214
242
__retrieveURLAndDownload : function ( ) {
215
- if ( this . __selection !== null ) {
216
- const fileId = this . __selection ;
243
+ let selection = this . __getItemSelected ( ) ;
244
+ if ( selection ) {
245
+ const fileId = selection . getFileId ( ) ;
217
246
let fileName = fileId . split ( "/" ) ;
218
247
fileName = fileName [ fileName . length - 1 ] ;
219
248
let store = qxapp . data . Store . getInstance ( ) ;
@@ -225,7 +254,7 @@ qx.Class.define("qxapp.component.widget.FileManager", {
225
254
}
226
255
} , this ) ;
227
256
const download = true ;
228
- const locationId = 0 ;
257
+ const locationId = selection . getLocation ( ) ;
229
258
store . getPresginedLink ( download , locationId , fileId ) ;
230
259
}
231
260
} ,
@@ -237,7 +266,7 @@ qx.Class.define("qxapp.component.widget.FileManager", {
237
266
xhr . onload = ( ) => {
238
267
console . log ( "onload" , xhr ) ;
239
268
if ( xhr . status == 200 ) {
240
- var blob = new Blob ( xhr . response ) ;
269
+ let blob = new Blob ( [ xhr . response ] ) ;
241
270
let urlBlob = window . URL . createObjectURL ( blob ) ;
242
271
let downloadAnchorNode = document . createElement ( "a" ) ;
243
272
downloadAnchorNode . setAttribute ( "href" , urlBlob ) ;
@@ -250,7 +279,18 @@ qx.Class.define("qxapp.component.widget.FileManager", {
250
279
} ,
251
280
252
281
__deleteFile : function ( ) {
253
- console . log ( "Delete " , this . __selection ) ;
282
+ let selection = this . __getItemSelected ( ) ;
283
+ if ( selection ) {
284
+ console . log ( "Delete " , selection ) ;
285
+ const fileId = selection . getFileId ( ) ;
286
+ const locationId = selection . getLocation ( ) ;
287
+ let store = qxapp . data . Store . getInstance ( ) ;
288
+ store . addListenerOnce ( "DeleteFile" , e => {
289
+ this . __reloadNodeTree ( ) ;
290
+ this . __reloadUserTree ( ) ;
291
+ } , this ) ;
292
+ store . deleteFile ( locationId , fileId ) ;
293
+ }
254
294
}
255
295
}
256
296
} ) ;
0 commit comments