From 631eac6150924b593b16b3463feba6208fb66535 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 3 Oct 2018 15:54:38 -0500 Subject: [PATCH 1/2] Respect the type specific show field config If you add configuration like: ```ruby config.for_display_type 'Person' do config.add_show_field 'name_tsim', label: 'Name' end ``` Then, that config should be used to draw the pages that have documents with that type. --- .rubocop_todo.yml | 6 ++---- .../blacklight/configuration_helper_behavior.rb | 8 +++++--- app/presenters/blacklight/index_presenter.rb | 5 +++++ app/presenters/blacklight/show_presenter.rb | 5 +++++ app/views/catalog/_index.html.erb | 6 +++--- app/views/catalog/_show.html.erb | 2 +- app/views/catalog/index.json.jbuilder | 2 +- app/views/catalog/show.json.jbuilder | 2 +- lib/blacklight/configuration.rb | 12 ++++++++++++ .../blacklight/templates/catalog_controller.rb | 4 ++-- spec/models/blacklight/configuration_spec.rb | 16 ++++++++++++++-- .../{ => blacklight}/index_presenter_spec.rb | 14 ++++++++++++-- .../{ => blacklight}/show_presenter_spec.rb | 14 ++++++++++++-- 13 files changed, 75 insertions(+), 21 deletions(-) rename spec/presenters/{ => blacklight}/index_presenter_spec.rb (95%) rename spec/presenters/{ => blacklight}/show_presenter_spec.rb (97%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 746626e848..405909813b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -202,8 +202,6 @@ Lint/UselessAssignment: - 'spec/helpers/blacklight/configuration_helper_behavior_spec.rb' - 'spec/helpers/catalog_helper_spec.rb' - 'spec/models/blacklight/solr/search_builder_spec.rb' - - 'spec/presenters/index_presenter_spec.rb' - - 'spec/presenters/show_presenter_spec.rb' - 'spec/services/blacklight/search_service_spec.rb' - 'spec/support/features/session_helpers.rb' @@ -399,7 +397,7 @@ RSpec/IteratedExpectation: RSpec/MessageChain: Exclude: - 'spec/controllers/bookmarks_controller_spec.rb' - - 'spec/presenters/show_presenter_spec.rb' + - 'spec/presenters/blacklight/show_presenter_spec.rb' - 'spec/views/shared/_user_util_links.html.erb_spec.rb' # Offense count: 52 @@ -428,7 +426,7 @@ RSpec/RepeatedDescription: - 'spec/helpers/blacklight/facets_helper_behavior_spec.rb' - 'spec/helpers/catalog_helper_spec.rb' - 'spec/models/blacklight/solr/search_builder_spec.rb' - - 'spec/presenters/show_presenter_spec.rb' + - 'spec/presenters/blacklight/show_presenter_spec.rb' # Offense count: 4 RSpec/RepeatedExample: diff --git a/app/helpers/blacklight/configuration_helper_behavior.rb b/app/helpers/blacklight/configuration_helper_behavior.rb index 566e63eb54..6f7471bbed 100644 --- a/app/helpers/blacklight/configuration_helper_behavior.rb +++ b/app/helpers/blacklight/configuration_helper_behavior.rb @@ -6,6 +6,7 @@ module Blacklight::ConfigurationHelperBehavior # @param [SolrDocument] document # @return [Array] def index_fields _document = nil + Deprecation.warn(self, "index_fields is deprecated and will be removed in Blacklight 8. Use IndexPresenter#fields instead") blacklight_config.index_fields end @@ -27,8 +28,9 @@ def search_field_options_for_select end.compact end - # used in the catalog/_show/_default partial + # used in the catalog/_show partial def document_show_fields _document = nil + Deprecation.warn(self, "document_show_fields is deprecated and will be removed in Blacklight 8. Use ShowPresenter#fields instead") blacklight_config.show_fields end @@ -53,7 +55,7 @@ def default_search_field?(selected_search_field) ## # Look up the label for the index field def index_field_label document, field - field_config = index_fields(document)[field] + field_config = blacklight_config.index_fields_for(document)[field] field_config ||= Blacklight::Configuration::NullField.new(key: field) field_config.display_label('index') @@ -62,7 +64,7 @@ def index_field_label document, field ## # Look up the label for the show field def document_show_field_label document, field - field_config = document_show_fields(document)[field] + field_config = blacklight_config.show_fields_for(document)[field] field_config ||= Blacklight::Configuration::NullField.new(key: field) field_config.display_label('show') diff --git a/app/presenters/blacklight/index_presenter.rb b/app/presenters/blacklight/index_presenter.rb index 3cdf443d0b..11739140cf 100644 --- a/app/presenters/blacklight/index_presenter.rb +++ b/app/presenters/blacklight/index_presenter.rb @@ -16,6 +16,11 @@ def initialize(document, view_context, configuration = view_context.blacklight_c @view_config = configuration.view_config(view_context.document_index_view_type) end + # @return [Hash] + def fields + configuration.index_fields_for(document) + end + ## # Render the document index heading # diff --git a/app/presenters/blacklight/show_presenter.rb b/app/presenters/blacklight/show_presenter.rb index a8b07be4d6..891c807e23 100644 --- a/app/presenters/blacklight/show_presenter.rb +++ b/app/presenters/blacklight/show_presenter.rb @@ -12,6 +12,11 @@ def initialize(document, view_context, configuration = view_context.blacklight_c @configuration = configuration end + # @return [Hash] + def fields + configuration.show_fields_for(document) + end + ## # Create links from a documents dynamically # provided export formats. Returns empty string if no links available. diff --git a/app/views/catalog/_index.html.erb b/app/views/catalog/_index.html.erb index acce4b41cc..b170e907e5 100644 --- a/app/views/catalog/_index.html.erb +++ b/app/views/catalog/_index.html.erb @@ -1,8 +1,8 @@ -<% doc_presenter = index_presenter(document) %> +<% doc_presenter = index_presenter(document) %> <%# default partial to display solr document fields in catalog index view -%>