Feat: write data on edit

This commit is contained in:
Bertrand Benjamin 2021-08-09 11:48:24 +02:00
parent 899fd95dbd
commit 5020479b0a
4 changed files with 11 additions and 4 deletions

View File

@ -74,10 +74,14 @@ export default {
...mapActions('travail', { ...mapActions('travail', {
'createMonth': 'createMonth', 'createMonth': 'createMonth',
}), }),
...mapActions('config', {
'writeData': 'writeData',
}),
save: function () { save: function () {
console.log("save") console.log("save")
console.log(this.monthCopy) console.log(this.monthCopy)
this.createMonth({date: this.monthDate, month: this.monthCopy}) this.createMonth({date: this.monthDate, month: this.monthCopy})
this.writeData()
}, },
cancel: function () { cancel: function () {
this.monthCopy = this.theEmptyMonth this.monthCopy = this.theEmptyMonth

View File

@ -71,13 +71,14 @@ export default {
'updateMonth': 'updateMonth', 'updateMonth': 'updateMonth',
}), }),
...mapActions('config', { ...mapActions('config', {
'loadData': 'loadData', 'writeData': 'writeData',
}), }),
toggleEdit: function () { toggleEdit: function () {
this.editing = !this.editing this.editing = !this.editing
}, },
save: function () { save: function () {
this.updateMonth({date: this.TheDate, month: {...this.monthCopy}}) this.updateMonth({date: this.TheDate, month: {...this.monthCopy}})
this.writeData()
this.toggleEdit() this.toggleEdit()
}, },
cancel: function () { cancel: function () {

View File

@ -71,6 +71,8 @@ export default {
retrocessionMean: "retrocessionMean", retrocessionMean: "retrocessionMean",
}) })
}, },
mounted () {
},
methods: { methods: {
}, },
} }

View File

@ -183,11 +183,11 @@ const travail = {
}, },
loadMonths (context) { loadMonths (context) {
// import all months from storage // import all months from storage
readFile(context.rootGetters["config/dataFilePath"], (err, data) => { readFile(context.rootGetters["config/dataFilePath"], (err, data) => {
if (err) throw err; if (err) throw err;
const months = Papa.parse(data.toString(), {header: true, dynamicTyping:true}) const months = Papa.parse(data.toString(), {header: true, dynamicTyping:true, skipEmptyLines:true})
.data.reduce( .data
.reduce(
(acc, el) => { (acc, el) => {
acc[el.date] = el; acc[el.date] = el;
return acc return acc