Skip to content

Commit

Permalink
DLC-1143 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Jul 25, 2024
1 parent 8a0b364 commit a7b60f9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
10 changes: 6 additions & 4 deletions app/components/dcv/document_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/sites/search_configuration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ 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
# todo: find a better way to unroll the list of values
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
Expand Down
18 changes: 13 additions & 5 deletions app/models/site/display_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand All @@ -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
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
</label>
</div>
</div>
<div class="form-group">
<label for="site_search_configuration_display_options_tombstone_fields">"Tombstone" Result Display <span class="fa fa-question-circle" data-tooltip="tooltip-display-tombstone"></span></label>
<%= options_form.text_field(:tombstone_fields, {value: @subsite.search_configuration.display_options.tombstone_fields.join(", "), class: ['form-control'], disabled: !can?(:admin, @subsite)}) %>
</div>
<div class="form-group">
<label for="site_search_configuration_display_options_show_csv_results">Allow CSV Search Results <span class="fa fa-question-circle" data-tooltip="tooltip-display-csv"></span></label>
<%= options_form.check_box :show_csv_results, {}, "true", "false" %>
Expand All @@ -40,4 +44,5 @@
<span id="tooltip-display-csv" title="Allow CSV Search Results">Configure the site to make search results available as a CSV download (linked from the results page).</span>
<span id="tooltip-display-original-files" title="Allow Original File Downloads">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.</span>
<span id="tooltip-display-other-sources" title="Link to Other Search Sources">Configure the site to include a link to alternate search sources relevant to site content. Editing is currently disabled.</span>
<span id="tooltip-display-tombstone" title="'Tombstone' Result Display">Configure the field types (<%= Site::DisplayOptions::VALID_TOMBSTONE_OPTIONS.join(", ") %>) to display in search result "tombstones" (the compact/grid view).</span>
</div>
5 changes: 3 additions & 2 deletions lib/dcv/configurators/dcv_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a7b60f9

Please sign in to comment.