Disallow removing filters from sort by column

This commit is contained in:
syeopite 2021-10-27 06:10:30 -07:00
parent 0a7c483044
commit 69b316e708
No known key found for this signature in database
GPG key ID: 6FA616E5A5294A82
2 changed files with 20 additions and 7 deletions

View file

@ -7,6 +7,7 @@
# - filters: the array of filters within the column we're creating
# - filter_name: name of the filter
# - selected_default: default selected filter
# - allow_removal: allows selected filter to be removed?
-%>
<div class="pure-u-1-3 pure-u-md-1-5 filter-catagory" id="filter-<%= filter_name %>">
@ -18,11 +19,14 @@
<li class="pure-menu-item">
<% if operators.fetch(filter_name, selected_default) == filter %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params.gsub(/&#{filter_name}=[a-z]+/, "")}"%>">
<% if allow_removal %>
<a style="color: inherit;" href="<%= base_url + "#{filter_params.gsub(/&#{filter_name}=[a-z]+/, "")}"%>">
<b><%= translate(locale, filter) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% else %>
<b><%= translate(locale, filter) %></b>
<i class="remove-filter icon ion-md-close"></i>
</a>
<% end %>
<% else %>
<a href="<%= base_url + "#{filter_params.gsub(/&#{filter_name}=[a-z]+/, "")}&#{filter_name}=#{filter}"%>">
<%= translate(locale, filter) %>

View file

@ -13,14 +13,18 @@
<% filter_params = env.request.query_params.to_s.gsub(/q=.+?(?=&|$)/, "").gsub(/&page=\d+/, "") %>
<% base_url = "/search?q=#{URI.encode_www_form(query.not_nil!)}" -%>
<%
# Literally only needed for the sort_by column. So for the rest we'd just use these values:
selected_default = "NotNeeded"
allow_removal = true
%>
<% filters = ["hour", "today", "week", "month", "year"] %>
<% filter_name = "date" %>
<% selected_default = "NotNeeded" %>
<%= rendered "components/search-filters/filter-column" -%>
<% filters = ["video", "channel", "playlist", "movie", "show"] %>
<% filter_name = "content_type" %>
<% selected_default = "NotNeeded" %>
<%= rendered "components/search-filters/filter-column" -%>
<% filters = ["short", "long"] %>
@ -70,7 +74,12 @@
<% filters = ["relevance", "rating", "date", "views"] %>
<% filter_name = "sort" %>
<% selected_default = "relevance" %>
<%
# Literally only needed for the sort_by column. So for the rest we'd just use these values:
selected_default = "relevance"
allow_removal = false
%>
<%= rendered "components/search-filters/filter-column" -%>
</div>