Skip to content

Commit

Permalink
DLC-1143 Rudimentary configuration of grid-mode index field display
Browse files Browse the repository at this point in the history
- rename tombstone field refs in code to grid_display for clarity
- fix test fixture for site config with grid_display_fields
  • Loading branch information
barmintor committed Jul 26, 2024
1 parent 8a0b364 commit c559373
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 34 deletions.
6 changes: 3 additions & 3 deletions app/components/dcv/document_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="document w-100 <%= @search_view %> <%= render_document_class @document %>" itemscope itemtype="<%= @document.itemtype %>">
<div class="card bg-transparent <%= (@document.site_result? ? 'site-result' : '') %>" data-number-of-members="<%= @document[:cul_number_of_members_isi] || -1 %>">
<%= linked_thumbnail %>
<%= thumbnail %>
<div class="card-body">
<h3 class="card-title index_title mb-0"><%= t('blacklight.search.documents.counter', counter: @counter) if @show_counter %>
<%= document_link %>
Expand All @@ -9,8 +9,8 @@
<% end %>
</h3>
<div class="card-text index-show-grid-fields">
<% document_tombstone_fields(@document).each do |field, field_config| -%>
<%= render_document_tombstone_field_value(@document, field) %>
<% each_grid_field(@document) do |field, _field_config| -%>
<%= render_grid_field_value(document: @document, field: field) %>
<% end -%>
</div>
<div class="card-text index-show-list-fields">
Expand Down
30 changes: 23 additions & 7 deletions app/components/dcv/document_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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 :byte_size_to_text_string, :render_document_class, :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 All @@ -48,6 +48,7 @@ def before_render
# @search_session = helpers.search_session
@search_view ||= "#{controller.default_search_mode}-view"
# part of superclass in BL8
with_thumbnail(linked_thumbnail) unless thumbnail
unless partials?
@view_partials&.each do |view_partial|
with_partial(view_partial) do
Expand Down Expand Up @@ -85,10 +86,25 @@ def short_title
title
end

def document_tombstone_fields(document = nil)
# Iterate over each field that is displayable in the site context for grid mode search results
# These will be yields in the order of configuration for grid mode, and then within the Blacklight
# index field definitions
def each_grid_field(document = @document)
return unless document
# the True key here supports custom sites with dedicated Blacklight configurators
grid_field_types = [true] + load_subsite.search_configuration.display_options.grid_field_types
grid_fields = grid_field_types.map {|x| [x, []]}.to_h
helpers.blacklight_config.index_fields.select do |field, field_config|
field_config[:tombstone_display] && document[field].present?
end.to_h
grid_key = (grid_field_types & Array(field_config[:grid_display])).first
grid_fields[grid_key] << [field, field_config] if grid_key && document[field].present?
end
grid_field_types.each do |type|
grid_fields[type].each { |gf| yield gf[0], gf[1] }
end
end

def render_grid_field_value(document:, field:, **_args)
content_tag(:div, Array(document[field]).first, class: "ellipsis")
end
end
end
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, :grid_field_types],
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['grid_field_types'] = display_options['grid_field_types'].split(',').map(&:strip) if display_options&.fetch('grid_field_types', nil)
end
end
end
Expand Down
8 changes: 0 additions & 8 deletions app/helpers/dcv/field_sets_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,4 @@ def document_citation_fields(document = nil)
def document_geo_fields(document = nil)
blacklight_config.geo_fields
end

def render_document_tombstone_field_value *args
options = args.extract_options!
document = args.shift || options[:document]

field = args.shift || options[:field]
content_tag(:div, Array(document[field]).first, class: "ellipsis")
end
end
26 changes: 21 additions & 5 deletions app/models/site/display_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,40 @@ 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, :grid_field_types
attr_accessor :default_search_mode, :show_csv_results, :show_original_file_download, :show_other_sources, :grid_field_types

VALID_SEARCH_MODES = ['grid', 'list'].freeze
VALID_SEARCH_MODES = %w(grid list).freeze
VALID_GRID_FIELD_TYPES = %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, grid_field_types: ['name'] }
end

