Skip to content

Commit

Permalink
link relatedItem[@otherType] values to facet if configured (DLC-1144)
Browse files Browse the repository at this point in the history
- replace deprecated field configuration key link_to_search with link_to_facet
  • Loading branch information
barmintor committed Jul 26, 2024
1 parent c559373 commit db0b29f
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/controllers/iiif/presentations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Iiif::PresentationsController < ApplicationController

configure_blacklight do |config|
Dcv::Configurators::DcvBlacklightConfigurator.configure(config)
config.show_fields.each { |field_key, show_field| show_field.link_to_search = false }
config.show_fields.each { |field_key, show_field| show_field.link_to_facet = false }
end

layout false
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/field_display_helpers/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def display_names_with_roles(args={})
field_config = blacklight_config.show_fields[args[:field]]
end

default_field = field_config.link_to_search if blacklight_config.facet_fields[field_config.link_to_search]
default_field = field_config.link_to_facet if blacklight_config.facet_fields[field_config.link_to_facet]
names.map do |name, role_info|
facet_field = role_info[:fields].detect { |field_name| blacklight_config.facet_fields[field_name]} || default_field
value = (!args[:suppress_links] && facet_field) ?
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/field_display_helpers/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def show_digital_project?(field_config, document)
end

def show_field_project_to_facet_link(args)
return args[:document][args[:field]] unless blacklight_config.show_fields[args[:field]].link_to_search
return args[:document][args[:field]] unless blacklight_config.show_fields[args[:field]].link_to_facet
projects_config = Rails.application.config_for(:hyacinth_projects)

display_values = args[:document][args[:field]]
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/field_display_helpers/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def show_field_repository_to_facet_link(args)
facet_value = full_repo_names_to_short_repo_names[display_value]
end

url_for_facet_search = search_action_path(:f => {facet_field_name => [facet_value]}) if blacklight_config.show_fields[args[:field]].link_to_search
url_for_facet_search = search_action_path(:f => {facet_field_name => [facet_value]}) if blacklight_config.show_fields[args[:field]].link_to_facet

if display_value == 'Non-Columbia Location' && args[:document]['lib_repo_text_ssm'].present?
result_src = [args[:document]['lib_repo_text_ssm'].first]
Expand Down
4 changes: 2 additions & 2 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Site < ApplicationRecord

Dcv::Configurators::DcvBlacklightConfigurator.configure_show_fields(config)
field_name = 'lib_repo_short_ssim'
config.show_fields[field_name].link_to_search = false
config.show_fields[field_name].link_to_facet = false
field_name = 'lib_project_full_ssim'
config.show_fields[field_name].link_to_search = false
config.show_fields[field_name].link_to_facet = false

Dcv::Configurators::DcvBlacklightConfigurator.configure_citation_fields(config)
Dcv::Configurators::DcvBlacklightConfigurator.configure_sort_fields(config)
Expand Down
5 changes: 5 additions & 0 deletions app/presenters/dcv/field_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ def label(context = 'index', **options)
super
end
end
def pipeline_steps
upstream_operations = Blacklight::Rendering::Pipeline.operations.dup
upstream_operations.index(Blacklight::Rendering::LinkToFacet)&.tap { |ix| upstream_operations[ix] = Rendering::LinkToFacet }
(options[:steps] || field_config[:steps] || upstream_operations) - except_operations
end
end
end
15 changes: 15 additions & 0 deletions app/presenters/dcv/rendering/link_to_facet.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Dcv
module Rendering
class LinkToFacet < Blacklight::Rendering::LinkToFacet
def render
return next_step(values) unless linkable_facet

next_step(render_link)
end

