Skip to content

Commit 6ca48cb

Browse files
committed
Searches can return IIIF Collection manifests
1 parent 4608126 commit 6ca48cb

File tree

6 files changed

+96
-5
lines changed

6 files changed

+96
-5
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ gem 'avalon-about', git: 'https://github.com/avalonmediasystem/avalon-about.git'
5858
#gem 'bootstrap-sass', '< 3.4.1' # Pin to less than 3.4.1 due to change in behavior with popovers
5959
gem 'bootstrap-toggle-rails'
6060
gem 'bootstrap_form'
61-
gem 'iiif_manifest', '~> 1.6'
61+
gem 'iiif_manifest', git: 'https://github.com/samvera/iiif_manifest.git', branch: 'v3_collections'
62+
#gem 'iiif_manifest', '~> 1.6'
6263
gem 'rack-cors', require: 'rack/cors'
6364
gem 'rails_same_site_cookie'
6465
gem 'recaptcha', require: 'recaptcha/rails'

Gemfile.lock

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ GIT
7777
rsolr (>= 1.1.2, < 3)
7878
ruby-progressbar (~> 1.0)
7979

80+
GIT
81+
remote: https://github.com/samvera/iiif_manifest.git
82+
revision: a3c1c504e9ac36eedb23f39e908ab86593e670a4
83+
branch: v3_collections
84+
specs:
85+
iiif_manifest (1.6.0)
86+
activesupport (>= 4)
87+
8088
GEM
8189
remote: https://rubygems.org/
8290
specs:
@@ -462,8 +470,6 @@ GEM
462470
i18n (1.14.7)
463471
concurrent-ruby (~> 1.0)
464472
iconv (1.0.8)
465-
iiif_manifest (1.6.0)
466-
activesupport (>= 4)
467473
ims-lti (1.1.13)
468474
builder
469475
oauth (>= 0.4.5, < 0.6)
@@ -1044,7 +1050,7 @@ DEPENDENCIES
10441050
httpx
10451051
hydra-head (~> 13.0)
10461052
iconv (~> 1.0.6)
1047-
iiif_manifest (~> 1.6)
1053+
iiif_manifest!
10481054
ims-lti (~> 1.1.13)
10491055
jbuilder (~> 2.0)
10501056
jquery-datatables

app/controllers/catalog_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ class CatalogController < ApplicationController
222222
config.bootstrap_version = 4
223223
end
224224

225+
def manifest
226+
@response = search_service.search_results
227+
228+
presenter = IiifCollectionManifestPresenter.new(items: @response.documents.map { |doc| SpeedyAF::Base.for(doc) }, params: params)
229+
manifest = IIIFManifest::V3::ManifestFactory.new(presenter).to_h
230+
231+
respond_to do |wants|
232+
wants.json { render json: manifest.to_json }
233+
wants.html { render json: manifest.to_json }
234+
end
235+
end
236+
225237
private
226238

227239
def load_home_page_collections
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2011-2024, The Trustees of Indiana University and Northwestern
2+
# University. Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
#
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed
10+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
# specific language governing permissions and limitations under the License.
13+
# --- END LICENSE_HEADER BLOCK ---
14+
15+
class IiifCollectionManifestPresenter
16+
attr_reader :items, :params
17+
18+
def initialize(items:, params:)
19+
@items = items.map { |item| IiifManifestPresenter.new(media_object: item, master_files: nil, lending_enabled: lending_enabled?(item)) }
20+
@params = params
21+
end
22+
23+
def file_set_presenters
24+
[]
25+
end
26+
27+
def work_presenters
28+
items
29+
end
30+
31+
def manifest_url
32+
Rails.application.routes.url_helpers.manifest_catalog_url(nil, *params.except(:action, :controller).permit!)
33+
end
34+
35+
def to_s
36+
'Catalog Search'
37+
end
38+
39+
def collection?
40+
true
41+
end
42+
43+
def homepage
44+
[
45+
{
46+
id: Rails.application.routes.url_helpers.search_catalog_url(nil, *params.except(:action, :controller).permit!),
47+
type: "Text",
48+
label: { "none" => [I18n.t('iiif.manifest.homepageLabel')] },
49+
format: "text/html"
50+
}
51+
]
52+
end
53+
54+
def manifest_metadata
55+
@manifest_metadata ||= iiif_metadata_fields.compact
56+
end
57+
58+
private
59+
60+
def iiif_metadata_fields
61+
[
62+
"Title" => to_s
63+
]
64+
end
65+
66+
def lending_enabled?(context)
67+
return context&.cdl_enabled? if Avalon::Configuration.controlled_digital_lending_enabled?
68+
false
69+
end
70+
end

app/presenters/speedy_af/proxy/media_object.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(solr_document, instance_defaults = {})
2525
instance_defaults ||= {}
2626
@model = SpeedyAF::Base.model_for(solr_document)
2727
@attrs = self.class.defaults.merge(instance_defaults)
28-
solr_document.each_pair do |k, v|
28+
solr_document.to_h.each_pair do |k, v|
2929
attr_name, value = parse_solr_field(k, v)
3030
@attrs[attr_name.to_sym] = value
3131
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
resource :catalog, only: [], as: 'catalog', path: '/catalog', controller: 'catalog' do
1010
concerns :searchable
11+
12+
get :manifest
1113
end
1214

1315
# For some reason this needs to be after `resource :catalog` otherwise Blacklight will generate links to / instead of /catalog

0 commit comments

Comments
 (0)