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 authored and jcoyne committed Aug 27, 2017
1 parent 1063daa commit 41fb6aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/helpers/blacklight/configuration_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ def document_index_views
should_render_field? config
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-default 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
12 changes: 12 additions & 0 deletions spec/helpers/configuration_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
end
end

describe '#document_index_view_controls' do
before do
blacklight_config.view.a
blacklight_config.view.b.display_control = false
end

it "filters index views to those set to display controls" do
expect(helper.document_index_view_controls).to have_key :a
expect(helper.document_index_view_controls).not_to have_key :b
end
end

describe "#has_alternative_views?" do
subject { helper.has_alternative_views?}
describe "with a single view defined" do
Expand Down

0 comments on commit 41fb6aa

Please sign in to comment.