From 41fb6aae6e8a8ccbb462aa8a94599fe9dc5f2cbc Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Thu, 27 Apr 2017 11:57:31 -0700 Subject: [PATCH] Add 'display_control' option to view configs to allow them to toggle on/off visibility in the view type widget --- .../blacklight/configuration_helper_behavior.rb | 9 ++++++++- app/views/catalog/_view_type_group.html.erb | 2 +- spec/helpers/configuration_helper_spec.rb | 12 ++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/helpers/blacklight/configuration_helper_behavior.rb b/app/helpers/blacklight/configuration_helper_behavior.rb index 1f4b2825c5..333b91604e 100644 --- a/app/helpers/blacklight/configuration_helper_behavior.rb +++ b/app/helpers/blacklight/configuration_helper_behavior.rb @@ -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 diff --git a/app/views/catalog/_view_type_group.html.erb b/app/views/catalog/_view_type_group.html.erb index d6833ccb26..c96a262ade 100644 --- a/app/views/catalog/_view_type_group.html.erb +++ b/app/views/catalog/_view_type_group.html.erb @@ -2,7 +2,7 @@
<%= t('blacklight.search.view_title') %>
- <% 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 %> <%= view_label(view) %> diff --git a/spec/helpers/configuration_helper_spec.rb b/spec/helpers/configuration_helper_spec.rb index 155ff9b192..3e68d22fd7 100644 --- a/spec/helpers/configuration_helper_spec.rb +++ b/spec/helpers/configuration_helper_spec.rb @@ -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