mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-18 14:38:04 -06: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 #12701. PR #21136.
This commit is contained in:
@@ -306,6 +306,15 @@ a.propButton img {
|
|||||||
top: 3px;
|
top: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#contextCategoryList img {
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: 1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#contextCategoryList img.highlightedCategoryIcon {
|
||||||
|
background-color: hsl(213deg 94% 86%);
|
||||||
|
}
|
||||||
|
|
||||||
/* Sliders */
|
/* Sliders */
|
||||||
|
|
||||||
.slider {
|
.slider {
|
||||||
|
|||||||
@@ -310,6 +310,7 @@ window.qBittorrent.ContextMenu ??= (() => {
|
|||||||
let all_are_auto_tmm = true;
|
let all_are_auto_tmm = true;
|
||||||
let there_are_auto_tmm = false;
|
let there_are_auto_tmm = false;
|
||||||
const tagCount = new Map();
|
const tagCount = new Map();
|
||||||
|
const categoryCount = new Map();
|
||||||
|
|
||||||
const selectedRows = torrentsTable.selectedRowsIds();
|
const selectedRows = torrentsTable.selectedRowsIds();
|
||||||
selectedRows.forEach((item, index) => {
|
selectedRows.forEach((item, index) => {
|
||||||
@@ -350,6 +351,10 @@ window.qBittorrent.ContextMenu ??= (() => {
|
|||||||
const count = tagCount.get(tag);
|
const count = tagCount.get(tag);
|
||||||
tagCount.set(tag, ((count !== undefined) ? (count + 1) : 1));
|
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
|
// hide renameFiles when more than 1 torrent is selected
|
||||||
@@ -428,16 +433,24 @@ window.qBittorrent.ContextMenu ??= (() => {
|
|||||||
checkbox.indeterminate = (hasCount ? isLesser : false);
|
checkbox.indeterminate = (hasCount ? isLesser : false);
|
||||||
checkbox.checked = (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) {
|
updateCategoriesSubMenu: function(categoryList) {
|
||||||
const contextCategoryList = $("contextCategoryList");
|
const contextCategoryList = $("contextCategoryList");
|
||||||
contextCategoryList.getChildren().each(c => c.destroy());
|
contextCategoryList.getChildren().each(c => c.destroy());
|
||||||
contextCategoryList.appendChild(new Element("li", {
|
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", {
|
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 = [];
|
const sortedCategories = [];
|
||||||
|
|||||||
@@ -565,7 +565,10 @@ const initializeWindows = function() {
|
|||||||
paddingVertical: 0,
|
paddingVertical: 0,
|
||||||
paddingHorizontal: 0,
|
paddingHorizontal: 0,
|
||||||
width: 400,
|
width: 400,
|
||||||
height: 150
|
height: 150,
|
||||||
|
onCloseComplete: function() {
|
||||||
|
updateMainData();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -584,6 +587,9 @@ const initializeWindows = function() {
|
|||||||
data: {
|
data: {
|
||||||
hashes: hashes.join("|"),
|
hashes: hashes.join("|"),
|
||||||
category: categoryName
|
category: categoryName
|
||||||
|
},
|
||||||
|
onSuccess: function() {
|
||||||
|
updateMainData();
|
||||||
}
|
}
|
||||||
}).send();
|
}).send();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user