Feat: Write data in csv
This commit is contained in:
parent
6188337140
commit
7ca7af24b9
@ -1,5 +1,6 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import Papa from 'papaparse'
|
import Papa from 'papaparse'
|
||||||
|
import { writeFile, readFileSync } from 'fs'
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
@ -23,17 +24,20 @@ const config = {
|
|||||||
},
|
},
|
||||||
loadData (context) {
|
loadData (context) {
|
||||||
// load data in userDir on dataFile
|
// load data in userDir on dataFile
|
||||||
console.log("Loading data")
|
console.log(readFileSync(context.getters.dataFilePath, "utf-8"))
|
||||||
console.log(context.getters.dataFilePath)
|
|
||||||
},
|
},
|
||||||
writeData (context) {
|
writeData (context) {
|
||||||
// overwrite the dataFile with months datas
|
// overwrite the dataFile with months datas
|
||||||
console.log("Writing data")
|
|
||||||
console.log(context.getters.dataFilePath)
|
|
||||||
const months = context.rootGetters['travail/monthsAll']
|
const months = context.rootGetters['travail/monthsAll']
|
||||||
console.log(Object.keys(months).map(k => {return { ...months[k], date: k}}))
|
const unpackMonths = Object.keys(months).map(k => {return { ...months[k], date: k}})
|
||||||
const csv = Papa.unparse(context.rootGetters['travail/monthsAll'])
|
const csv = Papa.unparse(unpackMonths)
|
||||||
console.log(csv)
|
writeFile(context.getters.dataFilePath, csv, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err)
|
||||||
|
} else {
|
||||||
|
console.log("Datas sauvegardées")
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user