Skip to content

Commit

Permalink
Fix indexing of Plum fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Feb 21, 2018
1 parent 0281684 commit 410fdff
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
16 changes: 16 additions & 0 deletions app/decorators/both_fields.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Decorates a Custom Field to give an accessor for the alternate suffix.
class BothFields < SimpleDelegator
def alternate_field
field.gsub(/(.*)_.*$/, '\1'+ alternate_field_suffix)
end

private

def alternate_field_suffix
if field.ends_with?(Spotlight::Engine.config.solr_fields.string_suffix)
Spotlight::Engine.config.solr_fields.text_suffix
else
Spotlight::Engine.config.solr_fields.string_suffix
end
end
end
20 changes: 20 additions & 0 deletions app/services/iiif_manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,24 @@ def noid
/.*\/(.*)\/manifest/.match(url)[1]
end
end

def manifest_metadata
metadata = metadata_class.new(manifest).to_solr
return {} unless metadata.present?
create_sidecars_for(*metadata.keys)

metadata.each_with_object({}) do |(key, value), hash|
next unless (field = exhibit_custom_fields[key])
field = BothFields.new(field)
hash[field.field] = value
hash[field.alternate_field] = value
end
end

def create_sidecars_for(*keys)
missing_keys(keys).each do |k|
exhibit.custom_fields.create! label: k, readonly_field: true, field_type: "vocab"
end
@exhibit_custom_fields = nil
end
end
22 changes: 14 additions & 8 deletions app/views/spotlight/catalog/_edit_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<%= bootstrap_form_for document, url: spotlight.polymorphic_path([current_exhibit, document]), html: {:'data-form-observer' => true, multipart: true} do |f| %>
<div class="edit-fields">

<%= f.fields_for :sidecar, document.sidecar(current_exhibit) do |c| %>
<%= c.check_box :public %>
<% end %>
<%= f.fields_for :uploaded_resource do |r| %>
<%= r.url_field :url, type: "file", help: t('.url-field.help', extensions: Spotlight::Engine.config.allowed_upload_extensions.join(' ')), label: "File" %>
<% end if document.uploaded_resource? %>
Expand All @@ -19,18 +14,29 @@
<% end %>
<% end %>
<% current_exhibit.custom_fields.each do |field| %>
<%# Using `includes(:exhibit)` to ensure all fields are using the same exhibit object to take advantage of memoization %>
<% current_exhibit.custom_fields.includes(:exhibit).to_a.uniq(&:label).each do |field| %>
<div class="form-group">
<%= d.label field.field, field.label %>
<%= d.text_field_without_bootstrap field.field, value: document.sidecar(current_exhibit).data[field.field.to_s], class: 'form-control', readonly: field.readonly_field? %>
<% if field.readonly_field? %>
<%= d.text_field_without_bootstrap field.field, value: document.sidecar(current_exhibit).data[field.field.to_s], class: 'form-control', readonly: field.readonly_field?, name: nil%>
<% 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? %>
<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))) %>
</p>
<% end %>
</div>
<% end %>
<% end %>
<% end %>
<% if can? :tag, current_exhibit %>
<div class="edit-tags">
<%= f.text_field :exhibit_tag_list, value: f.object.tags_from(current_exhibit).to_s, 'data-autocomplete_url' => exhibit_tags_path(current_exhibit, format: 'json') %>
<%= f.text_field :exhibit_tag_list, value: f.object.sidecar(current_exhibit).tags_from(current_exhibit).to_s, 'data-autocomplete_url' => exhibit_tags_path(current_exhibit, format: 'json') %>
</div>
<% end %>
<div class="form-actions">
Expand Down
2 changes: 2 additions & 0 deletions spec/models/iiif_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
expect(solr_doc["full_title_tesim"]).to eq 'Christopher and his kind, 1929-1939'
expect(solr_doc["readonly_created_tesim"]).to eq ["1976-01-01T00:00:00Z"]
expect(solr_doc["readonly_range-label_tesim"]).to eq ["Chapter 1", "Chapter 2"]
expect(Spotlight::CustomField.last.field_type).to eq 'vocab'
expect(solr_doc["readonly_created_ssim"]).to eq ["1976-01-01T00:00:00Z"]
end
it 'indexes collections' do
exhibit = Spotlight::Exhibit.create title: 'Exhibit A'
Expand Down

0 comments on commit 410fdff

Please sign in to comment.