WebUI: Don't sort rows with static trackers in Trackers table

Static trackers come before anything else so in this PR I made sure they are not moved when sorting Trackers table columns.

PR #21609.
This commit is contained in:
skomerko 2024-10-27 07:54:33 +01:00 committed by GitHub
parent e8dc6b3f73
commit 67b6cf5a6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 52 additions and 1 deletions

View file

@ -1899,7 +1899,57 @@ window.qBittorrent.DynamicTable ??= (() => {
this.newColumn("leeches", "", "QBT_TR(Leeches)QBT_TR[CONTEXT=TrackerListWidget]", 75, true); this.newColumn("leeches", "", "QBT_TR(Leeches)QBT_TR[CONTEXT=TrackerListWidget]", 75, true);
this.newColumn("downloaded", "", "QBT_TR(Times Downloaded)QBT_TR[CONTEXT=TrackerListWidget]", 100, true); this.newColumn("downloaded", "", "QBT_TR(Times Downloaded)QBT_TR[CONTEXT=TrackerListWidget]", 100, true);
this.newColumn("message", "", "QBT_TR(Message)QBT_TR[CONTEXT=TrackerListWidget]", 250, true); this.newColumn("message", "", "QBT_TR(Message)QBT_TR[CONTEXT=TrackerListWidget]", 250, true);
this.initColumnsFunctions();
}, },
initColumnsFunctions: function() {
const naturalSort = function(row1, row2) {
if (!row1.full_data._sortable || !row2.full_data._sortable)
return 0;
const value1 = this.getRowValue(row1);
const value2 = this.getRowValue(row2);
return window.qBittorrent.Misc.naturalSortCollator.compare(value1, value2);
};
this.columns["url"].compareRows = naturalSort;
this.columns["status"].compareRows = naturalSort;
this.columns["message"].compareRows = naturalSort;
const sortNumbers = function(row1, row2) {
if (!row1.full_data._sortable || !row2.full_data._sortable)
return 0;
const value1 = this.getRowValue(row1);
const value2 = this.getRowValue(row2);
if (value1 === "")
return -1;
if (value2 === "")
return 1;
return compareNumbers(value1, value2);
};
this.columns["tier"].compareRows = sortNumbers;
const sortMixed = function(row1, row2) {
if (!row1.full_data._sortable || !row2.full_data._sortable)
return 0;
const value1 = this.getRowValue(row1);
const value2 = this.getRowValue(row2);
if (value1 === "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]")
return -1;
if (value2 === "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]")
return 1;
return compareNumbers(value1, value2);
};
this.columns["peers"].compareRows = sortMixed;
this.columns["seeds"].compareRows = sortMixed;
this.columns["leeches"].compareRows = sortMixed;
this.columns["downloaded"].compareRows = sortMixed;
}
}); });
const BulkRenameTorrentFilesTable = new Class({ const BulkRenameTorrentFilesTable = new Class({

View file

@ -101,7 +101,8 @@ window.qBittorrent.PropTrackers ??= (() => {
seeds: (tracker.num_seeds >= 0) ? tracker.num_seeds : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]", seeds: (tracker.num_seeds >= 0) ? tracker.num_seeds : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
leeches: (tracker.num_leeches >= 0) ? tracker.num_leeches : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]", leeches: (tracker.num_leeches >= 0) ? tracker.num_leeches : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
downloaded: (tracker.num_downloaded >= 0) ? tracker.num_downloaded : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]", downloaded: (tracker.num_downloaded >= 0) ? tracker.num_downloaded : "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]",
message: tracker.msg message: tracker.msg,
_sortable: !tracker.url.startsWith("** [")
}; };
torrentTrackersTable.updateRowData(row); torrentTrackersTable.updateRowData(row);