diff --git a/tubearchivist/home/templates/home/downloads.html b/tubearchivist/home/templates/home/downloads.html index 85d61e7..22dd6fd 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 9d44399..ba5af2f 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 e4f9047..7a3872e 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 7e375c1..08e94d2 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")) {