Skip to content

Commit

Permalink
Add 'display_control' option to view configs to allow them to toggle …
Browse files Browse the repository at this point in the history
…on/off visibility in the view type widget
  • Loading branch information
cbeer committed Apr 27, 2017
1 parent 4b3e868 commit 478de81
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/helpers/blacklight/configuration_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def document_index_views
end
end

# filter #document_index_views to just views that should display in the view type control
def document_index_view_controls
document_index_views.select do |_k, config|
config.display_control.nil? || blacklight_configuration_context.evaluate_configuration_conditional(config.display_control)
end
end

##
# Get the default index view type
def default_document_index_view_type
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalog/_view_type_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="view-type">
<span class="sr-only"><%= t('blacklight.search.view_title') %></span>
<div class="view-type-group btn-group">
<% document_index_views.each do |view, config| %>
<% document_index_view_controls.each do |view, config| %>
<%= link_to url_for(search_state.to_h.merge(view: view)), title: view_label(view), class: "btn btn-secondary view-type-#{ view.to_s.parameterize } #{"active" if document_index_view_type == view}" do %>
<%= render_view_type_group_icon view %>
<span class="caption"><%= view_label(view) %></span>
Expand Down
15 changes: 15 additions & 0 deletions spec/views/catalog/_view_type_group.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@
expect(rendered).to have_selector('.view-type-c', :text => 'c')
end

it "hides views that are set to not display" do
blacklight_config.configure do |config|
config.view.delete(:list)
config.view.a
config.view.b
config.view.b.display_control = false
end

render partial: 'catalog/view_type_group'

expect(rendered).to have_selector('.btn-group.view-type-group')
expect(rendered).to have_selector('.view-type-a', text: 'a')
expect(rendered).not_to have_selector('.view-type-b', text: 'b')
end

it "sets the current view to 'active'" do
blacklight_config.configure do |config|
config.view.delete(:list)
Expand Down

0 comments on commit 478de81

Please sign in to comment.