Skip to content
Snippets Groups Projects
Commit c8e86148 authored by Kirill Stytsenko's avatar Kirill Stytsenko
Browse files

Upload CSV data

parent 2e56f30d
No related branches found
No related tags found
No related merge requests found
...@@ -88,7 +88,7 @@ export default { ...@@ -88,7 +88,7 @@ export default {
const tableId = this.tables[this.panelIndex].id const tableId = this.tables[this.panelIndex].id
try { try {
const res = await this.$axios.get(`/api/tables/api/database/${this.$route.params.db_id}/table/${tableId}`) const res = await this.$axios.get(`/api/tables/api/database/${this.$route.params.db_id}/table/${tableId}`)
this.tableDetails = res.data[0] // It's a list with one element this.tableDetails = res.data
} catch (err) { } catch (err) {
this.$toast.error('Could not get table details.') this.$toast.error('Could not get table details.')
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<v-row dense> <v-row dense>
<v-col cols="10"> <v-col cols="10">
<v-file-input <v-file-input
v-model="file"
accept="text/csv" accept="text/csv"
show-size show-size
label="CSV File" /> label="CSV File" />
...@@ -23,19 +24,32 @@ export default { ...@@ -23,19 +24,32 @@ export default {
}, },
data () { data () {
return { return {
loading: false loading: false,
file: null
} }
}, },
mounted () { mounted () {
}, },
methods: { methods: {
upload () { async upload () {
this.loading = true this.loading = true
setTimeout(() => { const url = `/api/tables/api/database/${this.$route.params.db_id}/table/${this.$route.params.table_id}`
const data = new FormData()
data.append('file', this.file)
try {
const res = await this.$axios.post(url, data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
if (res.data.Result) {
this.$toast.success('Uploaded successfully!') this.$toast.success('Uploaded successfully!')
this.loading = false
this.$router.push({ path: '.' }) this.$router.push({ path: '.' })
}, 1000) } else {
this.$toast.error('Could not upload CSV data')
}
} catch (err) {
this.$toast.error('Could not upload data.')
}
this.loading = false
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment