Feat: improve month selector

This commit is contained in:
2021-08-03 16:57:16 +02:00
parent 7f9cecf06d
commit 7b742d599a
6 changed files with 87 additions and 17 deletions

View File

@@ -60,14 +60,23 @@ const travail = {
remumeration: 2800, // rémunération décidée
},
},
range: {
start: "2021-01",
end: "2021-08",
},
}
},
getters: {
Count (state) {return state.months.length},
TheEmptyMonth (state) {return {...state.empty}},
Range (state) {return state.range},
MonthsDate (state) {
// Get months inside the range
return Object.keys(state.months).filter(date => (date >= state.range.start)&&(date <= state.range.end) ).sort().reverse()
},
MonthsAllDate (state) {
// Get all the months
return Object.keys(state.months).sort().reverse()
//return state.months.sort((a, b) => new Date(b.date) - new Date(a.date))
},
getMonth: (state) => (date) => {
return state.months[date]
@@ -80,9 +89,14 @@ const travail = {
createMonth (state, {date, month}) {
state.months[date] = month
},
setRange (state, range) {
state.range = range
},
},
actions: {
updateMonth (context, {date, month}) {
// update month's datas
if (date in context.state.months) {
context.commit('updateMonth', {date, month})
} else {
@@ -90,6 +104,7 @@ const travail = {
}
},
createMonth (context, {date, month}) {
// Create a new month
if (!(date in context.state.months)) {
console.log(date)
context.commit('createMonth', {date, month})
@@ -98,6 +113,10 @@ const travail = {
console.log("This month already exists")
}
},
setRange (context, range) {
context.commit("setRange", range)
},
},
}