From fea9009b23507b19f6a6a37790b090431924e5c4 Mon Sep 17 00:00:00 2001 From: Trey Terrell Date: Tue, 23 Jun 2015 14:49:33 -0700 Subject: [PATCH] Add thumbnails to index view. --- app/helpers/thumbnail_helper.rb | 8 +++++ app/models/blacklight_config.rb | 3 +- .../thumbnail_configuration.rb | 6 ++++ .../_thumbnail_default.html.erb_spec.rb | 29 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 app/helpers/thumbnail_helper.rb create mode 100644 app/models/blacklight_config/thumbnail_configuration.rb create mode 100644 spec/views/catalog/_thumbnail_default.html.erb_spec.rb diff --git a/app/helpers/thumbnail_helper.rb b/app/helpers/thumbnail_helper.rb new file mode 100644 index 0000000..6084855 --- /dev/null +++ b/app/helpers/thumbnail_helper.rb @@ -0,0 +1,8 @@ +module ThumbnailHelper + include Blacklight::CatalogHelper + # Had to override the thumbnail URL because the document doesn't directly have + # the relative URL, just the raw location of the thumbnail on disk. + def thumbnail_url document + document.derivative_paths[:thumbnail].relative_path.to_s + end +end diff --git a/app/models/blacklight_config.rb b/app/models/blacklight_config.rb index 8930c0b..538cd94 100644 --- a/app/models/blacklight_config.rb +++ b/app/models/blacklight_config.rb @@ -23,7 +23,8 @@ def configurations ViewConfiguration.new(configuration), DefaultConfiguration.new(configuration), SearchFieldConfiguration.new(configuration), - ShowActions.new(configuration) + ShowActions.new(configuration), + ThumbnailConfiguration.new(configuration) ] end diff --git a/app/models/blacklight_config/thumbnail_configuration.rb b/app/models/blacklight_config/thumbnail_configuration.rb new file mode 100644 index 0000000..fcf36da --- /dev/null +++ b/app/models/blacklight_config/thumbnail_configuration.rb @@ -0,0 +1,6 @@ +class BlacklightConfig::ThumbnailConfiguration + pattr_initialize :configuration + def run + configuration.index.thumbnail_field = :workflow_metadata__thumbnail_path_ssim + end +end diff --git a/spec/views/catalog/_thumbnail_default.html.erb_spec.rb b/spec/views/catalog/_thumbnail_default.html.erb_spec.rb new file mode 100644 index 0000000..6de26b2 --- /dev/null +++ b/spec/views/catalog/_thumbnail_default.html.erb_spec.rb @@ -0,0 +1,29 @@ +require 'rails_helper' + +RSpec.describe "catalog/_thumbnail_default.html.erb" do + let(:document) { SolrDocument.new(solr_hash) } + let(:solr_hash) { + { + :id => "1", + :workflow_metadata__thumbnail_path_ssim => [OregonDigital.derivative_injector.thumbnail_path("13")] + } + } + let(:blacklight_config) { + BlacklightConfig.new(GenericAsset, CatalogController.blacklight_config).configuration + } + describe "thumbnails" do + before do + allow(view).to receive(:blacklight_config).and_return(blacklight_config) + allow(view).to receive(:render_grouped_response?).and_return false + allow(view).to receive(:current_search_session).and_return nil + allow(view).to receive(:search_session).and_return({}) + assign :response, double(start: 0) + render :partial => "catalog/thumbnail_default", :locals => {:document => document, :document_counter => 1} + end + context "when there's a thumbnail" do + it "should show it" do + expect(rendered).to have_selector "img[src='/media/thumbnails/3/1/13.jpg']" + end + end + end +end