From b530e19a44430081852feb5cf59f3ba1ed6e7289 Mon Sep 17 00:00:00 2001 From: Vasiliy Halimonchuk Date: Thu, 30 May 2019 09:03:27 +0300 Subject: [PATCH] Implement tag management for WebUI --- src/webui/api/synccontroller.cpp | 6 + src/webui/api/torrentscontroller.cpp | 64 +++++++ src/webui/api/torrentscontroller.h | 5 + src/webui/www/private/css/style.css | 5 + src/webui/www/private/filters.html | 42 +++++ src/webui/www/private/index.html | 12 ++ src/webui/www/private/newtag.html | 105 ++++++++++++ src/webui/www/private/scripts/client.js | 142 +++++++++++++++- src/webui/www/private/scripts/contextmenu.js | 68 ++++++++ src/webui/www/private/scripts/dynamicTable.js | 34 +++- src/webui/www/private/scripts/mocha-init.js | 158 +++++++++++++++++- src/webui/www/webui.qrc | 1 + 12 files changed, 631 insertions(+), 11 deletions(-) create mode 100644 src/webui/www/private/newtag.html diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index dac4fb316..cb8a038c0 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -445,6 +445,12 @@ void SyncController::maindataAction() data["categories"] = categories; + QVariantList tags; + for (const QString &tag : asConst(session->tags())) + tags << tag; + + data["tags"] = tags; + QVariantMap serverState = getTranserInfo(); serverState[KEY_TRANSFER_FREESPACEONDISK] = getFreeDiskSpace(); serverState[KEY_SYNC_MAINDATA_QUEUEING] = session->isQueueingSystemEnabled(); diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 35561b10e..0a965bf28 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -1041,3 +1041,67 @@ void TorrentsController::categoriesAction() setResult(categories); } + +void TorrentsController::addTagsAction() +{ + checkParams({"hashes", "tags"}); + + const QStringList hashes {params()["hashes"].split('|')}; + const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)}; + + for (const QString &tag : tags) { + const QString tagTrimmed {tag.trimmed()}; + applyToTorrents(hashes, [&tagTrimmed](BitTorrent::TorrentHandle *const torrent) + { + torrent->addTag(tagTrimmed); + }); + } +} + +void TorrentsController::removeTagsAction() +{ + checkParams({"hashes"}); + + const QStringList hashes {params()["hashes"].split('|')}; + const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)}; + + for (const QString &tag : tags) { + const QString tagTrimmed {tag.trimmed()}; + applyToTorrents(hashes, [&tagTrimmed](BitTorrent::TorrentHandle *const torrent) + { + torrent->removeTag(tagTrimmed); + }); + } + + if (tags.isEmpty()) { + applyToTorrents(hashes, [](BitTorrent::TorrentHandle *const torrent) + { + torrent->removeAllTags(); + }); + } +} + +void TorrentsController::createTagsAction() +{ + checkParams({"tags"}); + + const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)}; + + for (const QString &tag : tags) + BitTorrent::Session::instance()->addTag(tag.trimmed()); +} + +void TorrentsController::deleteTagsAction() +{ + checkParams({"tags"}); + + const QStringList tags {params()["tags"].split(',', QString::SkipEmptyParts)}; + for (const QString &tag : tags) + BitTorrent::Session::instance()->removeTag(tag.trimmed()); +} + +void TorrentsController::tagsAction() +{ + const QStringList tags = BitTorrent::Session::instance()->tags().toList(); + setResult(QJsonArray::fromStringList(tags)); +} diff --git a/src/webui/api/torrentscontroller.h b/src/webui/api/torrentscontroller.h index 2f467a22e..61bf4e14f 100644 --- a/src/webui/api/torrentscontroller.h +++ b/src/webui/api/torrentscontroller.h @@ -56,6 +56,11 @@ private slots: void editCategoryAction(); void removeCategoriesAction(); void categoriesAction(); + void addTagsAction(); + void removeTagsAction(); + void createTagsAction(); + void deleteTagsAction(); + void tagsAction(); void addAction(); void deleteAction(); void addTrackersAction(); diff --git a/src/webui/www/private/css/style.css b/src/webui/www/private/css/style.css index 3200778ce..b625af7ab 100644 --- a/src/webui/www/private/css/style.css +++ b/src/webui/www/private/css/style.css @@ -258,6 +258,11 @@ a.propButton img { -ms-interpolation-mode: bicubic; } +.contextMenu li input[type=checkbox] { + position: relative; + top: 3px; +} + /* Sliders */ .slider { diff --git a/src/webui/www/private/filters.html b/src/webui/www/private/filters.html index 112a20356..d74c66b15 100644 --- a/src/webui/www/private/filters.html +++ b/src/webui/www/private/filters.html @@ -21,6 +21,13 @@ +
+ + QBT_TR(Tags)QBT_TR[CONTEXT=TransferListFiltersWidget] + + +
diff --git a/src/webui/www/private/index.html b/src/webui/www/private/index.html index 0fd0e8076..89fc2c68e 100644 --- a/src/webui/www/private/index.html +++ b/src/webui/www/private/index.html @@ -132,6 +132,10 @@ QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Category)QBT_TR[CONTEXT=TransferListWidget] +
  • + QBT_TR(Tags)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Tags)QBT_TR[CONTEXT=TransferListWidget] + +
  • QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget] QBT_TR(Automatic Torrent Management)QBT_TR[CONTEXT=TransferListWidget]
  • @@ -170,6 +174,14 @@
  • QBT_TR(Pause torrents)QBT_TR[CONTEXT=CategoryFilterWidget] QBT_TR(Pause torrents)QBT_TR[CONTEXT=CategoryFilterWidget]
  • QBT_TR(Delete torrents)QBT_TR[CONTEXT=CategoryFilterWidget] QBT_TR(Delete torrents)QBT_TR[CONTEXT=CategoryFilterWidget]
  • +