Skip to content

Commit

Permalink
Add regex toggle for WEBUI torrent filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletDuFromage committed Mar 17, 2024
1 parent d7aaf80 commit 8560fb2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
31 changes: 31 additions & 0 deletions src/webui/www/private/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,37 @@ a.propButton img {
padding: 4px 4px 4px 25px;
}

#torrentsFilterRegexBox {
display:none;
}

#torrentsFilterRegexBox + label {
display:inline-block;
height: 26px;
width: 26px;
margin-bottom: -9px;
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;
}

#torrentsFilterRegexBox:checked + label {
display:inline-block;
height: 26px;
width: 26px;
margin-bottom: -9px;
background-image: url("../images/regex.svg");
background-position: center;
background-repeat: no-repeat;
background-size: 1.5em;
background-color: var(--color-background-default);
border: 1px solid var(--color-accent-blue);
border-radius: 4px;
}

#torrentFilesFilterToolbar {
float: right;
margin-right: 30px;
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/private/images/regex.svg
Loading
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
Original file line number Diff line number Diff line change
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">
</div>
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/webui/www/private/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,13 @@ window.addEventListener("DOMContentLoaded", function() {
torrentsTable.updateTable();
}, window.qBittorrent.Misc.FILTER_INPUT_DELAY);
});
$('torrentsFilterRegexBox').addEvent('change', () => {
clearTimeout(torrentsFilterInputTimer);
torrentsFilterInputTimer = setTimeout(() => {
torrentsFilterInputTimer = -1;
torrentsTable.updateTable();
}, window.qBittorrent.Misc.FILTER_INPUT_DELAY);
});

$('transfersTabLink').addEvent('click', showTransfersTab);
$('searchTabLink').addEvent('click', showSearchTab);
Expand Down
23 changes: 18 additions & 5 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1437,10 +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 (Array.isArray(filterTerms)) {
if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms))
return false;
}
else { // regex search
if (!filterTerms.test(name))
return false;
}
}
return true;
},

Expand Down Expand Up @@ -1471,8 +1477,15 @@ window.qBittorrent.DynamicTable = (function() {
const filteredRows = [];

const rows = this.rows.getValues();
const torrentsFilterRegex = $('torrentsFilterRegexBox').checked;
const filterText = $('torrentsFilterInput').value.trim().toLowerCase();
const filterTerms = (filterText.length > 0) ? filterText.split(" ") : null;
let filterTerms;
if (torrentsFilterRegex) {
filterTerms = (filterText.length > 0) ? new RegExp(filterText) : null;
}
else {
filterTerms = (filterText.length > 0) ? 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
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@
<file>private/images/torrent-start.svg</file>
<file>private/images/torrent-stop.svg</file>
<file>private/images/trackers.svg</file>
<file>private/images/regex.svg</file>
<file>private/images/upload.svg</file>
<file>private/images/view-categories.svg</file>
<file>private/images/view-refresh.svg</file>
Expand Down

0 comments on commit 8560fb2

Please sign in to comment.