Browse Source

Merge pull request #10928 from Piccirello/webui-search-filter

Support exclusions in WebUI table filters
adaptive-webui-19844
Vladimir Golovnev 5 years ago committed by GitHub
parent
commit
2d28f50acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      src/webui/www/private/scripts/dynamicTable.js
  2. 34
      src/webui/www/private/scripts/misc.js

30
src/webui/www/private/scripts/dynamicTable.js

@ -1274,12 +1274,9 @@ const TorrentsTable = new Class({ @@ -1274,12 +1274,9 @@ const TorrentsTable = new Class({
}
}
if (filterTerms) {
for (let i = 0; i < filterTerms.length; ++i) {
if (name.indexOf(filterTerms[i]) === -1)
return false;
}
}
if ((filterTerms !== undefined) && (filterTerms !== null)
&& (filterTerms.length > 0) && !containsAllTerms(name, filterTerms))
return false;
return true;
},
@ -1523,16 +1520,6 @@ const SearchResultsTable = new Class({ @@ -1523,16 +1520,6 @@ const SearchResultsTable = new Class({
},
getFilteredAndSortedRows: function() {
const containsAll = function(text, searchTerms) {
text = text.toLowerCase();
for (let i = 0; i < searchTerms.length; ++i) {
if (text.indexOf(searchTerms[i].toLowerCase()) === -1)
return false;
}
return true;
};
const getSizeFilters = function() {
let minSize = (searchSizeFilter.min > 0.00) ? (searchSizeFilter.min * Math.pow(1024, searchSizeFilter.minUnit)) : 0.00;
let maxSize = (searchSizeFilter.max > 0.00) ? (searchSizeFilter.max * Math.pow(1024, searchSizeFilter.maxUnit)) : 0.00;
@ -1577,8 +1564,8 @@ const SearchResultsTable = new Class({ @@ -1577,8 +1564,8 @@ const SearchResultsTable = new Class({
for (let i = 0; i < rows.length; ++i) {
const row = rows[i];
if (searchInTorrentName && !containsAll(row.full_data.fileName, searchTerms)) continue;
if ((filterTerms.length > 0) && !containsAll(row.full_data.fileName, filterTerms)) continue;
if (searchInTorrentName && !containsAllTerms(row.full_data.fileName, searchTerms)) continue;
if ((filterTerms.length > 0) && !containsAllTerms(row.full_data.fileName, filterTerms)) continue;
if ((sizeFilters.min > 0.00) && (row.full_data.fileSize < sizeFilters.min)) continue;
if ((sizeFilters.max > 0.00) && (row.full_data.fileSize > sizeFilters.max)) continue;
if ((seedsFilters.min > 0) && (row.full_data.nbSeeders < seedsFilters.min)) continue;
@ -1913,12 +1900,7 @@ const TorrentFilesTable = new Class({ @@ -1913,12 +1900,7 @@ const TorrentFilesTable = new Class({
}
}
const lowercaseName = node.name.toLowerCase();
const matchesFilter = filterTerms.every(function(term) {
return (lowercaseName.indexOf(term) !== -1);
});
if (matchesFilter) {
if (containsAllTerms(node.name, filterTerms)) {
const row = this.getRow(node);
filteredRows.push(row);
return true;

34
src/webui/www/private/scripts/misc.js

@ -167,3 +167,37 @@ function toFixedPointString(number, digits) { @@ -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;
}

Loading…
Cancel
Save