Skip to content

Commit

Permalink
Add regex toggle for WebUI torrent filtering
Browse files Browse the repository at this point in the history
PR #20566.
  • Loading branch information
HamletDuFromage committed Mar 24, 2024
1 parent ce013f1 commit 5c67c5a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
31 changes: 31 additions & 0 deletions src/webui/www/private/css/style.css
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/private/images/regex.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/webui/www/private/index.html
Expand Up @@ -130,6 +130,8 @@ <h1 class="applicationTitle">qBittorrent Web User Interface <span class="version
</div>
<div id="torrentsFilterToolbar">
<input type="text" id="torrentsFilterInput" placeholder="QBT_TR(Filter torrent list...)QBT_TR[CONTEXT=MainWindow]" autocorrect="off" autocapitalize="none" />
<input type="checkbox" id="torrentsFilterRegexBox">
<label for="torrentsFilterRegexBox"></label>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions src/webui/www/private/scripts/client.js
Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions src/webui/www/private/scripts/dynamicTable.js
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/webui.qrc
Expand Up @@ -338,6 +338,7 @@
<file>private/images/queued.svg</file>
<file>private/images/ratio.svg</file>
<file>private/images/reannounce.svg</file>
<file>private/images/regex.svg</file>
<file>private/images/set-location.svg</file>
<file>private/images/slider-area.gif</file>
<file>private/images/slow.svg</file>
Expand Down

0 comments on commit 5c67c5a

Please sign in to comment.