From a5788117deddd82944a5648d7a0b6fe03c935809 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 22 Oct 2022 21:23:57 +0700 Subject: [PATCH] add dropdown channel agg for download page --- .../home/templates/home/downloads.html | 9 +++++ tubearchivist/home/views.py | 33 +++++++++++++++++++ tubearchivist/static/css/style.css | 1 + tubearchivist/static/script.js | 8 +++++ 4 files changed, 51 insertions(+) diff --git a/tubearchivist/home/templates/home/downloads.html b/tubearchivist/home/templates/home/downloads.html index 85d61e7c..22dd6fdf 100644 --- a/tubearchivist/home/templates/home/downloads.html +++ b/tubearchivist/home/templates/home/downloads.html @@ -41,6 +41,15 @@
+ {% if channel_agg_list|length > 1 %} + Filter: + + {% endif %} {% if view_style == "grid" %}
{% if grid_items < 7 %} diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 9d44399d..ba5af2f1 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -364,6 +364,7 @@ class DownloadView(ArchivistResultsView): { "title": "Downloads", "add_form": AddToQueueForm(), + "channel_agg_list": self._get_channel_agg(), } ) return render(request, "home/downloads.html", self.context) @@ -399,6 +400,38 @@ class DownloadView(ArchivistResultsView): } ) + def _get_channel_agg(self): + """get pending channel with count""" + data = { + "size": 0, + "query": {"term": {"status": {"value": "pending"}}}, + "aggs": { + "channel_downloads": { + "multi_terms": { + "size": 30, + "terms": [ + {"field": "channel_name.keyword"}, + {"field": "channel_id"}, + ], + "order": {"_count": "desc"}, + } + } + }, + } + response, _ = ElasticWrap(self.es_search).get(data=data) + buckets = response["aggregations"]["channel_downloads"]["buckets"] + + buckets_sorted = [] + for i in buckets: + bucket = { + "name": i["key"][0], + "id": i["key"][1], + "count": i["doc_count"], + } + buckets_sorted.append(bucket) + + return buckets_sorted + @staticmethod def post(request): """handle post requests""" diff --git a/tubearchivist/static/css/style.css b/tubearchivist/static/css/style.css index e4f90472..7a3872e3 100644 --- a/tubearchivist/static/css/style.css +++ b/tubearchivist/static/css/style.css @@ -344,6 +344,7 @@ button:hover { .grid-count { display: flex; justify-content: end; + align-items: center; } .view-icons img { diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index 7e375c17..08e94d24 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -1147,6 +1147,14 @@ function showForm() { animate('animate-icon', 'pulse-img'); } +function channelFilterDownload(value) { + if (value === "all") { + window.location = "/downloads/"; + } else { + window.location.search = "?channel=" + value; + } +} + function showOverwrite() { var overwriteDiv = document.getElementById("overwrite-form"); if (overwriteDiv.classList.contains("hidden-overwrite")) {