From 3f31e50b699ad2c5056ee7d1bc5079736f883723 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 25 Nov 2021 20:02:25 +0700 Subject: [PATCH] add delete download queue pending or ignored, #85 --- tubearchivist/home/src/download.py | 12 ++++++++++++ tubearchivist/home/templates/home/downloads.html | 15 +++++++++------ tubearchivist/home/views.py | 11 +++++++++++ tubearchivist/static/css/style.css | 5 +++++ tubearchivist/static/script.js | 11 +++++++++++ 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index 7f13eec..5ba6cba 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -225,6 +225,18 @@ class PendingList: if not response.ok: print(response.text) + def delete_pending(self, status): + """delete download queue based on status value""" + data = {"query": {"term": {"status": {"value": status}}}} + payload = json.dumps(data) + url = self.ES_URL + "/ta_download/_delete_by_query" + headers = {"Content-type": "application/json"} + response = requests.post( + url, data=payload, headers=headers, auth=self.ES_AUTH + ) + if not response.ok: + print(response.text) + def ignore_from_pending(self, ignore_list): """build the bulk query string""" diff --git a/tubearchivist/home/templates/home/downloads.html b/tubearchivist/home/templates/home/downloads.html index 71147f1..2a99c1e 100644 --- a/tubearchivist/home/templates/home/downloads.html +++ b/tubearchivist/home/templates/home/downloads.html @@ -21,7 +21,6 @@
{% csrf_token %} - {{ add_form }}
@@ -47,11 +46,15 @@ list view
-{% if show_ignored_only %} -

Ignored from download

-{% else %} -

Download queue

-{% endif %} +
+ {% if show_ignored_only %} +

Ignored from download

+ + {% else %} +

Download queue

+ + {% endif %} +

Total videos: {{ max_hits }}

{% if all_video_hits %} diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index a407187..d15013d 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -1005,6 +1005,7 @@ class PostData: "show_ignored_only": self.show_ignored_only, "forgetIgnore": self.forget_ignore, "addSingle": self.add_single, + "deleteQueue": self.delete_queue, "manual-import": self.manual_import, "re-embed": self.re_embed, "db-backup": self.db_backup, @@ -1172,6 +1173,16 @@ class PostData: extrac_dl.delay(youtube_ids) return {"success": True} + def delete_queue(self): + """delete download queue""" + status = self.exec_val + print("deleting from download queue: " + status) + if status == "pending": + PendingList().delete_pending("pending") + elif status == "ignore": + PendingList().delete_pending("ignore") + return {"success": True} + @staticmethod def manual_import(): """run manual import from settings page""" diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index 465447d..e9bf7a8 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -824,6 +824,11 @@ button:hover { filter: var(--img-filter-error); } +.title-split { + display: flex; + justify-content: space-between; +} + /* status message */ .download-progress { background-color: var(--highlight-bg); diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index e5fdf9f..00bc5cd 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -138,6 +138,17 @@ function addSingle(button) { }, 500); } +function deleteQueue(button) { + var to_delete = button.getAttribute('data-id'); + var payload = JSON.stringify({'deleteQueue': to_delete}); + console.log(payload); + sendPost(payload); + setTimeout(function(){ + location.reload(); + return false; + }, 1000); +} + function stopQueue() { var payload = JSON.stringify({'queue': 'stop'}); sendPost(payload);