From 7cd1dc19d46c7a5b2b21fcd93ed9ec23f73c07d4 Mon Sep 17 00:00:00 2001 From: Thomas Piccirello Date: Thu, 11 Jul 2024 09:49:39 -0700 Subject: [PATCH] Support managing web seeds from WebUI --- src/webui/www/private/addwebseeds.html | 58 +++++++++ src/webui/www/private/editwebseed.html | 68 ++++++++++ src/webui/www/private/index.html | 6 + .../www/private/scripts/prop-webseeds.js | 118 +++++++++++++++++- src/webui/www/webui.qrc | 2 + 5 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 src/webui/www/private/addwebseeds.html create mode 100644 src/webui/www/private/editwebseed.html diff --git a/src/webui/www/private/addwebseeds.html b/src/webui/www/private/addwebseeds.html new file mode 100644 index 000000000000..9bd0b1b05c1b --- /dev/null +++ b/src/webui/www/private/addwebseeds.html @@ -0,0 +1,58 @@ + + + + + + QBT_TR(Add web seeds)QBT_TR[CONTEXT=HttpServer] + + + + + + + +
+
+ + +
+ +
+ + + diff --git a/src/webui/www/private/editwebseed.html b/src/webui/www/private/editwebseed.html new file mode 100644 index 000000000000..24e509b58e59 --- /dev/null +++ b/src/webui/www/private/editwebseed.html @@ -0,0 +1,68 @@ + + + + + + QBT_TR(Edit web seed)QBT_TR[CONTEXT=HttpServer] + + + + + + + +
+
+ +
+ +
+
+ +
+ + + diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 4fb09c62be3e..68e89c4c2f1e 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -230,6 +230,12 @@

qBittorrent Web User Interface QBT_TR(Copy IP:port)QBT_TR[CONTEXT=PeerListWidget] QBT_TR(Copy IP:port)QBT_TR[CONTEXT=PeerListWidget]
  • QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget] QBT_TR(Ban peer permanently)QBT_TR[CONTEXT=PeerListWidget]
  • +
    • QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget] QBT_TR(Rename...)QBT_TR[CONTEXT=PropertiesWidget]
    • diff --git a/src/webui/www/private/scripts/prop-webseeds.js b/src/webui/www/private/scripts/prop-webseeds.js index 2d71e99f88f8..68759fddba33 100644 --- a/src/webui/www/private/scripts/prop-webseeds.js +++ b/src/webui/www/private/scripts/prop-webseeds.js @@ -94,7 +94,123 @@ window.qBittorrent.PropWebseeds ??= (() => { loadWebSeedsData(); }; - torrentWebseedsTable.setup("torrentWebseedsTableDiv", "torrentWebseedsTableFixedHeaderDiv"); + const torrentWebseedsContextMenu = new window.qBittorrent.ContextMenu.ContextMenu({ + targets: "#torrentWebseedsTableDiv", + menu: "torrentWebseedsMenu", + actions: { + AddWebseeds: function(element, ref) { + addWebseedFN(); + }, + EditWebseed: function(element, ref) { + // only allow editing of one row + element.firstChild.click(); + editWebseedFN(element); + }, + RemoveWebseed: function(element, ref) { + removeWebseedFN(element); + } + }, + offsets: { + x: -15, + y: 2 + }, + onShow: function() { + const selectedWebseeds = torrentWebseedsTable.selectedRowsIds(); + + if (selectedWebseeds.length === 0) { + this.hideItem("EditWebseed"); + this.hideItem("RemoveWebseed"); + this.hideItem("CopyWebseedUrl"); + } + else { + if (selectedWebseeds.length === 1) + this.showItem("EditWebseed"); + else + this.hideItem("EditWebseed"); + + this.showItem("RemoveWebseed"); + this.showItem("CopyWebseedUrl"); + } + } + }); + + const addWebseedFN = function() { + if (current_hash.length === 0) + return; + + new MochaUI.Window({ + id: "webseedsPage", + title: "QBT_TR(Add web seeds)QBT_TR[CONTEXT=HttpServer]", + loadMethod: "iframe", + contentURL: "addwebseeds.html?hash=" + current_hash, + scrollbars: true, + resizable: false, + maximizable: false, + closable: true, + paddingVertical: 0, + paddingHorizontal: 0, + width: 500, + height: 250, + onCloseComplete: function() { + updateData(); + } + }); + }; + + const editWebseedFN = function(element) { + if (current_hash.length === 0) + return; + + const selectedWebseeds = torrentWebseedsTable.selectedRowsIds(); + if (selectedWebseeds.length > 1) + return; + + const webseedUrl = selectedWebseeds[0]; + + new MochaUI.Window({ + id: "webseedsPage", + title: "QBT_TR(Web seed editing)QBT_TR[CONTEXT=PropertiesWidget]", + loadMethod: "iframe", + contentURL: "editwebseed.html?hash=" + current_hash + "&url=" + encodeURIComponent(webseedUrl), + scrollbars: true, + resizable: false, + maximizable: false, + closable: true, + paddingVertical: 0, + paddingHorizontal: 0, + width: 500, + height: 150, + onCloseComplete: function() { + updateData(); + } + }); + }; + + const removeWebseedFN = function(element) { + if (current_hash.length === 0) + return; + + const selectedWebseeds = torrentWebseedsTable.selectedRowsIds(); + new Request({ + url: "api/v2/torrents/removeWebseeds", + method: "post", + data: { + hash: current_hash, + urls: selectedWebseeds.map(webseed => encodeURIComponent(webseed)).join("|") + }, + onSuccess: function() { + updateData(); + } + }).send(); + }; + + new ClipboardJS("#CopyWebseedUrl", { + text: function(trigger) { + return torrentWebseedsTable.selectedRowsIds().join("\n"); + } + }); + + torrentWebseedsTable.setup("torrentWebseedsTableDiv", "torrentWebseedsTableFixedHeaderDiv", torrentWebseedsContextMenu); return exports(); })(); diff --git a/src/webui/www/webui.qrc b/src/webui/www/webui.qrc index 31a8632ae722..e7f770211172 100644 --- a/src/webui/www/webui.qrc +++ b/src/webui/www/webui.qrc @@ -2,6 +2,7 @@ private/addpeers.html private/addtrackers.html + private/addwebseeds.html private/confirmdeletion.html private/confirmfeeddeletion.html private/confirmruleclear.html @@ -18,6 +19,7 @@ private/download.html private/downloadlimit.html private/edittracker.html + private/editwebseed.html private/images/3-state-checkbox.gif private/images/application-exit.svg private/images/application-rss.svg