Feat: Tag filtering not on words

This commit is contained in:
Bertrand Benjamin 2018-12-03 10:41:57 +01:00
parent f112e8dc9d
commit 81b3fe241e
4 changed files with 47 additions and 19 deletions

View File

@ -1,10 +1,5 @@
--- ---
postes: postes:
total:
name: Tout
variant: info
icon: file-invoice-dollar
cash: cash:
name: Cash name: Cash
variant: info variant: info

View File

@ -25,6 +25,11 @@ export default {
], ],
data () { data () {
return { return {
default_poste: {
name: 'Tout',
variant: 'info',
icon: 'file-invoice-dollar'
}
} }
}, },
computed: { computed: {
@ -32,15 +37,23 @@ export default {
'postes' 'postes'
]), ]),
...mapGetters('datas', [ ...mapGetters('datas', [
'libelle_filter_rows' 'tag_filter_rows'
]), ]),
poste () { poste () {
if (this.postename) {
return this.postes[this.postename] return this.postes[this.postename]
} else {
return this.default_poste
}
} }
}, },
methods: { methods: {
filter_rows () { filter_rows () {
return this.libelle_filter_rows(this.poste.words, this.poste.invert) if (this.poste === this.default_poste) {
return this.tag_filter_rows([])
} else {
return this.tag_filter_rows([this.poste.name])
}
}, },
total () { total () {
return Math.round( return Math.round(

View File

@ -43,6 +43,18 @@ export default {
return (new Date(x.Date) >= start) & (new Date(x.Date) < end) return (new Date(x.Date) >= start) & (new Date(x.Date) < end)
}) })
}, },
tag_filter_rows: (state, getters) => (tags) => {
if (tags) {
return getters.date_filter_rows.filter(row => {
return tags.every(t => {
return row.tags.map(t => t.name.toLowerCase())
.indexOf(t.toLowerCase()) > -1
})
})
} else {
return getters.date_filter_rows
}
},
libelle_filter_rows: (state, getters) => (words, invert) => { libelle_filter_rows: (state, getters) => (words, invert) => {
if (!words) { if (!words) {
return getters.date_filter_rows return getters.date_filter_rows

View File

@ -15,13 +15,13 @@
</b-container> </b-container>
<b-card-group deck class="mb-3"> <b-card-group deck class="mb-3">
<box @click.native="set_poste('total')" postename="total"></box> <box @click.native="set_postes_filter([])"></box>
<box @click.native="set_poste('cash')" postename="cash"></box> <box @click.native="set_postes_filter(['cash'])" postename="cash"></box>
<box @click.native="set_poste('CB')" postename="CB"></box> <box @click.native="set_postes_filter(['CB'])" postename="CB"></box>
<box @click.native="set_poste('other')" postename="other"></box> <box @click.native="set_postes_filter(['other'])" postename="other"></box>
</b-card-group> </b-card-group>
<b-table striped hover :items="filtered_rows(poste.words, poste.invert)" :fields='fields'> <b-table striped hover :items="filtered_rows" :fields='fields'>
<template slot="tags" slot-scope="data"> <template slot="tags" slot-scope="data">
<div v-for="tag in data.item.tags"> <div v-for="tag in data.item.tags">
<div v-if="tag.name !== 'Tout'"> <div v-if="tag.name !== 'Tout'">
@ -60,10 +60,14 @@ export default {
}, },
{ {
key: 'tags', key: 'tags',
sortable: true
} }
], ],
poste: {} default_poste: {
name: 'Tout',
variant: 'info',
icon: 'file-invoice-dollar'
},
postes_filter: []
} }
}, },
mounted: function () { mounted: function () {
@ -73,11 +77,15 @@ export default {
computed: { computed: {
...mapGetters({ ...mapGetters({
'csvs': 'datas/csvs', 'csvs': 'datas/csvs',
'filtered_rows': 'datas/libelle_filter_rows', 'tag_filter_rows': 'datas/tag_filter_rows',
'start': 'datas/start', 'start': 'datas/start',
'end': 'datas/end', 'end': 'datas/end',
'postes': 'config/postes' 'postes': 'config/postes'
}) }),
filtered_rows () {
return this.tag_filter_rows(this.postes_filter)
}
}, },
methods: { methods: {
...mapActions('datas', [ ...mapActions('datas', [
@ -89,8 +97,8 @@ export default {
table_date_format (date) { table_date_format (date) {
return date return date
}, },
set_poste (postename) { set_postes_filter (postenames) {
this.poste = this.postes[postename] this.postes_filter = postenames
} }
} }
} }