Compare commits

...

3 Commits

Author SHA1 Message Date
Thomas Piccirello
06756936f3 WebUI: Always show Auto Torrent Management option
This behavior is consistent with the GUI.

Closes #22702.
PR #22819.
2025-06-09 21:31:46 +08:00
Thomas Piccirello
7ed026ef78 WebUI: Reset filter selection when double clicking filter
When double clicking on a filter, all other filters will be reset. For example, double clicking on a status filter will reset the categories, tags, and trackers filters to "All". This behavior can be disabled in WebUI options.

Closes #22449.
PR #22818.
2025-06-09 21:24:58 +08:00
Thomas Piccirello
78fae0ae76 WebUI: Cache server stats for statistics window
This change ensures that the WebUI caches relevant server stats for immediate display once the statistics window is opened. Previously, all stats would remain blank until maindata was fetched. This could take a while if e.g. the user was on the search tab.

Closes #22764.
PR #22817.
2025-06-09 21:17:30 +08:00
8 changed files with 158 additions and 33 deletions

View File

@@ -42,6 +42,7 @@
<script defer src="scripts/client.js?locale=${LANG}&v=${CACHEID}"></script>
<script defer src="scripts/contextmenu.js?locale=${LANG}&v=${CACHEID}"></script>
<script defer src="scripts/pathAutofill.js?v=${CACHEID}"></script>
<script defer src="scripts/statistics.js?v=${CACHEID}"></script>
</head>
<body>

View File

@@ -490,7 +490,7 @@ window.addEventListener("DOMContentLoaded", (event) => {
updateFilter("moving", "QBT_TR(Moving (%1))QBT_TR[CONTEXT=StatusFilterWidget]");
updateFilter("errored", "QBT_TR(Errored (%1))QBT_TR[CONTEXT=StatusFilterWidget]");
if (useAutoHideZeroStatusFilters && document.getElementById(`${selectedStatus}_filter`).classList.contains("invisible"))
setStatusFilter("all");
window.qBittorrent.Filters.clearStatusFilter();
};
const highlightSelectedStatus = () => {
@@ -1046,20 +1046,8 @@ window.addEventListener("DOMContentLoaded", (event) => {
}
// Statistics dialog
if (document.getElementById("statisticsContent")) {
document.getElementById("AlltimeDL").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.alltime_dl, false);
document.getElementById("AlltimeUL").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.alltime_ul, false);
document.getElementById("TotalWastedSession").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.total_wasted_session, false);
document.getElementById("GlobalRatio").textContent = serverState.global_ratio;
document.getElementById("TotalPeerConnections").textContent = serverState.total_peer_connections;
document.getElementById("ReadCacheHits").textContent = `${serverState.read_cache_hits}%`;
document.getElementById("TotalBuffersSize").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.total_buffers_size, false);
document.getElementById("WriteCacheOverload").textContent = `${serverState.write_cache_overload}%`;
document.getElementById("ReadCacheOverload").textContent = `${serverState.read_cache_overload}%`;
document.getElementById("QueuedIOJobs").textContent = serverState.queued_io_jobs;
document.getElementById("AverageTimeInQueue").textContent = `${serverState.average_time_queue} ms`;
document.getElementById("TotalQueuedSize").textContent = window.qBittorrent.Misc.friendlyUnit(serverState.total_queued_size, false);
}
window.qBittorrent.Statistics.save(serverState);
window.qBittorrent.Statistics.render();
switch (serverState.connection_status) {
case "connected":

View File

@@ -331,7 +331,6 @@ window.qBittorrent.ContextMenu ??= (() => {
let there_are_force_start = false;
let all_are_super_seeding = true;
let all_are_auto_tmm = true;
let there_are_auto_tmm = false;
let thereAreV1Hashes = false;
let thereAreV2Hashes = false;
const tagCount = new Map();
@@ -366,9 +365,7 @@ window.qBittorrent.ContextMenu ??= (() => {
else
there_are_force_start = true;
if (data["auto_tmm"] === true)
there_are_auto_tmm = true;
else
if (data["auto_tmm"] !== true)
all_are_auto_tmm = false;
if (data["infohash_v1"] !== "")
@@ -446,13 +443,7 @@ window.qBittorrent.ContextMenu ??= (() => {
else if (!there_are_stopped && !there_are_force_start)
this.hideItem("start");
if (!all_are_auto_tmm && there_are_auto_tmm) {
this.hideItem("autoTorrentManagement");
}
else {
this.showItem("autoTorrentManagement");
this.setItemChecked("autoTorrentManagement", all_are_auto_tmm);
}
this.setItemChecked("autoTorrentManagement", all_are_auto_tmm);
this.setEnabled("copyInfohash1", thereAreV1Hashes);
this.setEnabled("copyInfohash2", thereAreV2Hashes);

View File

@@ -492,7 +492,10 @@ const initializeWindows = () => {
height: loadWindowHeight(id, 415),
onResize: window.qBittorrent.Misc.createDebounceHandler(500, (e) => {
saveWindowSize(id);
})
}),
onContentLoaded: () => {
window.qBittorrent.Statistics.render();
}
});
};
@@ -967,7 +970,7 @@ const initializeWindows = () => {
if (!response.ok)
return;
setCategoryFilter(CATEGORIES_ALL);
window.qBittorrent.Filters.clearCategoryFilter();
updateMainData();
});
};
@@ -988,7 +991,7 @@ const initializeWindows = () => {
if (!response.ok)
return;
setCategoryFilter(CATEGORIES_ALL);
window.qBittorrent.Filters.clearCategoryFilter();
updateMainData();
});
};
@@ -1074,7 +1077,7 @@ const initializeWindows = () => {
tags: tag
})
});
setTagFilter(TAGS_ALL);
window.qBittorrent.Filters.clearTagFilter();
};
deleteUnusedTagsFN = () => {
@@ -1089,7 +1092,7 @@ const initializeWindows = () => {
tags: tags.join(",")
})
});
setTagFilter(TAGS_ALL);
window.qBittorrent.Filters.clearTagFilter();
};
deleteTrackerFN = (trackerHost) => {
@@ -1118,7 +1121,7 @@ const initializeWindows = () => {
height: 100,
onCloseComplete: () => {
updateMainData();
setTrackerFilter(TRACKERS_ALL);
window.qBittorrent.Filters.clearTrackerFilter();
}
});
};

