Skip to content

Commit

Permalink
Allow for titles to be changed.
Browse files Browse the repository at this point in the history
Closes #375
  • Loading branch information
tpendragon committed Feb 11, 2019
1 parent 0caf09e commit c63630b
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def current_year
def text_area?(field, exhibit)
index_field_config = exhibit.blacklight_config.index_fields[field.field]

index_field_config.text_area == "1"
index_field_config.respond_to?(:text_area) && index_field_config.text_area == "1"
end

def text_area_value(field, sidecar)
Expand Down
11 changes: 10 additions & 1 deletion app/presenters/rtl_index_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,22 @@ def value_from_symbol(field)
default_title_field = @configuration.index.title_field.to_sym
display_title_field = @configuration.index.display_title_field.to_sym

# When asked for a title, display the override title if it's present.
if field == default_title_field && @document.key?(display_title_field)
@document[display_title_field]
@document[override_title_field] || @document[display_title_field]
else
@document[field]
end
end

def exhibit_prefix
@exhibit_prefix ||= configuration.facet_fields["exhibit_tags"].field.gsub("tags_ssim", "")
end

def override_title_field
:"#{exhibit_prefix}override-title_ssim"
end

def label_value(value, config)
if value.is_a?(Array) && value.count > 1
value.collect { |v| field_values(config, value: v.html_safe) }
Expand Down
21 changes: 19 additions & 2 deletions app/presenters/rtl_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,37 @@ def field_value(field, options = {})
end

def header
fields = Array.wrap(view_config.title_field)
fields = Array.wrap(title_field)
f = fields.detect { |field| @document.has? field }
f ||= @configuration.document_model.unique_key
@document[f].to_sentence(field_config(f).separator_options)
field_value(f, value: @document[f].map(&:html_safe))
end

def heading
fields = Array.wrap(view_config.title_field)
fields = Array.wrap(title_field)
f = fields.detect { |field| document.has? field }
f ||= configuration.document_model.unique_key
field_values(field_config(f), value: document[f].map(&:html_safe))
end

# Automatically display the override title if it's present.
def title_field
if @document.has?(override_title_field) && @document[override_title_field].present?
override_title_field
else
view_config.title_field
end
end

def exhibit_prefix
@exhibit_prefix ||= configuration.facet_fields["exhibit_tags"].field.gsub("tags_ssim", "")
end

def override_title_field
:"#{exhibit_prefix}override-title_ssim"
end

def html_title
super.split("<br />").map(&:html_safe).join(", ")
end
Expand Down
20 changes: 19 additions & 1 deletion app/services/iiif_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def noid
def manifest_metadata
metadata = metadata_class.new(manifest).to_solr
return {} if metadata.blank?
metadata = default_metadata(metadata).merge(metadata)
create_sidecars_for(*metadata.keys)

metadata.each_with_object({}) do |(key, value), hash|
Expand All @@ -71,10 +72,27 @@ def manifest_metadata
end
end

# When importing a IIIF Resource the first time, create an "Override Title" field.
def default_metadata(metadata)
return {} if metadata["Title"].blank?
{
"Override Title" => nil
}
end

def create_sidecars_for(*keys)
missing_keys(keys).each do |k|
exhibit.custom_fields.create! label: k, readonly_field: true, field_type: "vocab"
readonly = k != "Override Title"
field = exhibit.custom_fields.create! label: k, readonly_field: readonly, field_type: "vocab"
field.update(configuration: field.configuration.merge("if" => false)) if disabled_fields.include?(k)
end
@exhibit_custom_fields = nil
end

def disabled_fields
[
"Override Title",
"Title"
]
end
end
1 change: 1 addition & 0 deletions app/values/manifest_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def language_name(value)
ISO_639.find_by_code(value).try(:english_name) || value
end
end

