diff --git a/src/store/modules/datas.js b/src/store/modules/datas.js index 2e64b28..3eb8250 100644 --- a/src/store/modules/datas.js +++ b/src/store/modules/datas.js @@ -9,20 +9,21 @@ export default { namespaced: true, state: { csv: {}, - start: moment().subtract(1, 'months'), - end: moment() + month: moment(), }, getters: { csvs: (state) => { // return array of csv filename return Object.values(state.csv).sort((a, b) => { - var filenameA=a.filename.toLowerCase(), filenameB=b.filename.toLowerCase(); - if (filenameA < filenameB) //sort string ascending - return -1; - if (filenameA > filenameB) - return 1; - return 0; //default return value (no sorting) - }); + var filenameA=a.filename.toLowerCase(), filenameB=b.filename.toLowerCase() + if (filenameA < filenameB) { + return -1 + } + if (filenameA > filenameB) { + return 1 + } + return 0 + }) }, rows: (state) => { // return all data stored in csv deleting duplicates rows @@ -46,18 +47,14 @@ export default { // return data with negatives 'Montant' return getters.rows.filter(x => x.Montant < 0) }, - start: (state) => { - // Start date - return state.start.format(moment.HTML5_FMT.DATE) - }, - end: (state) => { - // End date - return state.end.format(moment.HTML5_FMT.DATE) + month: (state) => { + // month date + return state.month }, date_filter_rows: (state, getters) => { // return rows filtered by date return getters.spending_rows.filter(x => { - return (x.Date >= state.start) & (x.Date < state.end) + return moment(x.Date).isSame(state.month, 'month') }) }, tag_filter_rows: (state, getters) => (tags, invert) => { @@ -111,11 +108,8 @@ export default { SET_DATA: (state, { filename, data }) => { Vue.set(state.csv, filename, data) }, - SET_START: (state, { start }) => { - state.start = start - }, - SET_END: (state, { end }) => { - state.end = end + SET_MONTH: (state, { month }) => { + state.month = month } }, actions: { @@ -171,11 +165,13 @@ export default { { filename: filename, data: parsed } ) }, - set_start (context, start) { - context.commit('SET_START', { start: moment(start) }) + next_month (context) { + var next = moment(context.getters.month).add(1, 'months') + context.commit('SET_MONTH', { month: next }) + }, + prev_month (context) { + var prev = moment(context.getters.month).subtract(1, 'months') + context.commit('SET_MONTH', { month: prev }) }, - set_end (context, end) { - context.commit('SET_END', { end: moment(end) }) - } } } diff --git a/src/views/home.vue b/src/views/home.vue index ed65b70..ef5c80b 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -4,17 +4,15 @@