def linkable_facet
config.link_to_facet && context.blacklight_config.facet_fields[link_field]
end
end
end
end
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 @@ -63,7 +63,7 @@ def self.configure(config, fulltext: true)
# The ordering of the field names is the order of the display
# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
config.add_show_field 'lib_name_ssm', label: 'Name', link_to_search: 'lib_name_sim', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_show_field 'lib_name_ssm', label: 'Name', link_to_facet: 'lib_name_sim', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_show_field 'title_display_ssm', label: 'Title'
config.add_show_field 'abstract_ssm', label: 'Abstract', helper_method: :expandable_past_400
config.add_show_field 'lib_collection_ssm', label: 'Collection Name', helper_method: :display_collection_with_links
Expand Down
12 changes: 6 additions & 6 deletions lib/dcv/configurators/dcv_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def self.configure_index_fields(config)
# The ordering of the field names is the order of the display
def self.configure_show_fields(config)
configure_file_show_fields(config)
config.add_show_field 'lib_name_ssm', label: 'Name', link_to_search: 'lib_name_sim', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_show_field 'rel_other_project_ssim', :label => 'Project'
config.add_show_field 'lib_name_ssm', label: 'Name', link_to_facet: 'lib_name_sim', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_show_field 'rel_other_project_ssim', label: 'Project', link_to_facet: true
config.add_show_field 'title_display_ssm', label: 'Title'
config.add_show_field 'alternative_title_ssm', :label => 'Other Titles'
config.add_show_field 'abstract_ssm', label: 'Abstract', helper_method: :expandable_past_400, iiif: false
Expand All @@ -132,14 +132,14 @@ def self.configure_show_fields(config)
config.add_show_field 'lib_date_textual_ssm', :label => 'Date', :helper_method => :show_date_field
config.add_show_field 'physical_description_extent_ssm', :label => 'Physical Description'
config.add_show_field 'dynamic_notes', pattern: /lib_.*_notes_ssm/, label: :notes_label, helper_method: :expandable_past_250, unless: :is_excepted_dynamic_field?, except: ['lib_acknowledgment_notes_ssm'], join: false
config.add_show_field 'language_language_term_text_ssim', :label => 'Language', :link_to_search => 'language_language_term_text_ssim'
config.add_show_field 'language_language_term_text_ssim', label: 'Language', link_to_facet: 'language_language_term_text_ssim'
config.add_show_field 'table_of_contents_ssm', :label => 'Contents'
config.add_show_field 'lib_repo_short_ssim', label: 'Library Location', helper_method: :show_field_repository_to_facet_link, link_to_search: true, iiif: false
config.add_show_field 'lib_repo_short_ssim', label: 'Library Location', helper_method: :show_field_repository_to_facet_link, link_to_facet: true, iiif: false
config.add_show_field 'location_sublocation_ssm', :label => 'Department'
config.add_show_field 'clio_ssim', label: 'Catalog Record', helper_method: :render_link_to_clio, join: false
config.add_show_field 'lib_part_ssm', :label => 'Part'
config.add_show_field 'lib_project_full_ssim', label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_search: :project_key, if: :show_digital_project?, unless_fields: :project_key_ssim
config.add_show_field 'project_key_ssim', label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_search: :project_key, if: :show_digital_project?
config.add_show_field 'lib_project_full_ssim', label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_facet: :project_key, if: :show_digital_project?, unless_fields: :project_key_ssim
config.add_show_field 'project_key_ssim', label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_facet: :project_key, if: :show_digital_project?
config.add_show_field 'other_sites_data', :label => 'Also In', :helper_method => :show_link_to_other_site_home
# Note: Do NOT show the access_condition field. See DCV-465 for explanation.
#config.add_show_field 'access_condition_ssim', :label => 'Rights'
Expand Down
2 changes: 1 addition & 1 deletion lib/dcv/configurators/jay_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.configure(config)
config.add_show_field 'title_display_ssm', :label => 'Title'
config.add_show_field 'alternative_title_ssm', :label => 'Alternative Titles'
config.add_show_field 'lib_repo_full_ssim', :label => 'Library Location', :helper_method => :show_field_repository_to_facet_link
config.add_show_field 'lib_name_ssm', label: 'Name', link_to_search: 'lib_name_sim', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_show_field 'lib_name_ssm', label: 'Name', link_to_facet: 'lib_name_sim', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_show_field 'lib_format_ssm', :label => 'Format'
config.add_show_field 'lib_project_full_ssim', :label => 'Digital Project'
config.add_show_field 'lib_collection_ssm', :label => 'Collection'
Expand Down
4 changes: 2 additions & 2 deletions lib/dcv/configurators/lcaaj_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def self.configure(config)
# The ordering of the field names is the order of the display
config.add_show_field 'title_display_ssm', :label => 'Title'
config.add_show_field 'lib_repo_full_ssim', :label => 'Library Location', :helper_method => :show_field_repository_to_facet_link
config.add_show_field 'role_interviewer_ssim', :label => 'Interviewer', :sort => 'index', :link_to_search => 'role_interviewer_ssim'
config.add_show_field 'role_interviewee_ssim', :label => 'Interviewee', :sort => 'index', :link_to_search => 'role_interviewee_ssim'
config.add_show_field 'role_interviewer_ssim', label: 'Interviewer', sort: 'index', link_to_facet: 'role_interviewer_ssim'
config.add_show_field 'role_interviewee_ssim', label: 'Interviewee', sort: 'index', link_to_facet: 'role_interviewee_ssim'
config.add_show_field 'lib_format_ssm', :label => 'Format'
config.add_show_field 'subject_hierarchical_geographic_region_ssim', :label => 'Region'
config.add_show_field 'subject_hierarchical_geographic_city_ssim', :label => 'City'
Expand Down
8 changes: 4 additions & 4 deletions lib/dcv/configurators/nyre_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def self.configure(config)
config.add_index_field 'lib_date_textual_ssm', :label => 'Date'
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 'classification_other_ssim', label: 'Call Number'
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 All @@ -62,9 +62,9 @@ def self.configure(config)
# The ordering of the field names is the order of the display
config.add_show_field 'title_display_ssm', :label => 'Title'
config.add_show_field 'lib_repo_full_ssim', :label => 'Library Location', :helper_method => :show_field_repository_to_facet_link
config.add_show_field 'role_architect_ssim', :label => 'Architect', :link_to_search => 'role_architect_ssim'
config.add_show_field 'role_owner_agent_ssim', :label => 'Owner/Agent', :link_to_search => 'role_owner_agent_ssim'
config.add_show_field 'classification_other_ssim', :label => 'Call Number', :link_to_search => 'classification_other_ssim'
config.add_show_field 'role_architect_ssim', label: 'Architect', link_to_facet: 'role_architect_ssim'
config.add_show_field 'role_owner_agent_ssim', label: 'Owner/Agent', link_to_facet: 'role_owner_agent_ssim'
config.add_show_field 'classification_other_ssim', label: 'Call Number', link_to_facet: 'classification_other_ssim'
config.add_show_field 'lib_format_ssm', :label => 'Format'
config.add_show_field 'subject_hierarchical_geographic_region_ssim', :label => 'Region'
config.add_show_field 'subject_hierarchical_geographic_city_ssim', :label => 'City'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.configure(config)
# The ordering of the field names is the order of the display
config.add_show_field 'title_display_ssm', :label => 'Title'
config.add_show_field 'alternative_title_ssm', :label => 'Alternative Titles'
config.add_show_field 'primary_name_ssm', :label => 'Seminar Number', :link_to_search => 'primary_name_sim'
config.add_show_field 'primary_name_ssm', label: 'Seminar Number', link_to_facet: 'primary_name_sim'
config.add_show_field 'lib_date_textual_ssm', :label => 'Date'
config.add_show_field 'lib_non_date_notes_ssm', :label => 'Note'
config.add_show_field 'lib_date_notes_ssm', :label => 'Date Note'
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/field_display_helpers/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
let(:field_name) { :project_key_ssim }
let(:field_values) { ['test'] }
before do
blacklight_config.add_show_field field_name, label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_search: true
blacklight_config.add_show_field field_name, label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_facet: true
end
it { is_expected.to satisfy {|x| x.length == field_values.length} }
it { is_expected.to satisfy {|x| x[0].include?(">Successful Project Mapping For Full Project Title</a>") } }
end
context "field is not linked" do
before do
blacklight_config.add_show_field field_name, label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_search: false
blacklight_config.add_show_field field_name, label: 'Digital Project', helper_method: :show_field_project_to_facet_link, link_to_facet: false
end
it { is_expected.to satisfy {|x| x.length == 2} }
it { is_expected.to satisfy {|x| x[0].eql?("Project 1") && x[1].eql?("Project 2") } }
Expand Down
30 changes: 30 additions & 0 deletions spec/presenters/dcv/field_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'rails_helper'

describe Dcv::FieldPresenter do
include_context "a solr document"

let(:blacklight_config) { Blacklight::Configuration.new }
let(:search_action_path) { '/search' }
let(:search_state) { Dcv::SearchState.new({}, blacklight_config) }
let(:view_context) { double(ActionController::Base, blacklight_config: blacklight_config, search_state: search_state, search_action_path: search_action_path) }
let(:presenter) { described_class.new(view_context, solr_document, blacklight_config.show_fields['dc_type_ssm']) }

before do
blacklight_config.add_show_field 'dc_type_ssm', label: 'DcType', link_to_facet: true
end

it "does not link the values without a configured facet" do
expect(presenter.render).to eql "Unknown"
end

context "facet field is configured" do
before do
blacklight_config.add_facet_field 'dc_type_ssm', label: 'DcType'
allow(view_context).to receive(:link_to).and_return ('success')
end

it "links the values" do
expect(presenter.render).to eql "success"
end
end
end

0 comments on commit db0b29f

Please sign in to comment.