def process_values(input_hash)
h = Hash[input_hash.map do |key, values|
Value.new(key, values).to_pair
Expand Down
3 changes: 2 additions & 1 deletion app/views/spotlight/catalog/_edit_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<% else %>
<%= d.text_field_without_bootstrap field.field, value: document.sidecar(current_exhibit).data[field.field.to_s], class: 'form-control', readonly: field.readonly_field? %>
<% end %>
<% unless field.configured_to_display? %>
<%# Don't show a warning for the override title - it should never display in the show fields. %>
<% unless field.slug == "override-title_ssim" || field.configured_to_display? %>
<p class="bg-warning help-block">
<%= t(:'.blank_field_warning_html',
link: link_to(t(:'spotlight.configuration.sidebar.metadata'), spotlight.edit_exhibit_metadata_configuration_path(current_exhibit))) %>
Expand Down
18 changes: 18 additions & 0 deletions config/initializers/monkeypatches/spotlight_breadcrumb_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Rails.application.config.to_prepare do
module SpotlightBreadcrumbPatch
def add_document_breadcrumbs(document)
if current_browse_category
add_breadcrumb current_browse_category.exhibit.main_navigations.browse.label_or_default, exhibit_browse_index_path(current_browse_category.exhibit)
add_breadcrumb current_browse_category.title, exhibit_browse_path(current_browse_category.exhibit, current_browse_category)
elsif current_page_context && current_page_context.title.present? && !current_page_context.is_a?(Spotlight::HomePage)
add_breadcrumb current_page_context.title, [current_page_context.exhibit, current_page_context]
elsif current_search_session
add_breadcrumb t(:'spotlight.catalog.breadcrumb.index'), search_action_url(current_search_session.query_params)
end

add_breadcrumb RTLShowPresenter.new(document, self).html_title, polymorphic_path([current_exhibit, document])
end
end

Spotlight::CatalogController.prepend(SpotlightBreadcrumbPatch)
end
18 changes: 17 additions & 1 deletion spec/presenters/rtl_index_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
let(:blacklight_config) do
double(
index: index_config,
index_fields: { field: field_config }
index_fields: { field: field_config },
facet_fields: { "exhibit_tags" => double(field: "tags_ssim") }
)
end

Expand Down Expand Up @@ -55,6 +56,21 @@
end
end

context 'when an override field exists' do
let(:index_config) { double(title_field: 'title', display_title_field: 'alternate_title') }
let(:document) do
{
title: title,
alternate_title: alternate_title,
"override-title_ssim": ["Test"]
}
end

it 'renders it' do
expect(presenter.label(:title)).to eq "Test"
end
end

context 'when passed a string' do
it 'renders the string as the label' do
label_value = 'a string'
Expand Down
31 changes: 30 additions & 1 deletion spec/presenters/rtl_show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
double(
show_fields: { field:
double(highlight: false, accessor: nil, default: nil, field: :field, text_area: false, helper_method: nil, link_to_search: nil, itemprop: nil, separator_options: nil, :separator_options= => nil) },
view_config: double(title_field: :title, html_title_field: nil)
view_config: double(title_field: :title, html_title_field: nil),
facet_fields: { "exhibit_tags" => double(field: "tags_ssim") }
)
end

Expand All @@ -36,11 +37,39 @@
it "returns multiple titles appropriately" do
expect(presenter.header).to eq "<ul><li dir=\"rtl\">بي</li><li dir=\"ltr\">Traité sur l'art de la charpente : théorique et pratique</li></ul>"
end
context "when there's an override title" do
let(:document) do
SolrDocument.new(
field: ["بي"],
special: ["Traité sur l'art de la charpente : théorique et pratique"],
title: ["بي", "Traité sur l'art de la charpente : théorique et pratique"],
"override-title_ssim": ["Test"]
)
end

it "uses it" do
expect(presenter.header).to eq "<ul><li dir=\"ltr\">Test</li></ul>"
end
end
end

describe "#html_title" do
it "returns multiple titles appropriately" do
expect(presenter.html_title).to eq "بي, Traité sur l'art de la charpente : théorique et pratique"
end
context "when there's an override title" do
let(:document) do
SolrDocument.new(
field: ["بي"],
special: ["Traité sur l'art de la charpente : théorique et pratique"],
title: ["بي", "Traité sur l'art de la charpente : théorique et pratique"],
"override-title_ssim": ["Test"]
)
end

it "uses it" do
expect(presenter.html_title).to eq "Test"
end
end
end
end

0 comments on commit c63630b

Please sign in to comment.