-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement Recent Items Widget #616
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"), | ||
}); | ||
})(); |
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 |
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> |
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> |
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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define the stub in the factory, never thought of this; seems handy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm not sure I'm a fan yet, but if we're going to try using more factories it seems like something to fiddle with. |
||
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 |
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, more factories!