32
32
</b-col >
33
33
</b-row >
34
34
<b-row
35
- ><b-col > Select Path</b-col
35
+ ><b-col sm = " 2 " > Select Path: </b-col
36
36
><b-col >
37
37
<b-form-select
38
38
v-model =" selected"
39
39
:options =" options"
40
40
></b-form-select > </b-col
41
41
></b-row >
42
42
<b-row
43
- ><b-col > Upload</b-col
44
- ><b-col >
43
+ ><b-col sm = " 2 " > Upload file to remote: </b-col
44
+ ><b-col sm = " 8 " >
45
45
<b-form-file
46
46
v-model =" uploadFile"
47
47
:state =" Boolean(uploadFile)"
48
48
placeholder =" Choose a file or drop it here..."
49
49
drop-placeholder =" Drop file here..."
50
50
></b-form-file ></b-col
51
- ><b-col > <b-button >Upload</b-button > </b-col ></b-row
52
- >
53
- <b-table
54
- striped
55
- bordered
56
- hover
57
- small
58
- selectable
59
- select-mode =" single"
60
- @row-selected =" onRowSelected"
61
- :items =" files"
62
- :fields =" fields"
63
- primary-key =" Name"
64
- sort-by =" Type"
65
- :sort-compare =" sortingChanged"
51
+ ><b-col sm =" 2" >
52
+ <b-button @click =" upload()" >Upload</b-button >
53
+ </b-col ></b-row
66
54
>
67
- <template v-slot :cell (Size)="row">
68
- <div v-if =" row.item.Type != 'Directory'" >
69
- {{ new Intl.NumberFormat().format(row.item.Size) }}
70
- </div >
71
- </template >
72
- <template v-slot :cell (Modified)="row">
73
- <div v-if =" row.item.Modified" >
74
- {{ new Date(row.item.Modified).toUTCString() }}
75
- </div >
76
- </template >
77
- <template v-slot :cell (Operation)="row">
78
- <b-button-group class =" mr-1" >
79
- <b-button class =" mr-1"
80
- v-if =" row.item.Type != 'Directory' && row.item.Size < 100000"
81
- @click =" show(row.item.Name)"
82
- v-b-modal.modal-xl
83
- variant =" primary"
84
- >Show</b-button
85
- >
86
- <b-button class =" mr-1"
87
- v-if =" row.item.Type != 'Directory'"
88
- @click =" download(row.item.Name)"
89
- variant =" primary"
90
- >Download</b-button
91
- ></b-button-group
55
+ <b-row
56
+ ><b-col sm =" 10" >
57
+ <b-pagination
58
+ v-model =" currentPage"
59
+ :total-rows =" files.length"
60
+ :per-page =" perPage"
61
+ aria-controls =" my-table"
62
+ ></b-pagination >
63
+ </b-col >
64
+ <b-col sm =" 2" >
65
+ <b-form-select
66
+ v-model =" perPage"
67
+ :options =" perPageOptions"
68
+ size =" sm"
69
+ class =" mt-3"
70
+ ></b-form-select > </b-col
71
+ ></b-row >
72
+ <b-row
73
+ ><b-col >
74
+ <b-table
75
+ striped
76
+ bordered
77
+ hover
78
+ :per-page =" perPage"
79
+ :current-page =" currentPage"
80
+ small
81
+ selectable
82
+ select-mode =" single"
83
+ @row-selected =" onRowSelected"
84
+ :items =" files"
85
+ :fields =" fields"
86
+ primary-key =" Name"
87
+ sort-by =" Type"
88
+ :sort-compare =" sortingChanged"
92
89
>
93
- </template >
94
- </b-table >
90
+ <template v-slot :cell (Size)="row">
91
+ <div v-if =" row.item.Type != 'Directory'" >
92
+ {{ new Intl.NumberFormat().format(row.item.Size) }}
93
+ </div >
94
+ </template >
95
+ <template v-slot :cell (Modified)="row">
96
+ <div v-if =" row.item.Modified" >
97
+ {{ new Date(row.item.Modified).toUTCString() }}
98
+ </div >
99
+ </template >
100
+ <template v-slot :cell (Operation)="row">
101
+ <b-button-group class =" mr-1" >
102
+ <b-button
103
+ class =" mr-1"
104
+ v-if ="
105
+ row.item.Type != 'Directory' && row.item.Size < 100000
106
+ "
107
+ @click =" show(row.item.Name)"
108
+ v-b-modal.modal-xl
109
+ variant =" primary"
110
+ >Show</b-button
111
+ >
112
+ <b-button
113
+ class =" mr-1"
114
+ v-if =" row.item.Type != 'Directory'"
115
+ @click =" download(row.item.Name)"
116
+ variant =" primary"
117
+ >Download</b-button
118
+ >
119
+ <b-button
120
+ class =" mr-1"
121
+ v-if ="
122
+ row.item.Type != 'Directory' && row.item.Size < 100000
123
+ "
124
+ @click =" deleteFile(row.item.Name)"
125
+ variant =" primary"
126
+ >Delete</b-button
127
+ ></b-button-group
128
+ >
129
+ </template >
130
+ </b-table ></b-col
131
+ >
132
+ </b-row >
95
133
</b-container ></b-card-body
96
134
></b-card
97
135
>
@@ -117,12 +155,16 @@ export default class FileBrowser extends Vue {
117
155
@Prop (String ) readonly url: string | undefined ;
118
156
data() {
119
157
return {
158
+ perPage: 10 ,
159
+ currentPage: 1 ,
160
+ perPageOptions: [10 , 20 , 50 , 100 ],
120
161
selected: null ,
162
+ selectedFile: null ,
121
163
timer: " " ,
122
164
options: [],
123
165
files: [],
124
166
uploadFile: null ,
125
- filedata: " AC " ,
167
+ filedata: " Loading data ... " ,
126
168
path: " /" ,
127
169
browser: null as FilePathBrowser | null ,
128
170
fields: [
@@ -171,22 +213,30 @@ export default class FileBrowser extends Vue {
171
213
} else {
172
214
b .addPath (this .$data .path );
173
215
}
174
- this .$data .browser
175
- .filesQuery ()
176
- .then ((response : any ) => {
177
- console .log (" Got response ---" );
178
- this .$data .current = this .$data .path ;
179
- this .$data .files = response .Content ;
180
- this .$data .files .push ({ Name: " .." , Type: " Directory" });
181
- this .$data .path = " " ;
182
- })
183
- .catch ((error : any ) => {
184
- console .log (" ERROR:" + JSON .stringify (error ));
185
- });
216
+ this .refreshDirectory ();
186
217
}
187
218
}
219
+ refreshDirectory() {
220
+ this .$data .browser
221
+ .filesQuery ()
222
+ .then ((response : any ) => {
223
+ this .$data .current = this .$data .path ;
224
+ this .$data .files = response .Content ;
225
+ this .$data .files .push ({ Name: " .." , Type: " Directory" });
226
+ this .$data .path = " " ;
227
+ })
228
+ .catch ((error : any ) => {
229
+ console .log (" Refresh ERROR:" + JSON .stringify (error ));
230
+ });
231
+ }
188
232
sortingChanged(a : any , b : any , key : any ) {
189
233
let result = 0 ;
234
+ if (a [" Name" ] === " .." ) {
235
+ return - 1 ;
236
+ }
237
+ if (b [" Name" ] === " .." ) {
238
+ return 1 ;
239
+ }
190
240
if (key === " day" ) {
191
241
let day1 = a [key ].toLowerCase ();
192
242
let day2 = b [key ].toLowerCase ();
@@ -204,10 +254,19 @@ export default class FileBrowser extends Vue {
204
254
return a [" Name" ] - b [" Name" ];
205
255
}
206
256
onRowSelected(items : any ) {
207
- console .log (" Selected " + JSON .stringify (items ));
208
257
if (items .length == 0 ) {
209
258
return ;
210
259
}
260
+ console .log (
261
+ " Selected " +
262
+ JSON .stringify (items ) +
263
+ " " +
264
+ JSON .stringify (this .$data .selected )
265
+ );
266
+ if (this .$data .selectedFile == items [0 ]) {
267
+ return ;
268
+ }
269
+ this .$data .selectedFile = items [0 ];
211
270
if (items [0 ].Name == " .." ) {
212
271
this .$data .path = " .." ;
213
272
this .loadDirectory ();
@@ -222,17 +281,42 @@ export default class FileBrowser extends Vue {
222
281
}
223
282
}
224
283
show(fileName : string ) {
225
- console .log (" Download " + fileName );
226
- this .$data .browser .download (fileName ).then ((response : any ) => {
284
+ console .log (" Read " + fileName );
285
+ this .$data .filedata = " Loading data ..." ;
286
+ this .$data .browser .read (fileName ).then ((response : any ) => {
227
287
this .$data .filedata = response ;
228
288
});
229
289
}
230
290
download(fileName : string ) {
231
291
console .log (" Download " + fileName );
292
+ this .$data .browser .download (fileName );
232
293
}
233
294
upload() {
295
+ console .log (" Upload " + this .$data .uploadFile .Name );
234
296
this .$data .browser .upload (this .$data .uploadFile );
235
297
}
298
+ deleteFile(fileName : string ) {
299
+ console .log (" Delete " + fileName );
300
+ this .$bvModal
301
+ .msgBoxConfirm (" Really delete file " + fileName + " ?" )
302
+ .then ((value ) => {
303
+ if (value == true ) {
304
+ this .$data .browser
305
+ .deleteFile (fileName )
306
+ .then ((value : any ) => {
307
+ console .log (" File deleted" );
308
+ })
309
+ .catch ((err : any ) => {
310
+ console .log (" Error deleting file" );
311
+ });
312
+ this .refreshDirectory ();
313
+ }
314
+ })
315
+ .catch ((err ) => {
316
+ // An error occurred
317
+ console .log (" Error: " + JSON .stringify (err ));
318
+ });
319
+ }
236
320
}
237
321
</script >
238
322
0 commit comments