mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +00:00
extend sort_by and sort_order in home view
This commit is contained in:
parent
d4e266f9c0
commit
78561981ad
@ -6,11 +6,25 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="info-box info-box-2">
|
<div class="info-box info-box-2">
|
||||||
<div class="sort">
|
<div class="sort">
|
||||||
<p>Sort order from <span class="settings-current">{{ sortorder }}</span>
|
<p>Sort by <span class="settings-current">{{ sort_by }}</span>
|
||||||
<select name="sort" id="sort" onchange="sortChange(this.value)">
|
<select name="sort" id="sort" onchange="sortChange(this.value)">
|
||||||
<option value="" disabled selected> -- change sort order -- </option>
|
<option value="" disabled selected> -- change sort by -- </option>
|
||||||
<option value="published">date published</option>
|
<option value="published">date published</option>
|
||||||
<option value="downloaded">date downloaded</option>
|
<option value="downloaded">date downloaded</option>
|
||||||
|
<option value="views">views</option>
|
||||||
|
<option value="likes">likes</option>
|
||||||
|
</select>
|
||||||
|
<select name="sord-order" id="sort-order" onchange="sortChange(this.value)">
|
||||||
|
{% if sort_order == "asc" %}
|
||||||
|
<option value="asc" selected>asc</option>
|
||||||
|
{% else %}
|
||||||
|
<option value="asc">asc</option>
|
||||||
|
{% endif %}
|
||||||
|
{% if sort_order == "desc" %}
|
||||||
|
<option value="desc" selected>desc</option>
|
||||||
|
{% else %}
|
||||||
|
<option value="desc">desc</option>
|
||||||
|
{% endif %}
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -58,6 +58,7 @@ class HomeView(View):
|
|||||||
url = self.ES_URL + "/ta_video/_search"
|
url = self.ES_URL + "/ta_video/_search"
|
||||||
data = self.build_data(
|
data = self.build_data(
|
||||||
pagination_handler,
|
pagination_handler,
|
||||||
|
view_config["sort_by"],
|
||||||
view_config["sort_order"],
|
view_config["sort_order"],
|
||||||
search_get,
|
search_get,
|
||||||
view_config["hide_watched"],
|
view_config["hide_watched"],
|
||||||
@ -70,7 +71,8 @@ class HomeView(View):
|
|||||||
context = {
|
context = {
|
||||||
"videos": videos_hits,
|
"videos": videos_hits,
|
||||||
"pagination": pagination_handler.pagination,
|
"pagination": pagination_handler.pagination,
|
||||||
"sortorder": view_config["sort_order"],
|
"sort_by": view_config["sort_by"],
|
||||||
|
"sort_order": view_config["sort_order"],
|
||||||
"hide_watched": view_config["hide_watched"],
|
"hide_watched": view_config["hide_watched"],
|
||||||
"colors": view_config["colors"],
|
"colors": view_config["colors"],
|
||||||
"view_style": view_config["view_style"],
|
"view_style": view_config["view_style"],
|
||||||
@ -78,27 +80,31 @@ class HomeView(View):
|
|||||||
return render(request, "home/home.html", context)
|
return render(request, "home/home.html", context)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def build_data(pagination_handler, sort_order, search_get, hide_watched):
|
def build_data(
|
||||||
|
pagination_handler, sort_by, sort_order, search_get, hide_watched
|
||||||
|
):
|
||||||
"""build the data dict for the search query"""
|
"""build the data dict for the search query"""
|
||||||
page_size = pagination_handler.pagination["page_size"]
|
page_size = pagination_handler.pagination["page_size"]
|
||||||
page_from = pagination_handler.pagination["page_from"]
|
page_from = pagination_handler.pagination["page_from"]
|
||||||
|
|
||||||
|
# overwrite sort_by to match key
|
||||||
|
if sort_by == "views":
|
||||||
|
sort_by = "stats.view_count"
|
||||||
|
elif sort_by == "likes":
|
||||||
|
sort_by = "stats.like_count"
|
||||||
|
elif sort_by == "downloaded":
|
||||||
|
sort_by = "date_downloaded"
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"size": page_size,
|
"size": page_size,
|
||||||
"from": page_from,
|
"from": page_from,
|
||||||
"query": {"match_all": {}},
|
"query": {"match_all": {}},
|
||||||
"sort": [
|
"sort": [{sort_by: {"order": sort_order}}],
|
||||||
{"published": {"order": "desc"}},
|
|
||||||
{"date_downloaded": {"order": "desc"}},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
# define sort
|
|
||||||
if sort_order == "downloaded":
|
|
||||||
del data["sort"][0]
|
|
||||||
if search_get:
|
|
||||||
del data["sort"]
|
|
||||||
if hide_watched:
|
if hide_watched:
|
||||||
data["query"] = {"term": {"player.watched": {"value": False}}}
|
data["query"] = {"term": {"player.watched": {"value": False}}}
|
||||||
if search_get:
|
if search_get:
|
||||||
|
del data["sort"]
|
||||||
query = {
|
query = {
|
||||||
"multi_match": {
|
"multi_match": {
|
||||||
"query": search_get,
|
"query": search_get,
|
||||||
@ -109,6 +115,8 @@ class HomeView(View):
|
|||||||
}
|
}
|
||||||
data["query"] = query
|
data["query"] = query
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -117,13 +125,19 @@ class HomeView(View):
|
|||||||
config_handler = AppConfig().config
|
config_handler = AppConfig().config
|
||||||
colors = config_handler["application"]["colors"]
|
colors = config_handler["application"]["colors"]
|
||||||
view_style = config_handler["default_view"]["home"]
|
view_style = config_handler["default_view"]["home"]
|
||||||
|
|
||||||
|
sort_by = RedisArchivist().get_message("sort_by")
|
||||||
|
if sort_by == {"status": False}:
|
||||||
|
sort_by = "published"
|
||||||
sort_order = RedisArchivist().get_message("sort_order")
|
sort_order = RedisArchivist().get_message("sort_order")
|
||||||
if not sort_order:
|
if sort_order == {"status": False}:
|
||||||
sort_order = "published"
|
sort_order = "desc"
|
||||||
|
|
||||||
hide_watched = RedisArchivist().get_message("hide_watched")
|
hide_watched = RedisArchivist().get_message("hide_watched")
|
||||||
view_config = {
|
view_config = {
|
||||||
"colors": colors,
|
"colors": colors,
|
||||||
"view_style": view_style,
|
"view_style": view_style,
|
||||||
|
"sort_by": sort_by,
|
||||||
"sort_order": sort_order,
|
"sort_order": sort_order,
|
||||||
"hide_watched": hide_watched,
|
"hide_watched": hide_watched,
|
||||||
}
|
}
|
||||||
@ -664,7 +678,12 @@ class PostData:
|
|||||||
def sort_order(self):
|
def sort_order(self):
|
||||||
"""change the sort between published to downloaded"""
|
"""change the sort between published to downloaded"""
|
||||||
sort_order = self.exec_val
|
sort_order = self.exec_val
|
||||||
RedisArchivist().set_message("sort_order", sort_order, expire=False)
|
if sort_order in ["asc", "desc"]:
|
||||||
|
RedisArchivist().set_message(
|
||||||
|
"sort_order", sort_order, expire=False
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
RedisArchivist().set_message("sort_by", sort_order, expire=False)
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
def hide_watched(self):
|
def hide_watched(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user