def initialize(atts = {})
atts = default_configuration.merge(atts.symbolize_keys).with_indifferent_access
correct_deprecated_att_names(atts)
assign_attributes(atts)
clear_changes_information
end

# deletable after staging data is corrected for DLC-1143
def correct_deprecated_att_names(atts)
# deletable after staging data is corrected
renamed_tombstone_fields = atts.delete(:tombstone_fields)
atts[:grid_field_types] = renamed_tombstone_fields if renamed_tombstone_fields.present?
end

def default_search_mode=(val)
@default_search_mode = VALID_SEARCH_MODES.include?(val) ? val : 'grid'
end

def grid_field_types=(vals)
@grid_field_types = Array(vals).map(&:to_s).map(&:downcase).select { |v| VALID_GRID_FIELD_TYPES.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 +70,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,
'grid_field_types' => @grid_field_types || []
}.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_grid_field_types">"Tombstone" Grid Result Display <span class="fa fa-question-circle" data-tooltip="tooltip-display-tombstone"></span></label>
<%= options_form.text_field(:grid_field_types, {value: @subsite.search_configuration.display_options.grid_field_types.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' Grid Result Display">Configure the field types (<%= Site::DisplayOptions::VALID_GRID_FIELD_TYPES.join(", ") %>) to display in search result "tombstones" (the compact/grid view).</span>
</div>
2 changes: 1 addition & 1 deletion lib/dcv/configurators/carnegie_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.configure(config, fulltext: true)
config.add_index_field 'lib_date_textual_ssm', :label => 'Date'
config.add_index_field 'lib_collection_ssm', label: 'Collection Name', helper_method: :display_composite_archival_context
config.add_index_field 'abstract_ssm', label: 'Abstract', helper_method: :expandable_past_250
config.add_index_field 'lib_name_ssm', label: 'Name', tombstone_display: true, if: false
config.add_index_field 'lib_name_ssm', label: 'Name', grid_display: true, if: false


# solr fields to be displayed in the show (single result) view
Expand Down
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', grid_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', grid_display: ['name'], if: false
config.add_index_field 'lib_format_ssm', label: 'Format', grid_display: ['format'], if: false
end

# solr fields to be displayed in the show (single result) view
Expand Down
4 changes: 2 additions & 2 deletions lib/dcv/configurators/durst_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def self.configure(config)

# solr fields to be displayed in the index (search results) view
# The ordering of the field names is the order of the display
config.add_index_field 'primary_name_ssm', label: 'Name', tombstone_display: true
config.add_index_field 'primary_name_ssm', label: 'Name', grid_display: true
config.add_index_field 'lib_date_textual_ssm', :label => 'Published', accessor: :published_origin_information, if: :has_publication_info?
config.add_index_field 'lib_format_ssm', label: 'Format', tombstone_display: true
config.add_index_field 'lib_format_ssm', label: 'Format', grid_display: true
config.add_index_field 'lib_non_item_in_context_url_ssm', label: 'Online', link_label: 'click here for full-text', helper_method: :render_link_to_external_resource, join: false
config.add_index_field 'clio_ssim', label: 'Catalog Record', link_label: 'check availability', helper_method: :render_link_to_clio, join: false

Expand Down
2 changes: 1 addition & 1 deletion lib/dcv/configurators/ifp_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.configure(config)
#config.add_index_field 'title_display_ssm', :label => 'Title'
config.add_index_field 'contributor_ssim', label: 'Office'
config.add_index_field 'original_name_ssim', label: 'Folder Path', helper_method: :dirname_prefixed_with_slash
config.add_index_field 'lib_name_ssm', label: 'Name', tombstone_display: true, if: false
config.add_index_field 'lib_name_ssm', label: 'Name', grid_display: true, if: false

# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
Expand Down
2 changes: 1 addition & 1 deletion lib/dcv/configurators/lcaaj_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def self.configure(config)
# The ordering of the field names is the order of the display
#config.add_index_field 'title_display_ssm', :label => 'Title'
config.add_index_field 'lib_repo_long_ssim', :label => 'Library Location'
config.add_index_field 'lib_name_ssm', label: 'Name', tombstone_display: true
config.add_index_field 'lib_name_ssm', label: 'Name', grid_display: true
config.add_index_field 'location_sublocation_ssm', :label => 'Department'
config.add_index_field 'location_shelf_locator_ssm', :label => 'Shelf Location'
config.add_index_field 'lib_date_textual_ssm', :label => 'Date'
Expand Down
2 changes: 1 addition & 1 deletion lib/dcv/configurators/nyre_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def self.configure(config)
config.add_index_field 'abstract_ssm', :label => 'Summary', :helper_method => :truncate_text_to_250
config.add_index_field 'cul_number_of_members_isi', :label => 'Number of Images'
config.add_index_field 'classification_other_ssim', :label => 'Call Number', :link_to_search => 'classification_other_ssim'
config.add_index_field 'lib_name_ssm', label: 'Name', tombstone_display: true, if: false
config.add_index_field 'lib_name_ssm', label: 'Name', grid_display: true, if: false

# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
Expand Down
30 changes: 28 additions & 2 deletions spec/components/dcv/document_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
describe '#short_title' do
let(:long_title) { '0123456789abcdefghijklmnopqrstuvwxyz' }
let(:short_title) { '0123456789abc' }
let(:document) { { 'title_ssm' => title_value } }
let(:solr_data) { { 'title_ssm' => title_value } }
let(:view_context) { Struct.new(:document_index_view_type).new(:index) }
let(:blacklight_config) { Blacklight::Configuration.new }
let(:presenter) { double(Dcv::ShowPresenter, document: document, heading: title_value) }
Expand All @@ -72,8 +72,34 @@

context "no title" do
let(:title_value) { nil }
let(:document) { { 'some_field' => 'some_value' } }
let(:solr_data) { { 'some_field' => 'some_value' } }
it { is_expected.to be_nil }
end
end
describe '#each_grid_field' do
let(:subsite) { instance_double(Site, search_configuration: search_configuration) }
let(:search_configuration) { instance_double(Site::SearchConfiguration, display_options: display_options) }
let(:display_options) { instance_double(Site::DisplayOptions, grid_field_types: ['format']) }
let(:blacklight_config) { Blacklight::Configuration.new }
let(:solr_data) { { 'ignored_ssm' => ['text value'], 'configured_type_ssm' => ['format value'], 'default_ssm' => ['default value'] } }
let(:listed_fields) do
_val = []
component.each_grid_field do |field, field_config|
_val << field
end
_val
end
before do
blacklight_config.add_index_field 'ignored_ssm', :label => 'Text'
blacklight_config.add_index_field 'configured_type_ssm', label: 'Format', grid_display: ['format']
blacklight_config.add_index_field 'default_ssm', label: 'Name', grid_display: true
blacklight_config.add_index_field 'missing_ssm', label: 'Missing', grid_display: ['format']
allow(controller.helpers).to receive(:blacklight_config).and_return(blacklight_config)
allow(controller).to receive(:load_subsite).and_return(subsite)
component.instance_variable_set(:@view_context, view_context)
end
it "yields in the expected configuration order" do
expect(listed_fields).to eql ['default_ssm', 'configured_type_ssm']
end
end
end
11 changes: 11 additions & 0 deletions spec/features/sites/search_configuration_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
expect(find_field('site[search_configuration][facets][1][facet_fields_form_value]').value).to eq("level_one_field_sim,level_2_field_sim")
expect(find_field('site[search_configuration][facets][1][label]').value).to eq("Levels")
end
it 'updates grid display field configuration' do
# verify the initial value from the import
expect(find_field('site[search_configuration][display_options][grid_field_types]').value).to eq("project, name")
page.fill_in('site[search_configuration][display_options][grid_field_types]', with: 'format, project')
click_button "Update Search Configuration"
# do a find to make sure page loaded
find('#site_search_configuration_display_options_grid_field_types')
visit(edit_link_href)
# verify the value update
expect(find_field('site[search_configuration][display_options][grid_field_types]').value).to eq("format, project")
end
end
describe '#edit' do
before do
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/sites/import/directory/properties.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ search_configuration:
show_csv_results: true
show_original_file_download: false
show_other_sources: false
grid_field_types:
- project
- name
facets:
- field_name: role_test_sim
label: Test Names
Expand Down

0 comments on commit c559373

Please sign in to comment.