Feat(config): Reloading csv files

This commit is contained in:
Bertrand Benjamin 2019-01-21 11:41:47 +01:00
parent 892d74a24d
commit 1c7a2556c4
3 changed files with 29 additions and 10 deletions

View File

@ -16,7 +16,7 @@ export default {
},
mounted: function () {
this.$store.dispatch('config/load')
this.$store.dispatch('datas/find_csv')
this.$store.dispatch('datas/load_csvs')
}
}
</script>

View File

@ -15,7 +15,7 @@ export default {
getters: {
csvs: (state) => {
// return array of csv filename
return Object.keys(state.csv)
return Object.values(state.csv)
},
rows: (state) => {
// return all data stored in csv deleting duplicates rows
@ -23,6 +23,14 @@ export default {
.reduce((acc, d) => acc.concat(d), [])
)]
},
rows_in: (state, getters) => (csv) => {
// return rows in a specific csv file
if (csv in getters.csvs) {
return state.csv[csv].data
} else {
console.log('Unkown csv file - ', csv)
}
},
present: (state, getters) => {
// is there any datas
return getters.rows.length > 0
@ -90,8 +98,8 @@ export default {
}
},
mutations: {
SET_CSV_FILES: (state, { csvs }) => {
state.csv_files = csvs
CLEAR_DATA: (state) => {
state.csv = {}
},
SET_DATA: (state, { filename, data }) => {
Vue.set(state.csv, filename, data)
@ -104,7 +112,12 @@ export default {
}
},
actions: {
find_csv (context) {
load_csvs (context) {
// Clean state.csv then load csvs files
context.commit('CLEAR_DATA')
context.dispatch('find_csvs')
},
find_csvs (context) {
try {
readdir(context.rootGetters['config/data_dir'], (err, list) => {
if (err) {
@ -116,7 +129,6 @@ export default {
for (var i in csvs) {
context.dispatch('load_csv', csvs[i])
}
context.commit('SET_CSV_FILES', { csvs })
}
})
} catch (e) {
@ -147,6 +159,7 @@ export default {
formatDate(row, 'Date')
})
parsed.filename = filename
context.commit('SET_DATA',
{ filename: filename, data: parsed }
)

View File

@ -1,6 +1,11 @@
<template>
<div class="tags">
<h1>Fichiers CSV</h1>
<h1>
Fichiers CSV
<b-button @click="reload_csvs">
<font-awesome-icon icon="sync-alt" class="fa" />
</b-button>
</h1>
<p>
Les fichiers csv sont cherché dans <span class="datadir">{{ data_dir }}</span>
<!--
@ -8,7 +13,7 @@
-->
<b-list-group>
<b-list-group-item v-for="csv in csvs">
{{ csv }}
{{ csv.filename }} {{ csv.data.length }}
</b-list-group-item>
</b-list-group>
</p>
@ -46,8 +51,9 @@ export default {
})
},
methods: {
...mapActions('datas', [
]),
...mapActions('datas', {
'reload_csvs': 'load_csvs'
}),
open_filebrowser (dir) {
console.log("plop")
}