-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5391afd
commit fe1b45f
Showing
9 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
SirTrevor.Blocks.RecentItems = (function(){ | ||
|
||
return SirTrevor.Block.extend({ | ||
type: "recent_items", | ||
|
||
title: function() { return "Recent Items"; }, | ||
|
||
description: function() { return "Display a list of recent items"; }, | ||
|
||
blockGroup: function() { return i18n.t("blocks:group:items") }, | ||
|
||
icon_name: "rule", | ||
|
||
editorHTML: function() { | ||
return _.template(this.template, this)(this); | ||
}, | ||
|
||
template: [ | ||
'<div class="form resources-admin clearfix">', | ||
'<div class="widget-header">', | ||
'<%= description() %>', | ||
'</div>', | ||
'</div>' | ||
].join("\n"), | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class RecentItemsBlock < SirTrevorRails::Blocks::SolrDocumentsBlock | ||
def documents | ||
search_results.last | ||
end | ||
|
||
def search_results | ||
@search_results ||= solr_helper.search_results(user_query) | ||
end | ||
|
||
def user_query | ||
Blacklight::SearchState.new({ sort: "timestamp DESC", rows: 9 }, blacklight_config).to_h | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<div class="card"> | ||
<div class="thumbnail"> | ||
<%= link_to_document document, image_tag(thumbnail_url(document).to_s.gsub(/full\/.*\/0/,"full/!400,400/0")) %> | ||
<div class="card-header"> | ||
<%= render_index_document document %> | ||
</div> | ||
</div> | ||
</div> |
9 changes: 9 additions & 0 deletions
9
app/views/spotlight/sir_trevor/blocks/_recent_items_block.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h1>Recent Additions</h1> | ||
<div class="content-block documents"> | ||
<% recent_items_block.with_solr_helper(self) %> | ||
<%- if recent_items_block.documents.present? %> | ||
<div class="cards"> | ||
<%= render collection: recent_items_block.documents, as: :document, partial: 'spotlight/sir_trevor/blocks/recent_item' %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FactoryBot.define do | ||
factory :iiif_resource, class: IIIFResource do | ||
transient do | ||
# Fixture to use for stubbing the manifest. | ||
manifest_fixture { nil } | ||
# Source metadata identifier to stub out | ||
source_metadata_identifier { nil } | ||
# Reference to the spec to enable the factory to stub out requests. | ||
spec { nil } | ||
end | ||
|
||
before(:create) do |resource, evaluator| | ||
if evaluator.spec.present? | ||
evaluator.spec.stub_manifest(url: resource.url, fixture: evaluator.manifest_fixture) if evaluator.manifest_fixture | ||
evaluator.spec.stub_metadata(id: evaluator.source_metadata_identifier) if evaluator.source_metadata_identifier | ||
end | ||
end | ||
after(:create) do |resource, evaluator| | ||
resource.save_and_index | ||
Blacklight.default_index.connection.commit | ||
end | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
spec/views/spotlight/sir_trevor/blocks/_recent_items_block.html.erb_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe 'spotlight/sir_trevor/blocks/_recent_items_block.html.erb', type: :view do | ||
let(:p) { 'spotlight/sir_trevor/blocks/recent_items_block.html.erb' } | ||
let(:block) do | ||
RecentItemsBlock.new({ type: 'block', data: {} }, view) | ||
end | ||
let(:exhibit) { FactoryBot.create(:exhibit) } | ||
|
||
before do | ||
# Include the search helper so the block can run a scoped query. Normally | ||
# the view has access to this from the controller, but this test uses an | ||
# anonymous controller. | ||
view.class.include Blacklight::SearchHelper | ||
allow(view).to receive_messages(recent_items_block: block) | ||
allow(view).to receive_messages( | ||
blacklight_config: CatalogController.blacklight_config, | ||
current_exhibit: exhibit, | ||
search_session: {}, | ||
current_search_session: {} | ||
) | ||
|
||
FactoryBot.create( | ||
:iiif_resource, | ||
url: "https://hydra-dev.princeton.edu/concern/scanned_resources/1r66j1149/manifest", | ||
exhibit: exhibit, | ||
manifest_fixture: "1r66j1149-expanded.json", | ||
source_metadata_identifier: "12345678", | ||
spec: self | ||
) | ||
FactoryBot.create( | ||
:iiif_resource, | ||
url: "https://hydra-dev.princeton.edu/concern/scanned_resources/44558d29f/manifest", | ||
exhibit: exhibit, | ||
manifest_fixture: "44558d29f.json", | ||
spec: self | ||
) | ||
end | ||
|
||
it 'renders a set of recent items' do | ||
render partial: p, locals: { recent_items_block: block } | ||
|
||
expect(rendered).to have_selector ".card", count: 2 | ||
# Assert first document is the newest indexed one. | ||
expect(rendered).to have_selector ".card:nth-child(1)", text: "L''ordine dorico ossia il tempio d''Ercole nella città di Cori umiliato alla santita di nostro signore Papa Pio Sesto" | ||
end | ||
end |