Refact: Move back filtering in store

This commit is contained in:
2018-12-01 14:49:02 +01:00
parent df4c1af893
commit 967557f397
3 changed files with 79 additions and 71 deletions

View File

@@ -2,6 +2,10 @@ import { readdir, readFile } from 'fs'
import path from 'path'
import Papa from 'papaparse'
var today = new Date()
var monthAgo = new Date()
monthAgo.setMonth(monthAgo.getMonth() - 1)
export default {
namespaced: true,
state: {
@@ -12,6 +16,8 @@ export default {
fields: []
}
},
start: monthAgo.toISOString().split('T')[0],
end: today.toISOString().split('T')[0]
},
getters: {
csvs: (state) => {
@@ -19,6 +25,40 @@ export default {
},
rows: (state) => {
return state.rows.data
},
spending_rows: (state, getters) => {
return getters.rows.filter(x => x.Montant < 0)
},
start: (state) => {
return state.start
},
end: (state) => {
return state.end
},
date_filter_rows: (state, getters) => {
var start = new Date(state.start)
var end = new Date(state.end)
return getters.spending_rows.filter(x => {
return (new Date(x.Date) >= start) & (new Date(x.Date) < end)
})
},
libelle_filter_rows: (state, getters) => (words, invert) => {
if (!words) {
return getters.date_filter_rows
}
if (invert) {
return getters.date_filter_rows.filter(x => {
return words.every(v => {
return x.Libellé.indexOf(v) < 0
})
})
} else {
return getters.date_filter_rows.filter(x => {
return words.some(v => {
return x.Libellé.indexOf(v) >= 0
})
})
}
}
},
mutations: {
@@ -31,6 +71,12 @@ export default {
},
APPEND_DATA: (state, { content }) => {
state.rows.push(content)
},
SET_START: (state, { start }) => {
state.start = start
},
SET_END: (state, { end }) => {
state.end = end
}
},
actions: {
@@ -65,6 +111,12 @@ export default {
context.commit('SET_DATA', { data: parsed })
}
})
}
},
set_start (context, start) {
context.commit('SET_START', { start })
},
set_end (context, end) {
context.commit('SET_END', { end })
},
}
}