From 2e58606a86ae98c7a5468b1779ca0923de24631d Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Wed, 10 Jan 2024 09:24:31 -0500 Subject: [PATCH 1/4] Serialize master file display title to iiif ranges --- app/models/concerns/master_file_behavior.rb | 2 +- app/models/iiif_canvas_presenter.rb | 3 +-- spec/models/iiif_canvas_presenter_spec.rb | 26 ++++++++++++++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/models/concerns/master_file_behavior.rb b/app/models/concerns/master_file_behavior.rb index 8b546dac9d..27a53220a8 100644 --- a/app/models/concerns/master_file_behavior.rb +++ b/app/models/concerns/master_file_behavior.rb @@ -68,7 +68,7 @@ def stream_details # Returns the hash return({ id: self.id, - label: title, + label: display_title, is_video: is_video?, poster_image: poster_path, embed_code: embed_code(EMBED_SIZE[:medium], {urlappend: '/embed'}), diff --git a/app/models/iiif_canvas_presenter.rb b/app/models/iiif_canvas_presenter.rb index 2d12db3862..c43ac2a1b6 100644 --- a/app/models/iiif_canvas_presenter.rb +++ b/app/models/iiif_canvas_presenter.rb @@ -131,8 +131,7 @@ def supplemental_captions_transcripts files end - def simple_iiif_range(label = stream_info[:embed_title]) - # TODO: embed_title? + def simple_iiif_range(label = stream_info[:label]) IiifManifestRange.new( label: { "none" => [label] }, items: [ diff --git a/spec/models/iiif_canvas_presenter_spec.rb b/spec/models/iiif_canvas_presenter_spec.rb index 46a7b8e665..55439a96a4 100644 --- a/spec/models/iiif_canvas_presenter_spec.rb +++ b/spec/models/iiif_canvas_presenter_spec.rb @@ -88,13 +88,27 @@ end context 'with no structural metadata' do - let(:structure_xml) { "" } + context 'master file with title' do + let(:structure_xml) { "" } + let(:master_file) { FactoryBot.create(:master_file, title: "video.mp4", media_object: media_object, derivatives: [derivative]) } + + it 'autogenerates a basic range with display_title label' do + expect(subject.label.to_s).to eq "{\"none\"=>[\"#{master_file.display_title}\"]}" + expect(subject.items.size).to eq 1 + expect(subject.items.first).to be_a IiifCanvasPresenter + expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}" + end + end - it 'autogenerates a basic range' do - expect(subject.label.to_s).to eq "{\"none\"=>[\"#{master_file.embed_title}\"]}" - expect(subject.items.size).to eq 1 - expect(subject.items.first).to be_a IiifCanvasPresenter - expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}" + context 'master file without title' do + let(:structure_xml) { "" } + + it 'autogenerates a basic range with nil label' do + expect(subject.label.to_s).to eq "{\"none\"=>[nil]}" + expect(subject.items.size).to eq 1 + expect(subject.items.first).to be_a IiifCanvasPresenter + expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}" + end end end From 9222907ecfaee70713aa8e240c4ef7d7aeedb49c Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Wed, 10 Jan 2024 11:24:23 -0500 Subject: [PATCH 2/4] Display media_object.title when there is 1 section --- app/models/concerns/master_file_behavior.rb | 2 +- app/presenters/speedy_af/proxy/master_file.rb | 8 ++++---- spec/models/iiif_canvas_presenter_spec.rb | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/concerns/master_file_behavior.rb b/app/models/concerns/master_file_behavior.rb index 27a53220a8..c799b1138f 100644 --- a/app/models/concerns/master_file_behavior.rb +++ b/app/models/concerns/master_file_behavior.rb @@ -112,7 +112,7 @@ def display_title elsif file_location.present? && (media_object.master_file_ids.size > 1) file_location.split("/").last end - mf_title.blank? ? nil : mf_title + mf_title.blank? ? media_object.title : mf_title end def embed_title diff --git a/app/presenters/speedy_af/proxy/master_file.rb b/app/presenters/speedy_af/proxy/master_file.rb index 6881a2e03a..708f52df16 100644 --- a/app/presenters/speedy_af/proxy/master_file.rb +++ b/app/presenters/speedy_af/proxy/master_file.rb @@ -1,11 +1,11 @@ # Copyright 2011-2023, The Trustees of Indiana University and Northwestern # University. Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. -# +# # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software distributed # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR # CONDITIONS OF ANY KIND, either express or implied. See the License for the @@ -44,7 +44,7 @@ def display_title elsif file_location.present? && (media_object.master_file_ids.size > 1) file_location.split("/").last end - mf_title.blank? ? nil : mf_title + mf_title.blank? ? media_object.title : mf_title end # @return [SupplementalFile] diff --git a/spec/models/iiif_canvas_presenter_spec.rb b/spec/models/iiif_canvas_presenter_spec.rb index 55439a96a4..99bf078c63 100644 --- a/spec/models/iiif_canvas_presenter_spec.rb +++ b/spec/models/iiif_canvas_presenter_spec.rb @@ -92,7 +92,7 @@ let(:structure_xml) { "" } let(:master_file) { FactoryBot.create(:master_file, title: "video.mp4", media_object: media_object, derivatives: [derivative]) } - it 'autogenerates a basic range with display_title label' do + it 'autogenerates a basic range with display_title as label' do expect(subject.label.to_s).to eq "{\"none\"=>[\"#{master_file.display_title}\"]}" expect(subject.items.size).to eq 1 expect(subject.items.first).to be_a IiifCanvasPresenter @@ -103,8 +103,8 @@ context 'master file without title' do let(:structure_xml) { "" } - it 'autogenerates a basic range with nil label' do - expect(subject.label.to_s).to eq "{\"none\"=>[nil]}" + it 'autogenerates a basic range with media_object.title as label' do + expect(subject.label.to_s).to eq "{\"none\"=>[\"#{media_object.title}\"]}" expect(subject.items.size).to eq 1 expect(subject.items.first).to be_a IiifCanvasPresenter expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}" From 2826e9a83370fe14ebd0e998bbbc1e814c1119d4 Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Wed, 10 Jan 2024 12:21:52 -0500 Subject: [PATCH 3/4] Fix methods so tests pass --- app/models/concerns/master_file_behavior.rb | 10 +++++++--- app/presenters/speedy_af/proxy/master_file.rb | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/master_file_behavior.rb b/app/models/concerns/master_file_behavior.rb index c799b1138f..bc5d0444dd 100644 --- a/app/models/concerns/master_file_behavior.rb +++ b/app/models/concerns/master_file_behavior.rb @@ -103,7 +103,7 @@ def hls_streams sort_streams hls end - def display_title + def structure_title mf_title = if has_structuralMetadata? structuralMetadata.section_title elsif title.present? @@ -112,11 +112,15 @@ def display_title elsif file_location.present? && (media_object.master_file_ids.size > 1) file_location.split("/").last end - mf_title.blank? ? media_object.title : mf_title + mf_title.blank? ? nil : mf_title end def embed_title - [media_object.title, display_title].compact.join(" - ") + [media_object.title, structure_title].compact.join(" - ") + end + + def display_title + structure_title.present? ? structure_title : media_object.title end def embed_code(width, permalink_opts = {}) diff --git a/app/presenters/speedy_af/proxy/master_file.rb b/app/presenters/speedy_af/proxy/master_file.rb index 708f52df16..4c72187a7c 100644 --- a/app/presenters/speedy_af/proxy/master_file.rb +++ b/app/presenters/speedy_af/proxy/master_file.rb @@ -35,7 +35,7 @@ def title attrs[:title].presence end - def display_title + def structure_title mf_title = if has_structuralMetadata? structuralMetadata.section_title elsif title.present? @@ -44,7 +44,7 @@ def display_title elsif file_location.present? && (media_object.master_file_ids.size > 1) file_location.split("/").last end - mf_title.blank? ? media_object.title : mf_title + mf_title.blank? ? nil : mf_title end # @return [SupplementalFile] From b2d5c7fa396e31015f9d5d57e6e7198ca50f0f54 Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Wed, 10 Jan 2024 13:19:35 -0500 Subject: [PATCH 4/4] Change method names --- app/models/concerns/master_file_behavior.rb | 10 +++++----- app/presenters/speedy_af/proxy/master_file.rb | 2 +- spec/models/iiif_canvas_presenter_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/concerns/master_file_behavior.rb b/app/models/concerns/master_file_behavior.rb index bc5d0444dd..415842a87f 100644 --- a/app/models/concerns/master_file_behavior.rb +++ b/app/models/concerns/master_file_behavior.rb @@ -68,7 +68,7 @@ def stream_details # Returns the hash return({ id: self.id, - label: display_title, + label: structure_title, is_video: is_video?, poster_image: poster_path, embed_code: embed_code(EMBED_SIZE[:medium], {urlappend: '/embed'}), @@ -103,7 +103,7 @@ def hls_streams sort_streams hls end - def structure_title + def display_title mf_title = if has_structuralMetadata? structuralMetadata.section_title elsif title.present? @@ -116,11 +116,11 @@ def structure_title end def embed_title - [media_object.title, structure_title].compact.join(" - ") + [media_object.title, display_title].compact.join(" - ") end - def display_title - structure_title.present? ? structure_title : media_object.title + def structure_title + display_title.present? ? display_title : media_object.title end def embed_code(width, permalink_opts = {}) diff --git a/app/presenters/speedy_af/proxy/master_file.rb b/app/presenters/speedy_af/proxy/master_file.rb index 4c72187a7c..867c7fa660 100644 --- a/app/presenters/speedy_af/proxy/master_file.rb +++ b/app/presenters/speedy_af/proxy/master_file.rb @@ -35,7 +35,7 @@ def title attrs[:title].presence end - def structure_title + def display_title mf_title = if has_structuralMetadata? structuralMetadata.section_title elsif title.present? diff --git a/spec/models/iiif_canvas_presenter_spec.rb b/spec/models/iiif_canvas_presenter_spec.rb index 99bf078c63..a31f965dbb 100644 --- a/spec/models/iiif_canvas_presenter_spec.rb +++ b/spec/models/iiif_canvas_presenter_spec.rb @@ -92,8 +92,8 @@ let(:structure_xml) { "" } let(:master_file) { FactoryBot.create(:master_file, title: "video.mp4", media_object: media_object, derivatives: [derivative]) } - it 'autogenerates a basic range with display_title as label' do - expect(subject.label.to_s).to eq "{\"none\"=>[\"#{master_file.display_title}\"]}" + it 'autogenerates a basic range with structure_title as label' do + expect(subject.label.to_s).to eq "{\"none\"=>[\"#{master_file.structure_title}\"]}" expect(subject.items.size).to eq 1 expect(subject.items.first).to be_a IiifCanvasPresenter expect(subject.items.first.media_fragment).to eq "t=0,#{master_file.duration.to_f/1000}"