From 142780b863bbf17b57e1b2858401e65a1c276eef Mon Sep 17 00:00:00 2001
From: skomerko <168652295+skomerko@users.noreply.github.com>
Date: Wed, 7 Aug 2024 15:40:21 +0200
Subject: [PATCH] WebUI: Highlight torrent category in context menu
This PR makes it possible to see common category of selected torrents in context menu. Everything should behave exactly like in GUI.
Closes #12701.
PR #21136.
---
src/webui/www/private/css/style.css | 9 +++++++++
src/webui/www/private/scripts/contextmenu.js | 17 +++++++++++++++--
src/webui/www/private/scripts/mocha-init.js | 8 +++++++-
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/src/webui/www/private/css/style.css b/src/webui/www/private/css/style.css
index 97e2314a5..5fc361c4a 100644
--- a/src/webui/www/private/css/style.css
+++ b/src/webui/www/private/css/style.css
@@ -306,6 +306,15 @@ a.propButton img {
top: 3px;
}
+#contextCategoryList img {
+ border: 1px solid transparent;
+ padding: 1px;
+}
+
+#contextCategoryList img.highlightedCategoryIcon {
+ background-color: hsl(213deg 94% 86%);
+}
+
/* Sliders */
.slider {
diff --git a/src/webui/www/private/scripts/contextmenu.js b/src/webui/www/private/scripts/contextmenu.js
index 4f49ca3d4..3f8bc514e 100644
--- a/src/webui/www/private/scripts/contextmenu.js
+++ b/src/webui/www/private/scripts/contextmenu.js
@@ -310,6 +310,7 @@ window.qBittorrent.ContextMenu ??= (() => {
let all_are_auto_tmm = true;
let there_are_auto_tmm = false;
const tagCount = new Map();
+ const categoryCount = new Map();
const selectedRows = torrentsTable.selectedRowsIds();
selectedRows.forEach((item, index) => {
@@ -350,6 +351,10 @@ window.qBittorrent.ContextMenu ??= (() => {
const count = tagCount.get(tag);
tagCount.set(tag, ((count !== undefined) ? (count + 1) : 1));
}
+
+ const torrentCategory = data["category"];
+ const count = categoryCount.get(torrentCategory);
+ categoryCount.set(torrentCategory, ((count !== undefined) ? (count + 1) : 1));
});
// hide renameFiles when more than 1 torrent is selected
@@ -428,16 +433,24 @@ window.qBittorrent.ContextMenu ??= (() => {
checkbox.indeterminate = (hasCount ? isLesser : false);
checkbox.checked = (hasCount ? !isLesser : false);
});
+
+ const contextCategoryList = document.getElementById("contextCategoryList");
+ category_list.forEach((category, categoryHash) => {
+ const categoryIcon = contextCategoryList.querySelector(`a[href$="(${categoryHash});"] img`);
+ const count = categoryCount.get(category.name);
+ const isEqual = ((count !== undefined) && (count === selectedRows.length));
+ categoryIcon.classList.toggle("highlightedCategoryIcon", isEqual);
+ });
},
updateCategoriesSubMenu: function(categoryList) {
const contextCategoryList = $("contextCategoryList");
contextCategoryList.getChildren().each(c => c.destroy());
contextCategoryList.appendChild(new Element("li", {
- html: '
QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]'
+ html: '
QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]'
}));
contextCategoryList.appendChild(new Element("li", {
- html: '
QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]'
+ html: '
QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]'
}));
const sortedCategories = [];
diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js
index 753d06d08..c36dcaa5e 100644
--- a/src/webui/www/private/scripts/mocha-init.js
+++ b/src/webui/www/private/scripts/mocha-init.js
@@ -565,7 +565,10 @@ const initializeWindows = function() {
paddingVertical: 0,
paddingHorizontal: 0,
width: 400,
- height: 150
+ height: 150,
+ onCloseComplete: function() {
+ updateMainData();
+ }
});
}
};
@@ -584,6 +587,9 @@ const initializeWindows = function() {
data: {
hashes: hashes.join("|"),
category: categoryName
+ },
+ onSuccess: function() {
+ updateMainData();
}
}).send();
};