-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from mlibrary/carousel
Carousel
- Loading branch information
Showing
11 changed files
with
228 additions
and
26 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
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
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,59 @@ | ||
class CarouselList | ||
def self.list(call_number, browse_solr_client = BrowseSolrClient.new, catalog_client = CatalogSolrClient.client) | ||
before = browse_solr_client.browse_reference_on_bottom(reference_id: call_number, rows: 22, field: "callnumber").body["response"]["docs"].reverse | ||
after = browse_solr_client.browse_reference_on_top(reference_id: call_number, rows: 23, field: "callnumber").body["response"]["docs"] | ||
|
||
ordered_call_number_docs = [before, after].flatten | ||
|
||
bib_ids = ordered_call_number_docs.map { |x| x["bib_id"] } | ||
catalog_response = catalog_client.get_bibs(bib_ids: bib_ids).body | ||
items = ordered_call_number_docs.map do |browse_doc| | ||
catalog_doc = catalog_response["response"]["docs"].find do |x| | ||
x["id"] == browse_doc["bib_id"] | ||
end || {} | ||
CarouselItem.new(catalog_doc, browse_doc) | ||
end | ||
items.map { |x| x.to_h } | ||
end | ||
|
||
class CarouselItem | ||
def initialize(catalog_doc, browse_doc) | ||
@catalog_doc = catalog_doc | ||
@browse_doc = browse_doc | ||
end | ||
|
||
def title | ||
@catalog_doc["title_display"]&.first | ||
end | ||
|
||
def author | ||
@catalog_doc["main_author_display"]&.first | ||
end | ||
|
||
def call_number | ||
@browse_doc["callnumber"]&.strip | ||
end | ||
|
||
def mms_id | ||
@browse_doc["bib_id"] | ||
end | ||
|
||
def date | ||
@catalog_doc["display_date"] | ||
end | ||
|
||
def url | ||
"https://search.lib.umich.edu/catalog/record/#{mms_id}" | ||
end | ||
|
||
def to_h | ||
{ | ||
title: title, | ||
author: author, | ||
date: date, | ||
call_number: call_number, | ||
url: url | ||
} | ||
end | ||
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
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
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,58 @@ | ||
describe CarouselList do | ||
before(:each) do | ||
@browse_client = instance_double(BrowseSolrClient) | ||
@catalog_client = instance_double(CatalogSolrClient::Client, get_bibs: OpenStruct.new(body: JSON.parse(fixture("biblio_results.json")))) | ||
end | ||
subject do | ||
described_class.list("my_call_number", @browse_client, @catalog_client) | ||
end | ||
def body(file_name) | ||
out = JSON.parse(fixture(file_name)) | ||
OpenStruct.new(body: out) | ||
end | ||
it "returns a list of carousel items" do | ||
allow(@browse_client).to receive(:browse_reference_on_bottom).and_return(body("callnumbers_before.json")) | ||
|
||
allow(@browse_client).to receive(:browse_reference_on_top).and_return(body("callnumbers_results.json")) | ||
expect(subject.first[:call_number]).to eq("Z 253 .U581 1952") | ||
end | ||
end | ||
describe CarouselList::CarouselItem do | ||
before(:each) do | ||
@catalog_doc = JSON.parse(fixture("biblio_results.json"))["response"]["docs"].first | ||
@browse_doc = JSON.parse(fixture("callnumbers_results.json"))["response"]["docs"].first | ||
end | ||
subject do | ||
described_class.new(@catalog_doc, @browse_doc) | ||
end | ||
it "has a title" do | ||
expect(subject.title).to eq("Theory and practice of composition.") | ||
end | ||
it "has an author" do | ||
expect(subject.author).to eq("United States. Government Printing Office") | ||
end | ||
it "has a call_number" do | ||
expect(subject.call_number).to eq("Z 253 .U6 1963") | ||
end | ||
it "has an mms_id" do | ||
expect(subject.mms_id).to eq("990011613060106381") | ||
end | ||
it "has a date" do | ||
expect(subject.date).to eq("1950") | ||
end | ||
it "has a url" do | ||
expect(subject.url).to eq("#{S.search_url}/catalog/record/990011613060106381") | ||
end | ||
it "has a hash output" do | ||
expect(subject.to_h).to eq( | ||
{ | ||
author: "United States. Government Printing Office", | ||
call_number: "Z 253 .U6 1963", | ||
date: "1950", | ||
title: "Theory and practice of composition.", | ||
url: "#{S.search_url}/catalog/record/990011613060106381" | ||
|
||
} | ||
) | ||
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
Oops, something went wrong.