-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDownloads.vue
72 lines (67 loc) · 1.93 KB
/
Downloads.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<template>
<div class="p-3">
<base-text variant="h1" class="my-3">{{
$t('nav.user_downloads')
}}</base-text>
<AjaxTable
:url="tableUrl"
:columns="columns"
:body-style="{ height: '30rem' }"
data-testid="testDownloadsTable"
class="border"
>
<template #file="{ item }">
<div v-if="item.file">
<base-button
:action="() => downloadFile(item.file)"
variant="solid"
class="ml-3"
size="small"
>
{{ $t('actions.download') }}
</base-button>
</div>
</template>
</AjaxTable>
</div>
</template>
<script lang="ts">
import moment from 'moment/moment';
import { makeTableColumns } from '@/utils/table';
import AjaxTable from '@/components/AjaxTable.vue';
import BaseText from '@/components/BaseText.vue';
import BaseButton from '@/components/BaseButton.vue';
import axios from 'axios';
import { forceFileDownloadFromURl } from '@/utils/downloads';
export default defineComponent({
name: 'Downloads',
components: { BaseButton, BaseText, AjaxTable },
setup() {
const tableUrl = `${import.meta.env.VITE_APP_API_BASE_URL}/user_downloads`;
const columns = makeTableColumns([
['created_at', '1fr', 'Created At'],
['status', '1fr', 'Status'],
['file', '1fr', ''],
]);
for (const column of columns) {
// overwrite default column title from `Name` to `Organization`
if (column.key === 'created_at') {
column.transformer = (field) => {
return moment(field).format('ddd MMMM Do YYYY h:mm:ss a');
};
}
}
const downloadFile = async (file: any) => {
const { data } = await axios.get(`/files/${file}`);
const url = data.csv_url;
return forceFileDownloadFromURl(url, data.filename_original);
};
return {
tableUrl,
columns,
downloadFile,
};
},
});
</script>
<style scoped></style>