Skip to content

Commit

Permalink
Restore support for storing full image urls for non-IIIF-backed image…
Browse files Browse the repository at this point in the history
…s in the sir-trevor widgets
  • Loading branch information
cbeer committed Feb 3, 2017
1 parent 41e7bd3 commit 26d435c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
25 changes: 22 additions & 3 deletions app/assets/javascripts/spotlight/blocks/solr_documents_block.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,25 @@ SirTrevor.Blocks.SolrDocuments = (function(){
_itemPanelIiifFields: function(index, data) {
return [
// '<input type="hidden" name="item[' + index + '][iiif_region]" value="' + (data.iiif_region) + '"/>',
// for legacy compatiblity:
'<input type="hidden" name="item[' + index + '][thumbnail_image_url]" value="' + (data.thumbnail_image_url || data.thumbnail) + '"/>',
'<input type="hidden" name="item[' + index + '][full_image_url]" value="' + (data.full_image_url || data.thumbnail_image_url || data.thumbnail) + '"/>',
'<input type="hidden" name="item[' + index + '][iiif_tilesource]" value="' + (data.iiif_tilesource) + '"/>',
'<input type="hidden" name="item[' + index + '][iiif_manifest_url]" value="' + (data.iiif_manifest_url) + '"/>',
'<input type="hidden" name="item[' + index + '][iiif_canvas_id]" value="' + (data.iiif_canvas_id) + '"/>',
'<input type="hidden" name="item[' + index + '][iiif_image_id]" value="' + (data.iiif_image_id) + '"/>',
].join("\n");
},
setIiifFields: function(data) {
setIiifFields: function(data, default) {
var legacyThumbnailField = $(this.inner).find('[name$="[thumbnail_image_url]"]')
var legacyFullField = $(this.inner).find('[name$="[full_image_url]"]')

if (default && legacyThumbnailField.val().length > 0) {
return;
}

legacyThumbnailField.val("");
legacyFullField.val("");
$(this.inner).find('[name$="[iiif_image_id]"]').val(data.imageId);
$(this.inner).find('[name$="[iiif_tilesource]"]').val(data.tilesource);
$(this.inner).find('[name$="[iiif_manifest_url]"]').val(data.manifest);
Expand All @@ -68,6 +80,13 @@ SirTrevor.Blocks.SolrDocuments = (function(){
var context = this;
var manifestUrl = data.iiif_manifest || data.iiif_manifest_url;

if (!manifestUrl) {
$(this.inner).find('[name$="[thumbnail_image_url]"]').val(data.thumbnail);
$(this.inner).find('[name$="[full_image_url]"]').val(data.full_image_url);

return;
}

$.ajax(manifestUrl).success(
function(manifest) {
var Iiif = require('spotlight/iiif');
Expand All @@ -76,11 +95,11 @@ SirTrevor.Blocks.SolrDocuments = (function(){
var thumbs = iiifManifest.imagesArray();

if (!data.iiif_manifest_url) {
context.setIiifFields(thumbs[0]);
context.setIiifFields(thumbs[0], true);
}
if(thumbs.length > 1) {
panel.multiImageSelector(thumbs, function(selectorImage) {
context.setIiifFields(selectorImage);
context.setIiifFields(selectorImage, false);
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/concerns/spotlight/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ def autocomplete_json_response(document_list)
end
end

# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def autocomplete_json_response_for_document(doc)
{
id: doc.id,
title: CGI.unescapeHTML(view_context.presenter(doc).heading.to_str),
thumbnail: doc.first(blacklight_config.index.thumbnail_field),
full_image_url: doc.first(Spotlight::Engine.config.full_image_field),
description: doc.id,
url: polymorphic_path([current_exhibit, doc]),
private: doc.private?(current_exhibit),
global_id: doc.to_global_id.to_s,
iiif_manifest: doc[Spotlight::Engine.config.iiif_manifest_field]
}
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
# Spotlight::Engine.config.solr_fields.string_suffix = '_ssim'.freeze
# Spotlight::Engine.config.solr_fields.text_suffix = '_tesim'.freeze
# Spotlight::Engine.config.resource_global_id_field = :"#{config.solr_fields.prefix}spotlight_resource_id#{config.solr_fields.string_suffix}"
# Spotlight::Engine.config.full_image_field = :full_image_url_ssm
# Spotlight::Engine.config.thumbnail_field = :thumbnail_url_ssm

# ==> Uploaded item configuration
Expand Down
1 change: 1 addition & 0 deletions lib/spotlight/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def self.blacklight_config
config.resource_global_id_field = :"#{config.solr_fields.prefix}spotlight_resource_id#{config.solr_fields.string_suffix}"

# Set to nil if you don't want to pull thumbnails from the index
config.full_image_field = :full_image_url_ssm
config.thumbnail_field = :thumbnail_url_ssm

# Defaults to the blacklight_config.index.title_field:
Expand Down

0 comments on commit 26d435c

Please sign in to comment.