From 5c67c5a77da6210c1b8b5864fccb1bf895c95525 Mon Sep 17 00:00:00 2001 From: HamletDuFromage <61667930+HamletDuFromage@users.noreply.github.com> Date: Sun, 24 Mar 2024 06:44:57 +0100 Subject: [PATCH] Add regex toggle for WebUI torrent filtering PR #20566. --- src/webui/www/private/css/style.css | 31 +++++++++++++++++++ src/webui/www/private/images/regex.svg | 1 + src/webui/www/private/index.html | 2 ++ src/webui/www/private/scripts/client.js | 3 ++ src/webui/www/private/scripts/dynamicTable.js | 18 ++++++++--- src/webui/www/webui.qrc | 1 + 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 src/webui/www/private/images/regex.svg diff --git a/src/webui/www/private/css/style.css b/src/webui/www/private/css/style.css index 4387c43a26..0805fef600 100644 --- a/src/webui/www/private/css/style.css +++ b/src/webui/www/private/css/style.css @@ -409,6 +409,37 @@ a.propButton img { padding: 4px 4px 4px 25px; } +#torrentsFilterRegexBox { + display: none; +} + +#torrentsFilterRegexBox + label { + background-image: url("../images/regex.svg"); + background-position: center; + background-repeat: no-repeat; + background-size: 1.5em; + border: 1px solid var(--color-border-default); + border-radius: 4px; + display: inline-block; + height: 26px; + margin-bottom: -9px; + width: 26px; +} + +#torrentsFilterRegexBox:checked + label { + background-color: var(--color-background-default); + background-image: url("../images/regex.svg"); + background-position: center; + background-repeat: no-repeat; + background-size: 1.5em; + border: 1px solid var(--color-accent-blue); + border-radius: 4px; + display: inline-block; + height: 26px; + margin-bottom: -9px; + width: 26px; +} + #torrentFilesFilterToolbar { float: right; margin-right: 30px; diff --git a/src/webui/www/private/images/regex.svg b/src/webui/www/private/images/regex.svg new file mode 100644 index 0000000000..323c23c50c --- /dev/null +++ b/src/webui/www/private/images/regex.svg @@ -0,0 +1 @@ + diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 8ef335539b..9db96fbca3 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -130,6 +130,8 @@

qBittorrent Web User Interface + + diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 0abe49705a..93039ab207 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -1460,6 +1460,9 @@ window.addEventListener("DOMContentLoaded", function() { torrentsTable.updateTable(); }, window.qBittorrent.Misc.FILTER_INPUT_DELAY); }); + $('torrentsFilterRegexBox').addEvent('change', () => { + torrentsTable.updateTable(); + }); $('transfersTabLink').addEvent('click', showTransfersTab); $('searchTabLink').addEvent('click', showSearchTab); diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index ce0e7d2ebc..7f63b8295a 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -1437,9 +1437,16 @@ window.qBittorrent.DynamicTable = (function() { } } - if ((filterTerms !== undefined) && (filterTerms !== null) - && (filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms)) - return false; + if ((filterTerms !== undefined) && (filterTerms !== null)) { + if (filterTerms instanceof RegExp) { + if (!filterTerms.test(name)) + return false; + } + else { + if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms)) + return false; + } + } return true; }, @@ -1471,8 +1478,11 @@ window.qBittorrent.DynamicTable = (function() { const filteredRows = []; const rows = this.rows.getValues(); + const useRegex = $('torrentsFilterRegexBox').checked; const filterText = $('torrentsFilterInput').value.trim().toLowerCase(); - const filterTerms = (filterText.length > 0) ? filterText.split(" ") : null; + const filterTerms = (filterText.length > 0) + ? (useRegex ? new RegExp(filterText) : filterText.split(" ")) + : null; for (let i = 0; i < rows.length; ++i) { if (this.applyFilter(rows[i], selected_filter, selected_category, selectedTag, selectedTracker, filterTerms)) { diff --git a/src/webui/www/webui.qrc b/src/webui/www/webui.qrc index f3cad50443..1670730da6 100644 --- a/src/webui/www/webui.qrc +++ b/src/webui/www/webui.qrc @@ -338,6 +338,7 @@ private/images/queued.svg private/images/ratio.svg private/images/reannounce.svg + private/images/regex.svg private/images/set-location.svg private/images/slider-area.gif private/images/slow.svg