Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple filter select #1474

Merged
merged 2 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ dt:first-of-type{
.filter .active {
font-weight: bold;
}
.filter .active:after {
content: '✔';
margin-left: 0.5em; margin-right: .100em;
}

.navbar{
background: #222;
Expand Down
29 changes: 18 additions & 11 deletions app/views/search/_facet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
<h5><%= format_facet_name(name) %></h5>
</div>
<div class="panel-body">
<ul class='filter'>
<% facet.buckets.each do |term| %>
<% next if term['key'].blank? %>
<%= render 'search/term', term: term, name: name %>
<% end %>
<% if params[name.to_sym].present? && !facet.buckets.map{|t| t['key']}.include?(params[name.to_sym]) %>
<li class='active'>
<%= link_to platform_name(params[name.to_sym]), url_for(params.except(:host).merge(name.to_sym => nil, page: nil).permit!) %>
</li>
<% end %>
</ul>
<ul class='filter'>
<% facet.buckets.each do |term| %>
<% next if term['key'].blank? %>
<%= render 'search/term', term: term, name: name %>
<% end %>
<% if params[name.to_sym].present? %>
<% params[name.to_sym].split(',').each do |term| %>
<% if !facet.buckets.map{|t| t['key']}.include?(term) %>
<li class='active'>
<%= link_to url_for(params.except(:host).merge(name.to_sym => params[name.to_sym].split(',').reject{ |x| x == term }.join(','), page: nil).permit!) do %>
<input type='checkbox' checked>
<%= format_term(term) %>
<% end %>
</li>
<% end %>
<% end %>
<% end %>
</ul>
</div>
</div>
13 changes: 10 additions & 3 deletions app/views/search/_term.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<% term['key'] = term['key'].downcase if name == 'host_type' %>
<% active = term['key'] == params[name.to_sym] %>
<% current_param = params[name.to_sym].try(:split,',') || [] %>
<% active = current_param.include?(term['key']) %>
<li class='<%= 'active' if active %>'>
<% if active %>
<%= link_to format_term(term['key']), url_for(params.except(:host).merge(name.to_sym => nil, page: nil).permit!) %>
<%= link_to url_for(params.except(:host).merge(name.to_sym => current_param.reject{ |x| x == term['key'] }.join(','), page: nil).permit!) do %>
<input type='checkbox' checked>
<%= format_term(term['key']) %>
<% end %>
<% else %>
<%= link_to format_term(term['key']), url_for(params.except(:host).merge(name.to_sym => term['key'], page: nil).permit!) %>
<%= link_to url_for(params.except(:host).merge(name.to_sym => current_param.push(term['key']).join(','), page: nil).permit!) do %>
<input type='checkbox'>
<%= format_term(term['key']) %>
<% end %>
<small><%= number_to_human term['doc_count'] %> projects</small>
<% end %>
</li>