mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Display distributor filter as links instead of checkboxes, style in the same way as taxonomy selectors
This commit is contained in:
24
app/assets/stylesheets/store/openfoodweb.css.scss
Normal file
24
app/assets/stylesheets/store/openfoodweb.css.scss
Normal file
@@ -0,0 +1,24 @@
|
||||
@import "screen";
|
||||
|
||||
/* Based on Spree's nav#taxonomies style. Copied instead of
|
||||
* extended with SASS because SASS does not allow extending
|
||||
* nested selectors.
|
||||
*/
|
||||
nav#filters {
|
||||
.filter_name {
|
||||
text-transform: uppercase;
|
||||
border-bottom: 1px solid lighten($body_text_color, 60);
|
||||
margin-bottom: 5px;
|
||||
font-size: $main_navigation_header_font_size;
|
||||
}
|
||||
|
||||
.filter_choices {
|
||||
padding-left: 20px;
|
||||
margin-bottom: 20px;
|
||||
list-style: disc outside;
|
||||
|
||||
li a {
|
||||
font-size: $main_navigation_font_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,19 @@
|
||||
<% filters = @taxon ? @taxon.applicable_filters : [Spree::ProductFilters.distributor_filter] %>
|
||||
<% unless filters.empty? %>
|
||||
<%= form_tag '', :method => :get, :id => 'sidebar_products_search' do %>
|
||||
<nav id="filters">
|
||||
<% params[:search] ||= {} %>
|
||||
<%= hidden_field_tag 'per_page', params[:per_page] %>
|
||||
<% filters.each do |filter| %>
|
||||
<% labels = filter[:labels] || filter[:conds].map {|m,c| [m,m]} %>
|
||||
<% next if labels.empty? %>
|
||||
<div class="navigation" data-hook="navigation">
|
||||
<span class="category"> <%= filter[:name] %> </span>
|
||||
<ul class="filter_choices">
|
||||
<% labels.each do |nm,val| %>
|
||||
<% label = "#{filter[:name]}_#{nm}".gsub(/\s+/,'_') %>
|
||||
<li class="nowrap">
|
||||
<input type="checkbox"
|
||||
id="<%= label %>"
|
||||
name="search[<%= filter[:scope].to_s %>][]"
|
||||
value="<%= val %>"
|
||||
<%= params[:search][filter[:scope]] && params[:search][filter[:scope]].include?(val.to_s) ? "checked" : "" %> />
|
||||
<label class="nowrap" for="<%= label %>"> <%= nm %> </label>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<h6 class="filter_name">Shop by <%= filter[:name] %></h6>
|
||||
<ul class="filter_choices">
|
||||
<% labels.each do |nm,val| %>
|
||||
<li class="nowrap">
|
||||
<% active = params[:search][filter[:scope]] && params[:search][filter[:scope]].include?(val.to_s) %>
|
||||
<%= link_to nm, "?search[#{filter[:scope].to_s}][]=#{val}" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<%= submit_tag t(:search), :name => nil %>
|
||||
<% end %>
|
||||
</nav>
|
||||
<% end %>
|
||||
|
||||
@@ -10,7 +10,7 @@ module Spree
|
||||
def ProductFilters.distributor_filter
|
||||
distributors = Spree::Distributor.all.map(&:name).compact.uniq
|
||||
conds = Hash[*distributors.map { |d| [d, "#{Spree::Distributor.table_name}.name = '#{d}'"] }.flatten]
|
||||
{ :name => "Distributor",
|
||||
{ :name => "Group",
|
||||
:scope => :distributor_any,
|
||||
:conds => conds,
|
||||
:labels => (distributors.sort).map { |k| [k, k] }
|
||||
|
||||
Reference in New Issue
Block a user