View File

@@ -0,0 +1,85 @@
/*
* MIT License
* Copyright (C) 2025 Thomas Piccirello <thomas@piccirello.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
"use strict";
window.qBittorrent ??= {};
window.qBittorrent.Statistics ??= (() => {
const exports = () => {
return {
save: save,
render: render,
};
};
const statistics = {
alltimeDL: 0,
alltimeUL: 0,
totalWastedSession: 0,
globalRatio: 0,
totalPeerConnections: 0,
readCacheHits: 0,
totalBuffersSize: 0,
writeCacheOverload: 0,
readCacheOverload: 0,
queuedIOJobs: 0,
averageTimeInQueue: 0,
totalQueuedSize: 0,
};
const save = (serverState) => {
statistics.alltimeDL = serverState.alltime_dl;
statistics.alltimeUL = serverState.alltime_ul;
statistics.totalWastedSession = serverState.total_wasted_session;
statistics.globalRatio = serverState.global_ratio;
statistics.totalPeerConnections = serverState.total_peer_connections;
statistics.readCacheHits = serverState.read_cache_hits;
statistics.totalBuffersSize = serverState.total_buffers_size;
statistics.writeCacheOverload = serverState.write_cache_overload;
statistics.readCacheOverload = serverState.read_cache_overload;
statistics.queuedIOJobs = serverState.queued_io_jobs;
statistics.averageTimeInQueue = serverState.average_time_queue;
statistics.totalQueuedSize = serverState.total_queued_size;
};
const render = () => {
if (!document.getElementById("statisticsContent"))
return;
document.getElementById("AlltimeDL").textContent = window.qBittorrent.Misc.friendlyUnit(statistics.alltimeDL, false);
document.getElementById("AlltimeUL").textContent = window.qBittorrent.Misc.friendlyUnit(statistics.alltimeUL, false);
document.getElementById("TotalWastedSession").textContent = window.qBittorrent.Misc.friendlyUnit(statistics.totalWastedSession, false);
document.getElementById("GlobalRatio").textContent = statistics.globalRatio;
document.getElementById("TotalPeerConnections").textContent = statistics.totalPeerConnections;
document.getElementById("ReadCacheHits").textContent = `${statistics.readCacheHits}%`;
document.getElementById("TotalBuffersSize").textContent = window.qBittorrent.Misc.friendlyUnit(statistics.totalBuffersSize, false);
document.getElementById("WriteCacheOverload").textContent = `${statistics.writeCacheOverload}%`;
document.getElementById("ReadCacheOverload").textContent = `${statistics.readCacheOverload}%`;
document.getElementById("QueuedIOJobs").textContent = statistics.queuedIOJobs;
document.getElementById("AverageTimeInQueue").textContent = `${statistics.averageTimeInQueue} ms`;
document.getElementById("TotalQueuedSize").textContent = window.qBittorrent.Misc.friendlyUnit(statistics.totalQueuedSize, false);
};
return exports();
})();
Object.freeze(window.qBittorrent.Statistics);

View File

@@ -74,7 +74,11 @@
return {
categoriesFilterContextMenu: categoriesFilterContextMenu,
tagsFilterContextMenu: tagsFilterContextMenu,
trackersFilterContextMenu: trackersFilterContextMenu
trackersFilterContextMenu: trackersFilterContextMenu,
clearStatusFilter: clearStatusFilter,
clearCategoryFilter: clearCategoryFilter,
clearTagFilter: clearTagFilter,
clearTrackerFilter: clearTrackerFilter
};
};
@@ -256,6 +260,42 @@
}
});
document.getElementById("Filters_pad").addEventListener("dblclick", (event) => {
if (LocalPreferences.get("dblclick_filter", "1") !== "1")
return;
const filterItem = event.target.closest("li");
if (filterItem === null)
return;
const { id: filterListID } = filterItem.closest("ul[id]");
switch (filterListID) {
case "statusFilterList":
clearCategoryFilter();
clearTagFilter();
clearTrackerFilter();
break;
case "categoryFilterList":
clearStatusFilter();
clearTagFilter();
clearTrackerFilter();
break;
case "tagFilterList":
clearStatusFilter();
clearCategoryFilter();
clearTrackerFilter();
break;
case "trackerFilterList":
clearStatusFilter();
clearCategoryFilter();
clearTagFilter();
break;
default:
console.error(`Unexpected filterListID: ${filterListID}`);
break;
}
});
document.getElementById("Filters_pad").addEventListener("click", (event) => {
const filterTitle = event.target.closest(".filterTitle");
if (!filterTitle)
@@ -281,6 +321,11 @@
toggleCategoryDisplay(filterItem.id);
});
const clearStatusFilter = () => { setStatusFilter("all"); };
const clearCategoryFilter = () => { setCategoryFilter(CATEGORIES_ALL); };
const clearTagFilter = () => { setTagFilter(TAGS_ALL); };
const clearTrackerFilter = () => { setTrackerFilter(TRACKERS_ALL); };
return exports();
})();
Object.freeze(window.qBittorrent.Filters);

View File

@@ -49,6 +49,15 @@
</select>
</td>
</tr>
<tr>
<td><label for="dblclickFiltersSelect">QBT_TR(Filters:)QBT_TR[CONTEXT=OptionsDialog]</label></td>
<td>
<select id="dblclickFiltersSelect">
<option value="1" selected>QBT_TR(Reset filter selection)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="0">QBT_TR(No action)QBT_TR[CONTEXT=OptionsDialog]</option>
</select>
</td>
</tr>
</tbody>
</table>
</fieldset>
@@ -2230,6 +2239,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
document.getElementById("hideZeroFiltersCheckbox").checked = (LocalPreferences.get("hide_zero_status_filters", "false") === "true");
document.getElementById("dblclickDownloadSelect").value = LocalPreferences.get("dblclick_download", "1");
document.getElementById("dblclickCompleteSelect").value = LocalPreferences.get("dblclick_complete", "1");
document.getElementById("dblclickFiltersSelect").value = LocalPreferences.get("dblclick_filter", "1");
document.getElementById("confirmTorrentDeletion").checked = pref.confirm_torrent_deletion;
document.getElementById("useAltRowColorsInput").checked = (LocalPreferences.get("use_alt_row_colors", "true") === "true");
document.getElementById("filelog_checkbox").checked = pref.file_log_enabled;
@@ -2663,6 +2673,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
LocalPreferences.set("hide_zero_status_filters", document.getElementById("hideZeroFiltersCheckbox").checked.toString());
LocalPreferences.set("dblclick_download", document.getElementById("dblclickDownloadSelect").value);
LocalPreferences.set("dblclick_complete", document.getElementById("dblclickCompleteSelect").value);
LocalPreferences.set("dblclick_filter", document.getElementById("dblclickFiltersSelect").value);
settings["confirm_torrent_deletion"] = document.getElementById("confirmTorrentDeletion").checked;
LocalPreferences.set("use_alt_row_colors", document.getElementById("useAltRowColorsInput").checked.toString());
settings["file_log_enabled"] = document.getElementById("filelog_checkbox").checked;

View File

@@ -419,6 +419,7 @@
<file>private/scripts/prop-webseeds.js</file>
<file>private/scripts/rename-files.js</file>
<file>private/scripts/search.js</file>
<file>private/scripts/statistics.js</file>
<file>private/setlocation.html</file>
<file>private/shareratio.html</file>
<file>private/speedlimit.html</file>