WebUI: Allow to filter torrent list by save path

This PR adds ability to filter torrent list by save path. Everything should work exactly like in GUI.

Closes #19393.
PR #21175.
This commit is contained in:
skomerko 2024-08-11 10:08:13 +02:00 committed by GitHub
parent ea06eb9fe6
commit 04eb40376e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 6 deletions

View file

@ -449,6 +449,10 @@ a.propButton img {
width: 26px; width: 26px;
} }
#torrentsFilterSelect {
padding: 2px 4px;
}
#torrentFilesFilterToolbar { #torrentFilesFilterToolbar {
float: right; float: right;
margin-right: 30px; margin-right: 30px;

View file

@ -133,6 +133,11 @@
<input type="text" id="torrentsFilterInput" placeholder="QBT_TR(Filter torrent list...)QBT_TR[CONTEXT=MainWindow]" aria-label="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]" aria-label="QBT_TR(Filter torrent list...)QBT_TR[CONTEXT=MainWindow]" autocorrect="off" autocapitalize="none">
<input type="checkbox" id="torrentsFilterRegexBox"> <input type="checkbox" id="torrentsFilterRegexBox">
<label for="torrentsFilterRegexBox" aria-label="QBT_TR(Use regular expressions)QBT_TR[CONTEXT=MainWindow]"></label> <label for="torrentsFilterRegexBox" aria-label="QBT_TR(Use regular expressions)QBT_TR[CONTEXT=MainWindow]"></label>
<label for="torrentsFilterSelect">QBT_TR(Filter by:)QBT_TR[CONTEXT=MainWindow]</label>
<select id="torrentsFilterSelect">
<option value="name" selected>QBT_TR(Name)QBT_TR[CONTEXT=MainWindow]</option>
<option value="save_path">QBT_TR(Save Path)QBT_TR[CONTEXT=MainWindow]</option>
</select>
</div> </div>
</div> </div>
</div> </div>

View file

@ -1563,9 +1563,8 @@ window.addEventListener("DOMContentLoaded", () => {
torrentsTable.updateTable(); torrentsTable.updateTable();
}, window.qBittorrent.Misc.FILTER_INPUT_DELAY); }, window.qBittorrent.Misc.FILTER_INPUT_DELAY);
}); });
$("torrentsFilterRegexBox").addEventListener("change", () => {
torrentsTable.updateTable(); document.getElementById("torrentsFilterToolbar").addEventListener("change", (e) => { torrentsTable.updateTable(); });
});
$("transfersTabLink").addEventListener("click", showTransfersTab); $("transfersTabLink").addEventListener("click", showTransfersTab);
$("searchTabLink").addEventListener("click", showSearchTab); $("searchTabLink").addEventListener("click", showSearchTab);

View file

@ -1357,7 +1357,6 @@ window.qBittorrent.DynamicTable ??= (() => {
applyFilter: function(row, filterName, categoryHash, tagHash, trackerHash, filterTerms) { applyFilter: function(row, filterName, categoryHash, tagHash, trackerHash, filterTerms) {
const state = row["full_data"].state; const state = row["full_data"].state;
const name = row["full_data"].name.toLowerCase();
let inactive = false; let inactive = false;
switch (filterName) { switch (filterName) {
@ -1487,12 +1486,14 @@ window.qBittorrent.DynamicTable ??= (() => {
} }
if ((filterTerms !== undefined) && (filterTerms !== null)) { if ((filterTerms !== undefined) && (filterTerms !== null)) {
const filterBy = document.getElementById("torrentsFilterSelect").value;
const textToSearch = row["full_data"][filterBy].toLowerCase();
if (filterTerms instanceof RegExp) { if (filterTerms instanceof RegExp) {
if (!filterTerms.test(name)) if (!filterTerms.test(textToSearch))
return false; return false;
} }
else { else {
if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(name, filterTerms)) if ((filterTerms.length > 0) && !window.qBittorrent.Misc.containsAllTerms(textToSearch, filterTerms))
return false; return false;
} }
} }