Feat: Tag rows before storing them in vuex

This commit is contained in:
2018-12-03 09:49:36 +01:00
parent 4c7523dbb8
commit 697435de30
3 changed files with 52 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
export function appendTag (row, keywords, field='Libellé') {
// Append row.tag
// 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'] =
row.tags = keywords.filter(k => {
return strContains(row[field], k.words, k.invert)
})
}
function strContains (string, words, invert) {
// Does a string contain one of words or the opposite
if (!words) {
return true
}
if (invert) {
return words.every(v => {
return string.indexOf(v) < 0
})
} else {
return words.some(v => {
return string.indexOf(v) >= 0
})
}
}