diff --git a/app/components/dcv/document_component.rb b/app/components/dcv/document_component.rb index 434b99c5d..05c71c408 100644 --- a/app/components/dcv/document_component.rb +++ b/app/components/dcv/document_component.rb @@ -3,7 +3,7 @@ module Dcv class DocumentComponent < Blacklight::DocumentComponent delegate :byte_size_to_text_string, :render_document_class, :render_document_tombstone_field_value, :render_snippet_with_post_processing, to: :helpers - + delegate :load_subsite, to: :controller # this is a BL8 forward-compatible override # - BL8 will pass DocumentPresenter as :document # - BL8 will use ViewComponent collection iteration @@ -29,9 +29,9 @@ def initialize(document:, partials: nil, @id = id || ('document' if show) @classes = classes - @metadata_component = Blacklight::DocumentMetadataComponent + @metadata_component = metadata_component || Blacklight::DocumentMetadataComponent - @thumbnail_component = Blacklight::Document::ThumbnailComponent + @thumbnail_component = thumbnail_component || Blacklight::Document::ThumbnailComponent # ViewComponent 3 will change document_counter to be zero-based, but BL8 will accommodate @counter = document_counter + counter_offset if document_counter.present? @@ -86,8 +86,10 @@ def short_title end def document_tombstone_fields(document = nil) + tombstone_fields = load_subsite.search_configuration.display_options.tombstone_fields helpers.blacklight_config.index_fields.select do |field, field_config| - field_config[:tombstone_display] && document[field].present? + tombstone_display = (field_config[:tombstone_display] == true) || (tombstone_fields & Array(field_config[:tombstone_display])).present? + tombstone_display && document[field].present? end.to_h end end diff --git a/app/controllers/sites/search_configuration_controller.rb b/app/controllers/sites/search_configuration_controller.rb index 0150edfda..a7d6bb422 100644 --- a/app/controllers/sites/search_configuration_controller.rb +++ b/app/controllers/sites/search_configuration_controller.rb @@ -42,7 +42,7 @@ def search_configuration_params .require(:search_configuration).permit( date_search_configuration: [:enabled, :granularity_search, :show_sidebar, :show_timeline, :sidebar_label], map_configuration: [:default_lat, :default_long, :enabled, :granularity_data, :granularity_search, :show_items, :show_sidebar], - display_options: [:default_search_mode, :show_csv_results, :show_original_file_download, :show_other_sources], + display_options: [:default_search_mode, :show_csv_results, :show_original_file_download, :show_other_sources, :tombstone_fields], facets: [:facet_fields_form_value, :label, :limit, :sort, :value_transforms], search_fields: [:type, :label] )&.to_h @@ -50,6 +50,8 @@ def search_configuration_params scp&.tap do |atts| atts['search_fields'] = atts['search_fields'].values if atts&.fetch('search_fields', nil) atts['facets'] = atts['facets'].values if atts&.fetch('facets', nil) + display_options = atts['display_options'] + display_options['tombstone_fields'] = display_options['tombstone_fields'].split(',').map(&:strip) if display_options&.fetch('tombstone_fields', nil) end end end diff --git a/app/models/site/display_options.rb b/app/models/site/display_options.rb index 19041a4ac..49a0170a1 100644 --- a/app/models/site/display_options.rb +++ b/app/models/site/display_options.rb @@ -4,13 +4,16 @@ class Site::DisplayOptions include ActiveRecord::AttributeAssignment include Site::ConfigurationValues - define_attribute_methods :default_search_mode, :show_csv_results, :show_original_file_download, :show_other_sources - attr_accessor :default_search_mode, :show_csv_results, :show_original_file_download, :show_other_sources + define_attribute_methods :default_search_mode, :show_csv_results, :show_original_file_download, :show_other_sources, :tombstone_fields + attr_accessor :default_search_mode, :show_csv_results, :show_original_file_download, :show_other_sources, :tombstone_fields - VALID_SEARCH_MODES = ['grid', 'list'].freeze + VALID_SEARCH_MODES = %w(grid list).freeze + VALID_TOMBSTONE_OPTIONS = %w(format name project).freeze def default_configuration - { default_search_mode: 'grid', show_csv_results: false, show_original_file_download: false, show_other_sources: false } + { + default_search_mode: 'grid', show_csv_results: false, show_original_file_download: false, + show_other_sources: false, tombstone_fields: ['name'] } end def initialize(atts = {}) @@ -23,6 +26,10 @@ def default_search_mode=(val) @default_search_mode = VALID_SEARCH_MODES.include?(val) ? val : 'grid' end + def tombstone_fields=(vals) + @tombstone_fields = Array(vals).map(&:to_s).map(&:downcase).select { |v| VALID_TOMBSTONE_OPTIONS.include?(v) } + end + def show_csv_results=(val) val = boolean_or_nil(val) show_csv_results_will_change! unless val == @show_csv_results @@ -55,7 +62,8 @@ def serializable_hash(opts = {}) 'default_search_mode' => @default_search_mode, 'show_csv_results' => @show_csv_results, 'show_original_file_download' => @show_original_file_download, - 'show_other_sources' => @show_other_sources + 'show_other_sources' => @show_other_sources, + 'tombstone_fields' => @tombstone_fields || [] }.tap {|v| v.compact! if opts&.fetch(:compact, false)} end end \ No newline at end of file diff --git a/app/views/sites/search_configuration/_display_options_form.html.erb b/app/views/sites/search_configuration/_display_options_form.html.erb index 360187523..86dfdcc59 100644 --- a/app/views/sites/search_configuration/_display_options_form.html.erb +++ b/app/views/sites/search_configuration/_display_options_form.html.erb @@ -15,6 +15,10 @@ +
+ + <%= options_form.text_field(:tombstone_fields, {value: @subsite.search_configuration.display_options.tombstone_fields.join(", "), class: ['form-control'], disabled: !can?(:admin, @subsite)}) %> +
<%= options_form.check_box :show_csv_results, {}, "true", "false" %> @@ -40,4 +44,5 @@ Configure the site to make search results available as a CSV download (linked from the results page). Configure the site to link original file downloads where available (useful for born-digital content, such as office documents or spreadsheets). Editing is currently disabled. Configure the site to include a link to alternate search sources relevant to site content. Editing is currently disabled. + Configure the field types (<%= Site::DisplayOptions::VALID_TOMBSTONE_OPTIONS.join(", ") %>) to display in search result "tombstones" (the compact/grid view).
diff --git a/lib/dcv/configurators/dcv_blacklight_configurator.rb b/lib/dcv/configurators/dcv_blacklight_configurator.rb index eabbb2c4f..66dc914f8 100644 --- a/lib/dcv/configurators/dcv_blacklight_configurator.rb +++ b/lib/dcv/configurators/dcv_blacklight_configurator.rb @@ -99,13 +99,14 @@ def self.configure_sort_fields(config) # The ordering of the field names is the order of the display def self.configure_index_fields(config) config.add_index_field 'primary_name_ssm', label: 'Name', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names? - config.add_index_field 'rel_other_project_ssim', :label => 'Project' + config.add_index_field 'rel_other_project_ssim', label: 'Project', tombstone_display: ['project'] config.add_index_field 'lib_repo_long_ssim', :label => 'Library Location' config.add_index_field 'location_sublocation_ssm', :label => 'Department' config.add_index_field 'lib_collection_ssm', label: 'Collection Name', helper_method: :display_composite_archival_context config.add_index_field 'lib_date_textual_ssm', :label => 'Date' config.add_index_field 'lib_item_in_context_url_ssm', :label => 'Item in Context', :helper_method => :link_to_url_value - config.add_index_field 'lib_name_ssm', label: 'Name', tombstone_display: true, if: false + config.add_index_field 'lib_name_ssm', label: 'Name', tombstone_display: ['name'], if: false + config.add_index_field 'lib_format_ssm', label: 'Format', tombstone_display: ['format'], if: false end # solr fields to be displayed in the show (single result) view