Add regex toggle for WebUI torrent filtering

PR #20566.
This commit is contained in:
HamletDuFromage 2024-03-24 06:44:57 +01:00 committed by GitHub
parent ce013f132f
commit 5c67c5a77d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 52 additions and 4 deletions

View file

@ -409,6 +409,37 @@ a.propButton img {
padding: 4px 4px 4px 25px; 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 { #torrentFilesFilterToolbar {
float: right; float: right;
margin-right: 30px; margin-right: 30px;

View file

@ -0,0 +1 @@
<svg height="32" viewBox="0 0 32 32" width="32" xmlns="http://www.w3.org/2000/svg"><path d="M 19.355469 21.824219 L 19.355469 14.433594 L 13.265625 18.164062 L 11.117188 14.425781 L 17.472656 10.945312 L 11.117188 7.417969 L 13.277344 3.746094 L 19.355469 7.460938 L 19.355469 0.0390625 L 23.695312 0.0390625 L 23.695312 7.460938 L 29.828125 3.746094 L 32 7.417969 L 25.617188 10.945312 L 32 14.425781 L 29.820312 18.179688 L 23.695312 14.433594 L 23.695312 21.824219 Z M 9.074219 27.425781 C 9.074219 23.945312 5.28125 21.757812 2.261719 23.5 C -0.753906 25.238281 -0.753906 29.609375 2.261719 31.351562 C 5.28125 33.089844 9.074219 30.902344 9.074219 27.425781 Z M 9.074219 27.425781" fill="#1e90ff"/></svg>

After

Width:  |  Height:  |  Size: 710 B

View file

@ -130,6 +130,8 @@
</div> </div>
<div id="torrentsFilterToolbar"> <div id="torrentsFilterToolbar">
<input type="text" id="torrentsFilterInput" placeholder="QBT_TR(Filter torrent list...)QBT_TR[CONTEXT=MainWindow]" autocorrect="off" autocapitalize="none" /> <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> </div>
</div> </div>

View file

@ -1460,6 +1460,9 @@ window.addEventListener("DOMContentLoaded", function() {
torrentsTable.updateTable(); torrentsTable.updateTable();
}, window.qBittorrent.Misc.FILTER_INPUT_DELAY); }, window.qBittorrent.Misc.FILTER_INPUT_DELAY);
}); });
$('torrentsFilterRegexBox').addEvent('change', () => {
torrentsTable.updateTable();
});
$('transfersTabLink').addEvent('click', showTransfersTab); $('transfersTabLink').addEvent('click', showTransfersTab);
$('searchTabLink').addEvent('click', showSearchTab); $('searchTabLink').addEvent('click', showSearchTab);

View file

@ -1437,9 +1437,16 @@ window.qBittorrent.DynamicTable = (function() {
} }
} }
if ((filterTerms !== undefined) && (filterTerms !== null) if ((filterTerms !== undefined) && (filterTerms !== null)) {
&& (filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms)) if (filterTerms instanceof RegExp) {
if (!filterTerms.test(name))
return false; return false;
}
else {
if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms))
return false;
}
}
return true; return true;
}, },
@ -1471,8 +1478,11 @@ window.qBittorrent.DynamicTable = (function() {
const filteredRows = []; const filteredRows = [];
const rows = this.rows.getValues(); const rows = this.rows.getValues();
const useRegex = $('torrentsFilterRegexBox').checked;
const filterText = $('torrentsFilterInput').value.trim().toLowerCase(); 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) { for (let i = 0; i < rows.length; ++i) {
if (this.applyFilter(rows[i], selected_filter, selected_category, selectedTag, selectedTracker, filterTerms)) { if (this.applyFilter(rows[i], selected_filter, selected_category, selectedTag, selectedTracker, filterTerms)) {

View file

@ -338,6 +338,7 @@
<file>private/images/queued.svg</file> <file>private/images/queued.svg</file>
<file>private/images/ratio.svg</file> <file>private/images/ratio.svg</file>
<file>private/images/reannounce.svg</file> <file>private/images/reannounce.svg</file>
<file>private/images/regex.svg</file>
<file>private/images/set-location.svg</file> <file>private/images/set-location.svg</file>
<file>private/images/slider-area.gif</file> <file>private/images/slider-area.gif</file>
<file>private/images/slow.svg</file> <file>private/images/slow.svg</file>