Support specifying tags when adding torrent in WebUI

Signed-off-by: Thomas Piccirello <thomas@piccirello.com>
This commit is contained in:
Thomas Piccirello 2024-09-19 15:08:51 -07:00
commit 772fe9999e
No known key found for this signature in database
2 changed files with 60 additions and 0 deletions

View file

@ -7,8 +7,10 @@
<link rel="stylesheet" type="text/css" href="css/dynamicTable.css?v=${CACHEID}"> <link rel="stylesheet" type="text/css" href="css/dynamicTable.css?v=${CACHEID}">
<link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css"> <link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
<link rel="stylesheet" href="css/Window.css?v=${CACHEID}" type="text/css"> <link rel="stylesheet" href="css/Window.css?v=${CACHEID}" type="text/css">
<link rel="stylesheet" href="css/vanillaSelectBox.css" type="text/css">
<script defer src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script> <script defer src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
<script defer src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script> <script defer src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
<script defer src="scripts/lib/vanillaSelectBox.js"></script>
<script defer src="scripts/localpreferences.js?v=${CACHEID}"></script> <script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
<script defer src="scripts/color-scheme.js?v=${CACHEID}"></script> <script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
<script defer src="scripts/addtorrent.js?locale=${LANG}&v=${CACHEID}"></script> <script defer src="scripts/addtorrent.js?locale=${LANG}&v=${CACHEID}"></script>
@ -84,6 +86,13 @@
window.qBittorrent.AddTorrent.loadMetadata(source); window.qBittorrent.AddTorrent.loadMetadata(source);
}); });
</script> </script>
<style>
#btn-group-tagsSelect button {
background-color: initial;
}
</style>
</head> </head>
<body> <body>
@ -166,6 +175,17 @@
</div> </div>
</td> </td>
</tr> </tr>
<tr>
<td>
<label id="tagsLabel" for="tagsSelect">QBT_TR(Tags:)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>
</td>
<td>
<div>
<input type="hidden" id="tags" name="tags">
<select id="tagsSelect" name="tagsSelect" multiple></select>
</div>
</td>
</tr>
<tr> <tr>
<td> <td>
<label for="startTorrent">QBT_TR(Start torrent)QBT_TR[CONTEXT=AddNewTorrentDialog]</label> <label for="startTorrent">QBT_TR(Start torrent)QBT_TR[CONTEXT=AddNewTorrentDialog]</label>

View file

@ -37,6 +37,7 @@ window.qBittorrent.AddTorrent ??= (() => {
}; };
let categories = {}; let categories = {};
let tags = [];
let defaultSavePath = ""; let defaultSavePath = "";
let windowId = ""; let windowId = "";
let source; let source;
@ -66,6 +67,38 @@ window.qBittorrent.AddTorrent ??= (() => {
}); });
}; };
const getTags = () => {
fetch("api/v2/torrents/tags", {
method: "GET",
cache: "no-store"
})
.then(async (response) => {
if (!response.ok)
return;
const data = await response.json();
tags = data;
const tagsSelect = document.getElementById("tagsSelect");
for (const tag of tags) {
const option = document.createElement("option");
option.value = tag;
option.textContent = tag;
tagsSelect.appendChild(option);
}
new vanillaSelectBox("#tagsSelect", {
maxHeight: 200,
search: false,
disableSelectAll: true,
translations: {
all: tags.length === 0 ? "" : "QBT_TR(All)QBT_TR[CONTEXT=AddNewTorrentDialog]",
},
keepInlineStyles: false
});
});
};
const getPreferences = () => { const getPreferences = () => {
const pref = window.parent.qBittorrent.Cache.preferences.get(); const pref = window.parent.qBittorrent.Cache.preferences.get();
@ -122,6 +155,11 @@ window.qBittorrent.AddTorrent ??= (() => {
} }
}; };
const changeTagsSelect = (element) => {
const tags = [...element.options].filter(opt => opt.selected).map(opt => opt.value);
document.getElementById("tags").value = tags.join(",");
};
const changeTMM = (item) => { const changeTMM = (item) => {
const savepath = document.getElementById("savepath"); const savepath = document.getElementById("savepath");
const useDownloadPath = document.getElementById("useDownloadPath"); const useDownloadPath = document.getElementById("useDownloadPath");
@ -240,10 +278,12 @@ window.qBittorrent.AddTorrent ??= (() => {
getPreferences(); getPreferences();
getCategories(); getCategories();
getTags();
}); });
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
document.getElementById("useDownloadPath").addEventListener("change", (e) => changeUseDownloadPath(e.target)); document.getElementById("useDownloadPath").addEventListener("change", (e) => changeUseDownloadPath(e.target));
document.getElementById("tagsSelect").addEventListener("change", (e) => changeTagsSelect(e.target));
}); });
return exports(); return exports();