1
0
mirror of https://github.com/qbittorrent/qBittorrent.git synced 2025-03-12 04:35:47 -07:00

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 .
PR .
This commit is contained in:
skomerko 2024-08-07 15:40:21 +02:00 committed by GitHub
parent 7b2886e477
commit 142780b863
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 3 deletions
src/webui/www/private

@ -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 {

@ -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: '<a href="javascript:torrentNewCategoryFN();"><img src="images/list-add.svg" alt="QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]</a>'
html: '<a href="javascript:torrentNewCategoryFN();"><img src="images/list-add.svg" alt="QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]"/>QBT_TR(New...)QBT_TR[CONTEXT=TransferListWidget]</a>'
}));
contextCategoryList.appendChild(new Element("li", {
html: '<a href="javascript:torrentSetCategoryFN(0);"><img src="images/edit-clear.svg" alt="QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]"/> QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]</a>'
html: '<a href="javascript:torrentSetCategoryFN(0);"><img src="images/edit-clear.svg" alt="QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]"/>QBT_TR(Reset)QBT_TR[CONTEXT=TransferListWidget]</a>'
}));
const sortedCategories = [];

@ -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();
};