From 7031c52d16dc3f3405ee7987be9d6bdf3c4a8c1f Mon Sep 17 00:00:00 2001 From: skomerko <168652295+skomerko@users.noreply.github.com> Date: Sat, 19 Oct 2024 10:25:30 +0200 Subject: [PATCH] WebUI: Improve sort order in Status column This commit adds custom compare function to Status column (same sort order as in the GUI). Closes #15499. PR #21570. --- src/webui/www/private/scripts/client.js | 29 +++++++++++++++++-- src/webui/www/private/scripts/dynamicTable.js | 4 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/webui/www/private/scripts/client.js b/src/webui/www/private/scripts/client.js index 83db30de8..c122e1757 100644 --- a/src/webui/www/private/scripts/client.js +++ b/src/webui/www/private/scripts/client.js @@ -672,6 +672,28 @@ window.addEventListener("DOMContentLoaded", () => { tracker.classList.toggle("selectedFilter", (Number(tracker.id) === selectedTracker)); }; + const statusSortOrder = Object.freeze({ + "unknown": -1, + "forcedDL": 0, + "downloading": 1, + "forcedMetaDL": 2, + "metaDL": 3, + "stalledDL": 4, + "forcedUP": 5, + "uploading": 6, + "stalledUP": 7, + "checkingResumeData": 8, + "queuedDL": 9, + "queuedUP": 10, + "checkingUP": 11, + "checkingDL": 12, + "stoppedDL": 13, + "stoppedUP": 14, + "moving": 15, + "missingFiles": 16, + "error": 17 + }); + let syncMainDataTimeoutID = -1; let syncRequestInProgress = false; const syncMainData = function() { @@ -800,8 +822,11 @@ window.addEventListener("DOMContentLoaded", () => { response["torrents"][key]["hash"] = key; response["torrents"][key]["rowId"] = key; - if (response["torrents"][key]["state"]) - response["torrents"][key]["status"] = response["torrents"][key]["state"]; + if (response["torrents"][key]["state"]) { + const state = response["torrents"][key]["state"]; + response["torrents"][key]["status"] = state; + response["torrents"][key]["_statusOrder"] = statusSortOrder[state]; + } torrentsTable.updateRowData(response["torrents"][key]); if (addTorrentToCategoryList(response["torrents"][key])) update_categories = true; diff --git a/src/webui/www/private/scripts/dynamicTable.js b/src/webui/www/private/scripts/dynamicTable.js index 03db2b2c6..e34611eec 100644 --- a/src/webui/www/private/scripts/dynamicTable.js +++ b/src/webui/www/private/scripts/dynamicTable.js @@ -1102,6 +1102,10 @@ window.qBittorrent.DynamicTable ??= (() => { td.title = status; }; + this.columns["status"].compareRows = function(row1, row2) { + return compareNumbers(row1.full_data._statusOrder, row2.full_data._statusOrder); + }; + // priority this.columns["priority"].updateTd = function(td, row) { const queuePos = this.getRowValue(row);