From d0b54f8a8841ce625cbb781be2e0274185046d52 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 24 Sep 2021 18:03:22 +0700 Subject: [PATCH] add stop queue button to frontend --- .../home/templates/home/downloads.html | 1 + tubearchivist/home/views.py | 10 +++ tubearchivist/static/css/style.css | 13 +++- tubearchivist/static/img/icon-stop.svg | 67 +++++++++++++++++++ tubearchivist/static/progress.js | 18 +++++ tubearchivist/static/script.js | 7 ++ 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 tubearchivist/static/img/icon-stop.svg diff --git a/tubearchivist/home/templates/home/downloads.html b/tubearchivist/home/templates/home/downloads.html index cd96bfb..3c5bbb9 100644 --- a/tubearchivist/home/templates/home/downloads.html +++ b/tubearchivist/home/templates/home/downloads.html @@ -5,6 +5,7 @@

Downloads

+
rescan-icon diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 2d93d09..11da297 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -480,6 +480,7 @@ class PostData: "rescan_pending": self.rescan_pending, "ignore": self.ignore, "dl_pending": self.dl_pending, + "queue": self.queue_handler, "unsubscribe": self.unsubscribe, "sort_order": self.sort_order, "hide_watched": self.hide_watched, @@ -522,6 +523,15 @@ class PostData: download_pending.delay() return {"success": True} + def queue_handler(self): + """queue controls from frontend""" + to_execute = self.exec_val + if to_execute == "stop": + print("stopping download queue") + RedisQueue("dl_queue").clear() + + return {"success": True} + def unsubscribe(self): """unsubscribe from channel""" channel_id_unsub = self.exec_val diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index 1bcbc59..ebc0f68 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -458,10 +458,21 @@ button:hover { } .dl-desc { - padding-left: 15px; + padding: 0 15px; width: 75%; } +.dl-control-icons { + display: flex; + justify-content: center; + padding: 10px 0; +} + +.dl-control-icons img { + width: 30px; + filter: var(--img-filter); + cursor: pointer; +} /* status message */ .download-progress { diff --git a/tubearchivist/static/img/icon-stop.svg b/tubearchivist/static/img/icon-stop.svg new file mode 100644 index 0000000..b806c20 --- /dev/null +++ b/tubearchivist/static/img/icon-stop.svg @@ -0,0 +1,67 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/tubearchivist/static/progress.js b/tubearchivist/static/progress.js index 6e5acf6..aa70168 100644 --- a/tubearchivist/static/progress.js +++ b/tubearchivist/static/progress.js @@ -18,6 +18,7 @@ function checkMessage() { if (dlProgress['status']) { buildDownloadMessage(dlProgress); handleInterval(); + buildDownloadIcons(); }; }; req.send(); @@ -71,3 +72,20 @@ function buildDownloadMessage(dlProgress) { message.appendChild(messageText); box.appendChild(message); }; + + +// add dl control icons +function buildDownloadIcons() { + var box = document.getElementById('downloadControl'); + var iconBox = document.createElement('div'); + iconBox.classList = 'dl-control-icons'; + var stopIcon = document.createElement('img'); + stopIcon.setAttribute('id', "stop-icon"); + stopIcon.setAttribute('title', "Stop Download Queue"); + stopIcon.setAttribute('src', "/static/img/icon-stop.svg"); + stopIcon.setAttribute('alt', "stop icon"); + stopIcon.setAttribute('onclick', 'stopQueue()'); + // stich together + iconBox.appendChild(stopIcon); + box.appendChild(iconBox); +} diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index c726035..c4939b3 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -79,6 +79,13 @@ function downloadNow(button) { }, 500); } +function stopQueue() { + var payload = JSON.stringify({'queue': 'stop'}); + sendPost(payload); + document.getElementById('stop-icon').remove(); +} + + // settings page buttons function manualImport() { var payload = JSON.stringify({'manual-import': true});