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