Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display thumbnail in search results. #316

Merged
merged 2 commits into from
Nov 20, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/repository_models/curation_concern/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def to_solr(solr_doc={}, opts={})
super(solr_doc, opts)
index_collection_pids(solr_doc)
solr_doc[Solrizer.solr_name('noid', Sufia::GenericFile.noid_indexer)] = noid
solr_doc[Solrizer.solr_name('representative', :stored_searchable)] = self.representative
add_derived_date_created(solr_doc)
return solr_doc
end
Expand Down
5 changes: 0 additions & 5 deletions app/repository_models/curation_concern/with_generic_files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,5 @@ def after_destroy_cleanup_generic_files
generic_files.each(&:destroy)
end

def representative_generic_file_object
return nil if self.representative.nil?
@representative_generic_file_object ||= GenericFile.find(self.representative)
end

end
end
4 changes: 4 additions & 0 deletions app/repository_models/generic_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ def current_version_id
def human_readable_type
self.class.to_s.demodulize.titleize
end

def representative
to_param
end
end
5 changes: 5 additions & 0 deletions app/repository_models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ def to_solr(solr_doc={}, opts={})
Solrizer.set_field(solr_doc, 'generic_type', 'Person', :facetable)
solr_doc['read_access_group_ssim'] = 'public'
solr_doc['has_user_bsi'] = !!User.exists?(repository_id: pid)
solr_doc[Solrizer.solr_name('representative', :stored_searchable)] = self.representative
solr_doc
end

def representative
to_param
end

def to_s
name || "No Title"
end
Expand Down
7 changes: 6 additions & 1 deletion app/services/curation_concern/generic_work_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module CurationConcern
class GenericWorkActor < CurationConcern::BaseActor

def create
super && attach_files && create_linked_resources
super && attach_files && create_linked_resources && assign_representative
end

def update
Expand Down Expand Up @@ -63,6 +63,11 @@ def create_linked_resource(link_resource_url)
false
end

def assign_representative
curation_concern.representative = curation_concern.generic_file_ids.first
curation_concern.save
end

private
def attach_file(file)
generic_file = GenericFile.new
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<%= image_tag 'curate/nope.png', class: "canonical-image" %>
<%- if document.respond_to?(:representative) && document.representative.present? %>
<%= image_tag download_path(document.representative, {:datastream_id => 'thumbnail'}), class: "canonical-image" %>
<%- else -%>
<span class="canonical-image"></span>
<%- end -%>
2 changes: 1 addition & 1 deletion app/views/curation_concern/base/_related_files.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<% curation_concern.generic_files.each do |generic_file| %>
<tr class="<%= dom_class(generic_file) %> attributes">
<td class="attribute title">
<%= render partial: 'thumbnail', locals: {generic_file: generic_file, dom_class_name: 'thumbnail'} %>
<%= render partial: 'thumbnail', locals: {thumbnail: generic_file, dom_class_name: 'thumbnail'} %>
<%= generic_file_title(generic_file) %>
</td>
<td class="attribute filename"><%= link_to(generic_file_link_name(generic_file), curation_concern_generic_file_path(generic_file)) %></td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/curation_concern/base/_thumbnail.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%- if generic_file && generic_file.thumbnail.has_content? -%>
<%= image_tag download_path(generic_file.pid, {:datastream_id => 'thumbnail'}), class: dom_class_name %>
<%- if thumbnail.representative.present? -%>
<%= image_tag download_path(thumbnail.representative, {:datastream_id => 'thumbnail'}), class: dom_class_name %>
<%- else -%>
<%= image_tag 'curate/nope.png', class: "canonical-image" %>
<%- end -%>
2 changes: 1 addition & 1 deletion app/views/curation_concern/base/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% content_for :page_header do %>
<h1><%= curation_concern %> <span class="human_readable_type">(<%= curation_concern.human_readable_type %>)</span></h1>
<% end %>
<%= render partial: 'thumbnail', locals: {generic_file: curation_concern.representative_generic_file_object, dom_class_name: 'representative_image'} %>
<%= render partial: 'thumbnail', locals: {thumbnail: curation_concern, dom_class_name: 'representative_image'} %>
<%= render 'attributes', curation_concern: curation_concern %>
<%= render 'doi', curation_concern: curation_concern %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/curation_concern/generic_files/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% content_for :page_header do %>
<h1>File Details</h1>
<% end %>
<%= render partial: 'thumbnail', locals: {generic_file: curation_concern, dom_class_name: 'representative_image'} %>
<%= render partial: 'thumbnail', locals: {thumbnail: curation_concern, dom_class_name: 'representative_image'} %>
<%= render "attributes", curation_concern: curation_concern %>

<div class="form-actions">
Expand Down
22 changes: 0 additions & 22 deletions app/views/curation_concern/generic_works/show.html.erb

This file was deleted.

6 changes: 3 additions & 3 deletions spec/features/thumbnail_display_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
it 'shows thumbnail for all related files' do
login_as(user)
visit curation_concern_image_path(curation_concern)
page.should have_css("img[src$='#{generic_file2.pid}?datastream_id=thumbnail'][class$='thumbnail']")
page.should have_css("img[src$='#{generic_file2.to_param}?datastream_id=thumbnail'][class$='thumbnail']")
end
end

Expand All @@ -37,8 +37,8 @@
login_as(user)
visit curation_concern_image_path(curation_concern)
page.should have_css("img[src$='#{generic_file1.pid}?datastream_id=thumbnail'][class$='representative_image']")
page.should have_css("img[src$='#{generic_file1.pid}?datastream_id=thumbnail'][class$='thumbnail']")
page.should have_css("img[src$='#{generic_file2.pid}?datastream_id=thumbnail'][class$='thumbnail']")
page.should have_css("img[src$='#{generic_file1.to_param}?datastream_id=thumbnail'][class$='thumbnail']")
page.should have_css("img[src$='#{generic_file2.to_param}?datastream_id=thumbnail'][class$='thumbnail']")
page.should_not have_css("img[src$='#{generic_file2.pid}?datastream_id=thumbnail'][class$='representative_image']")
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/repository_models/generic_work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@
end
end

context 'Representative Image' do
let!(:work) { FactoryGirl.create(:generic_work, title: 'Work') }
it "shows up in the solr document" do
work.to_solr["representative"].should == nil
work.representative = "123"
work.save
work.to_solr["representative_tesim"].should == "123"
end
end

end
1 change: 1 addition & 0 deletions spec/services/curation_concern/generic_work_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
curation_concern.date_uploaded.should == Date.today
curation_concern.date_modified.should == Date.today
curation_concern.depositor.should == user.user_key
expect(curation_concern.representative).to_not be_nil

curation_concern.generic_files.count.should == 1
# Sanity test to make sure the file we uploaded is stored and has same permission as parent.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'
describe 'catalog/_index_partials/_thumbnail_display' do
let(:document) { FactoryGirl.create(:generic_work, representative: '1234') }
before do
render partial: 'thumbnail_display', locals: { document: document }
end
it 'should display thumbnail' do
rendered.should include("/downloads/1234?datastream_id=thumbnail")
end
end