-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple UI/API to search for MARC records by ISBN and return a r…
…esponse of those records grouped by organization
- Loading branch information
Showing
4 changed files
with
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
## | ||
# Controller to lookup MARC records based on standard numbers (e.g. ISBN) | ||
class LookupController < ApplicationController | ||
skip_authorization_check | ||
|
||
def index | ||
return {} if index_params[:isbn].blank? | ||
|
||
@response = grouped_marc_records | ||
end | ||
|
||
def index_params | ||
params.permit(:isbn) | ||
end | ||
helper_method :index_params | ||
|
||
private | ||
|
||
def grouped_marc_records | ||
MarcRecord.includes(:organization).where(isbn: index_params[:isbn]).group_by(&:organization).select do |org, _| | ||
can? :read, org | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<div class="container"> | ||
<div class="d-flex justify-content-between"> | ||
<h1>Marc Records</h1> | ||
</div> | ||
<%= link_to "view as JSON", url_for(index_params.merge(format: :json)) %> | ||
|
||
<table class="table table-striped organizations"> | ||
<thead> | ||
<tr> | ||
<th>marc001</th> | ||
<th>Stream</th> | ||
<th>Download</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @response.each do |organization, marc_records| %> | ||
<tr> | ||
<td colspan="3" class="bg-info font-weight-bold text-white"><%= organization.name %></td> | ||
</tr> | ||
|
||
<% marc_records.each do |marc_record| %> | ||
<tr> | ||
<td><%= marc_record.marc001 %></td> | ||
<td><%= link_to(marc_record.stream.display_name, organization_stream_path(organization, marc_record.stream)) %></td> | ||
<td><%= link_to('marc21', marc21_organization_marc_record_url(organization, marc_record)) %>, <%= link_to('marcxml', marcxml_organization_marc_record_url(organization, marc_record)) %></td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
json.total @response&.values&.sum(&:count) || 0 | ||
json.isbn index_params[:isbn] | ||
json.organizations @response do |organization, records| | ||
json.extract! organization, :id, :name, :slug | ||
json.records records do |record| | ||
json.extract! record, :id, :marc001, :bytecount, :length, :checksum | ||
json.url organization_marc_record_url(record.organization, record) | ||
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