add dropdown channel agg for download page

This commit is contained in:
simon 2022-10-22 21:23:57 +07:00
parent 3f1075d0b2
commit a5788117de
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
4 changed files with 51 additions and 0 deletions

View File

@ -41,6 +41,15 @@
</div>
</div>
<div class="view-icons">
{% if channel_agg_list|length > 1 %}
<span>Filter:</span>
<select name="channel_filter" id="channel_filter" onchange="channelFilterDownload(this.value)">
<option value="all" {% if not channel_filter_id %}selected{% endif %}>all</option>
{% for channel in channel_agg_list %}
<option {% if channel_filter_id == channel.id %}selected{% endif %} value="{{ channel.id }}">{{ channel.name }} ({{channel.count}})</option>
{% endfor %}
</select>
{% endif %}
{% if view_style == "grid" %}
<div class="grid-count">
{% if grid_items < 7 %}

View File

@ -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"""

View File

@ -344,6 +344,7 @@ button:hover {
.grid-count {
display: flex;
justify-content: end;
align-items: center;
}
.view-icons img {

View File

@ -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")) {