Support exclusions in WebUI table filters

Closes #10241
This commit is contained in:
Thomas Piccirello 2019-07-14 21:34:12 -07:00
parent c65c40a5cb
commit b829a0c687
2 changed files with 40 additions and 24 deletions

View file

@ -167,3 +167,37 @@ function toFixedPointString(number, digits) {
const power = Math.pow(10, digits);
return (Math.floor(power * number) / power).toFixed(digits);
}
/**
*
* @param {String} text the text to search
* @param {Array<String>} terms terms to search for within the text
* @returns {Boolean} true if all terms match the text, false otherwise
*/
function containsAllTerms(text, terms) {
const textToSearch = text.toLowerCase();
for (let i = 0; i < terms.length; ++i) {
const term = terms[i].trim().toLowerCase();
if ((term[0] === '-')) {
// ignore lonely -
if (term.length === 1)
continue;
// disallow any text after -
if (textToSearch.indexOf(term.substring(1)) !== -1)
return false;
}
else if ((term[0] === '+')) {
// ignore lonely +
if (term.length === 1)
continue;
// require any text after +
if (textToSearch.indexOf(term.substring(1)) === -1)
return false;
}
else if (textToSearch.indexOf(term) === -1){
return false;
}
}
return true;
}