|
| 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 |
0 commit comments