Feat: Select poste on clicking

This commit is contained in:
Bertrand Benjamin 2018-11-30 22:07:08 +01:00
parent e7d792e7ef
commit df4c1af893
4 changed files with 65 additions and 29 deletions

View File

@ -1,13 +1,17 @@
<template> <template>
<b-card :bg-variant="poste.variant" <b-card v-if="poste"
:bg-variant="poste.variant"
text-variant="white" text-variant="white"
class="text-center"> class="text-center">
<p class="card-text"> <div class="card-text">
<font-awesome-icon :icon="poste.icon" /> <div class="icon">
{{ poste.name }} <font-awesome-icon :icon="poste.icon" class="fa-3x"/>
</br> </div>
{{ total() }} <div class="amount">
</p> <h3>{{ total() }}</h3>
{{ poste.name }}
</div>
</div>
</b-card> </b-card>
</template> </template>
@ -21,11 +25,6 @@ export default {
], ],
data () { data () {
return { return {
empty_poste: {
variant: '',
icon: '',
name: ''
}
} }
}, },
computed: { computed: {
@ -33,11 +32,7 @@ export default {
'postes' 'postes'
]), ]),
poste () { poste () {
if (this.postes) { return this.postes[this.postename]
return this.postes[this.postename]
} else {
return this.empty_poste
}
} }
}, },
methods: { methods: {
@ -75,4 +70,18 @@ export default {
</script> </script>
<style scoped> <style scoped>
.card-body {
padding: 10px;
}
.card-text {
display: flex;
}
.icon {
flex: 40%;
}
.amount {
flex: 50%;
text-align: right;
margin-left: 10px;
}
</style> </style>

View File

@ -6,6 +6,7 @@ export default {
namespaced: true, namespaced: true,
state: { state: {
data_dir: '/home/lafrite/scripts/comptes/data/', data_dir: '/home/lafrite/scripts/comptes/data/',
config_dir: '/home/lafrite/scripts/comptes/config/',
postes_filename: 'postes.yml', postes_filename: 'postes.yml',
postes: {} postes: {}
}, },
@ -13,6 +14,9 @@ export default {
data_dir: (state) => { data_dir: (state) => {
return state.data_dir return state.data_dir
}, },
config_dir: (state) => {
return state.config_dir
},
postes_filename: (state) => { postes_filename: (state) => {
return state.postes_filename return state.postes_filename
}, },
@ -27,7 +31,7 @@ export default {
}, },
actions: { actions: {
async load_postes (context) { async load_postes (context) {
readFile(path.join(context.getters.data_dir, context.getters.postes_filename), 'utf8', (err, content) => { readFile(path.join(context.getters.config_dir, context.getters.postes_filename), 'utf8', (err, content) => {
if (err) { if (err) {
console.log(err) console.log(err)
} else { } else {

View File

@ -26,6 +26,7 @@ export default {
state.csv_files = csvs state.csv_files = csvs
}, },
SET_DATA: (state, { data }) => { SET_DATA: (state, { data }) => {
data.data = data.data.filter(x => x.Libellé != undefined)
state.rows = data state.rows = data
}, },
APPEND_DATA: (state, { content }) => { APPEND_DATA: (state, { content }) => {

View File

@ -13,10 +13,10 @@
</b-container> </b-container>
<b-card-group deck class="mb-3"> <b-card-group deck class="mb-3">
<box postename="total" :rows="filter_rows"></box> <box @click.native="set_poste('total')" postename="total" :rows="date_rows"></box>
<box postename="cash" :rows="filter_rows"></box> <box @click.native="set_poste('cash')" postename="cash" :rows="date_rows"></box>
<box postename="CB" :rows="filter_rows"></box> <box @click.native="set_poste('CB')" postename="CB" :rows="date_rows"></box>
<box postename="other" :rows="filter_rows"></box> <box @click.native="set_poste('other')" postename="other" :rows="date_rows"></box>
</b-card-group> </b-card-group>
<b-table striped hover :items="filter_rows" :fields='fields'></b-table> <b-table striped hover :items="filter_rows" :fields='fields'></b-table>
@ -54,6 +54,7 @@ export default {
} }
], ],
spending: true, spending: true,
poste: {},
start: monthAgo.toISOString().split('T')[0], start: monthAgo.toISOString().split('T')[0],
end: today.toISOString().split('T')[0] end: today.toISOString().split('T')[0]
} }
@ -68,20 +69,19 @@ export default {
'rows': 'datas/rows', 'rows': 'datas/rows',
'postes': 'config/postes' 'postes': 'config/postes'
}), }),
filter_rows () { date_rows () {
return this.filter_date(this.filter_spending(this.rows)) return this.filter_date(this.filter_spending(this.rows))
} },
filter_rows () {
return this.filter_poste(this.date_rows)
},
}, },
methods: { methods: {
table_date_format (date) { table_date_format (date) {
return date return date
}, },
filter_spending (rows) { filter_spending (rows) {
if (this.spending) { return rows.filter(x => x.Montant < 0)
return rows.filter(x => x.Montant < 0)
} else {
return rows
}
}, },
filter_date (rows) { filter_date (rows) {
var start = new Date(this.start) var start = new Date(this.start)
@ -89,6 +89,28 @@ export default {
return rows.filter(x => { return rows.filter(x => {
return (new Date(x.Date) >= start) & (new Date(x.Date) < end) return (new Date(x.Date) >= start) & (new Date(x.Date) < end)
}) })
},
filter_poste (rows) {
if (this.poste.words) {
if (this.poste.invert) {
return rows.filter(x => {
return this.poste.words.every(v => {
return x.Libellé.indexOf(v) < 0
})
})
} else {
return rows.filter(x => {
return this.poste.words.some(v => {
return x.Libellé.indexOf(v) >= 0
})
})
}
} else {
return rows
}
},
set_poste (postename) {
this.poste = this.postes[postename]
} }
} }
} }