Fix(Categorie): filter table on categories
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import moment from 'moment'
|
||||
export function appendTag (row, keywords, field = 'Libellé') {
|
||||
// Append row.tag
|
||||
export function appendKeywordField (row, toField, keywords, fromField = 'Libellé') {
|
||||
// Append row[toField] base on keywords
|
||||
// if row.libellé contains one of words and not invert it gets tagged
|
||||
// if row.libellé contains no words and invert it gets tagged
|
||||
// according to keywords [{name: string, words: [], invert: bool}]
|
||||
row.tags = keywords.filter(k => {
|
||||
return strContains(row[field], k.words, k.invert)
|
||||
row[toField] = keywords.filter(k => {
|
||||
return strContains(row[fromField], k.words, k.invert)
|
||||
})
|
||||
}
|
||||
|
||||
function strContains (string, words, invert) {
|
||||
// Does a string contain one of words or the opposite
|
||||
if (!words) {
|
||||
if (words.length === 0) {
|
||||
return true
|
||||
}
|
||||
if (invert) {
|
||||
@@ -35,19 +35,19 @@ export function total (rows, field = 'Montant') {
|
||||
return Math.round(sum)
|
||||
}
|
||||
|
||||
export function tagFilter (rows, tags, invert = false) {
|
||||
// filter rows by tags
|
||||
export function keywordFilter (rows, field, keywords, invert = false) {
|
||||
// filter rows by keywords in rows[field]
|
||||
// invert inverts the selection
|
||||
return rows.filter(row => {
|
||||
if (invert) {
|
||||
return tags.some(t => {
|
||||
return row.tags.map(t => t.name.toLowerCase())
|
||||
.indexOf(t.toLowerCase()) < 0
|
||||
return keywords.some(kwd => {
|
||||
return row[field].map(k => k.name.toLowerCase())
|
||||
.indexOf(kwd.toLowerCase()) < 0
|
||||
})
|
||||
} else {
|
||||
return tags.every(t => {
|
||||
return row.tags.map(t => t.name.toLowerCase())
|
||||
.indexOf(t.toLowerCase()) > -1
|
||||
return keywords.every(kwd => {
|
||||
return row[field].map(k => k.name.toLowerCase())
|
||||
.indexOf(kwd.toLowerCase()) > -1
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user