Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit d551682

Browse files
committed
filelist wip
1 parent a904744 commit d551682

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"axios": "^0.21.1",
1414
"buefy": "^0.9",
1515
"core-js": "^3.6.5",
16+
"file-saver": "^2.0.5",
1617
"lodash": "^4.17.20",
1718
"postcss-import": "^12.0.1",
1819
"prismjs": "^1.22.0",

src/store/file/actions.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// import axios from 'axios'
22

33

4+
import {filterToQueryString} from "@/helpers/URL";
5+
46
export default {
5-
async list(context, paginationData) {
6-
return await this._vm.$http.get('/file?page='+paginationData.page+'&per_page='+paginationData.perPage)
7+
async list(context, parameters) {
8+
const filterStr = filterToQueryString(parameters.filter)
9+
return await this._vm.$http.get(`/file?page=${parameters.page}&per_page=${parameters.perPage}${filterStr}`)
710
},
811
async all({ commit }) {
912
const response = await this._vm.$http.get('/file')
@@ -18,5 +21,10 @@ export default {
1821
'Content-Type': 'multipart/form-data'
1922
}
2023
})
24+
},
25+
async download(context, file_id) {
26+
return await this._vm.$http.get(`/file/${file_id}/download`, {
27+
responseType: 'blob',
28+
})
2129
}
2230
}

src/views/files/FileList.vue

+54-8
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,49 @@
2626
:autoload="false"
2727
:dense="true"
2828
ref="table"
29+
:headers="headers"
2930
>
3031

31-
<b-table-column field="name" label="Name" v-slot="props">
32-
{{ props.row.filename }}
32+
<b-table-column field="name" label="Name" searchable>
33+
<template
34+
slot="searchable"
35+
slot-scope="props">
36+
<b-input
37+
v-model="props.filters[props.column.field]"
38+
placeholder="Search..."
39+
icon="magnify"
40+
size="is-small" />
41+
</template>
42+
<template v-slot="props">
43+
{{ props.row.name }}
44+
</template>
45+
</b-table-column>
46+
47+
<b-table-column field="type" label="Type" searchable>
48+
<template
49+
slot="searchable"
50+
slot-scope="props">
51+
<b-input
52+
v-model="props.filters[props.column.field]"
53+
placeholder="Search..."
54+
icon="magnify"
55+
size="is-small" />
56+
</template>
57+
<template v-slot="props">
58+
{{ props.row.type }}
59+
</template>
3360
</b-table-column>
3461

3562
<b-table-column field="size" label="File size" v-slot="props">
3663
{{ props.row.size }} bytes
3764
</b-table-column>
3865

39-
<b-table-column field="size" label="Mod time" v-slot="props">
40-
{{ props.row.mod_time }}
66+
<b-table-column field="created_at" label="Upload time" v-slot="props">
67+
{{ props.row.created_at | moment }}
4168
</b-table-column>
4269

4370
<b-table-column field="actions" label="Actions" v-slot="props">
44-
<b-button tag="a" type="is-primary" :href="generateFileUri(props.row.filename)">
71+
<b-button tag="a" type="is-primary" @click="download(props.row)">
4572
<b-icon icon="download"></b-icon>
4673
</b-button>
4774
</b-table-column>
@@ -51,19 +78,38 @@
5178
</template>
5279

5380
<script>
81+
import { saveAs } from 'file-saver';
5482
import PaginatedTable from "../../components/PaginatedTable";
5583
import UploadFile from "./UploadFile";
5684
export default {
5785
name: "FileList",
5886
components: {UploadFile, PaginatedTable},
5987
data() {
6088
return {
61-
uploadDialog: false,
89+
headers: [
90+
{
91+
text: 'Name',
92+
value: 'name',
93+
searchable: true,
94+
},
95+
{
96+
text: 'Type',
97+
value: 'type',
98+
searchable: true,
99+
},
100+
{
101+
text: 'Size',
102+
value: 'size',
103+
searchable: true,
104+
},
105+
],
106+
uploadDialog: false,
62107
}
63108
},
64109
methods: {
65-
generateFileUri(filename) {
66-
return `${process.env.VUE_APP_API_URL}../file/${filename}`
110+
download(file) {
111+
const response = this.$store.dispatch('file/download', file.id)
112+
saveAs(response.data, file.name)
67113
},
68114
refreshList() {
69115
this.$refs.table.fetchItems()

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -3769,6 +3769,11 @@ file-loader@^4.0.0, file-loader@^4.2.0:
37693769
loader-utils "^1.2.3"
37703770
schema-utils "^2.5.0"
37713771

3772+
file-saver@^2.0.5:
3773+
version "2.0.5"
3774+
resolved "https://registry.yarnpkg.com/file-saver/-/file-saver-2.0.5.tgz#d61cfe2ce059f414d899e9dd6d4107ee25670c38"
3775+
integrity sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==
3776+
37723777
file-uri-to-path@1.0.0:
37733778
version "1.0.0"
37743779
resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"

0 commit comments

Comments
 (0)