diff --git a/Gemfile.lock b/Gemfile.lock index cf7f2c87bb..247bbb7980 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -24,7 +24,7 @@ GIT GIT remote: https://github.com/avalonmediasystem/media-element-add-to-playlist.git - revision: 90c07c0c8403d88c4c5c091af4468a9656ea4e2b + revision: 129f6bb1d05bd9cea5b359d25ccd2288f2336632 specs: media_element_add_to_playlist (0.0.1) rails (~> 4.0) diff --git a/app/controllers/media_objects_controller.rb b/app/controllers/media_objects_controller.rb index f1ab3f5200..095a6c8a26 100644 --- a/app/controllers/media_objects_controller.rb +++ b/app/controllers/media_objects_controller.rb @@ -87,8 +87,8 @@ def add_to_playlist if playlistitem_scope=='structure' && mf.has_structuralMetadata? && mf.structuralMetadata.xpath('//Span').present? #create individual items for spans within structure mf.structuralMetadata.xpath('//Span').each do |s| - labels = [@media_object.title, mf.title] - labels += s.xpath('ancestor::*[\'label\']').collect{|a|a.attribute('label').value.strip} + labels = [mf.embed_title] + labels += s.xpath('ancestor::Div[\'label\']').collect{|a|a.attribute('label').value.strip} labels << s.attribute('label') label = labels.reject(&:blank?).join(' - ') start_time = s.attribute('begin') diff --git a/app/models/concerns/master_file_behavior.rb b/app/models/concerns/master_file_behavior.rb index 656290c388..4405d27ff3 100644 --- a/app/models/concerns/master_file_behavior.rb +++ b/app/models/concerns/master_file_behavior.rb @@ -68,7 +68,10 @@ def stream_details(token,host=nil) end def embed_title - "#{ self.media_object.title } - #{ self.title.present? ? self.title : self.file_location.split( "/" ).last }" + mf_title = self.structuralMetadata.section_title unless self.structuralMetadata.blank? + mf_title ||= self.title if self.title.present? + mf_title ||= self.file_location.split( "/" ).last if self.file_location.present? + [ self.media_object.title, mf_title ].compact.join(" - ") end def embed_code(width, permalink_opts = {}) diff --git a/app/models/structural_metadata.rb b/app/models/structural_metadata.rb index f42be4ce93..25b45e78a2 100644 --- a/app/models/structural_metadata.rb +++ b/app/models/structural_metadata.rb @@ -33,4 +33,8 @@ def self.content_valid? content def valid? self.class.schema.validate(self.ng_xml).empty? end + + def section_title + xpath('/Item/@label').text() + end end diff --git a/spec/controllers/media_objects_controller_spec.rb b/spec/controllers/media_objects_controller_spec.rb index 7a988710c9..fbec0282cb 100644 --- a/spec/controllers/media_objects_controller_spec.rb +++ b/spec/controllers/media_objects_controller_spec.rb @@ -1057,12 +1057,14 @@ end describe "#add_to_playlist" do - let(:media_object) { FactoryGirl.create(:media_object, ordered_master_files: [FactoryGirl.create(:master_file), master_file_with_structure], title: 'Test Item') } - let(:master_file_with_structure) { FactoryGirl.create(:master_file, :with_structure) } + let(:media_object) { FactoryGirl.create(:media_object, title: 'Test Item') } + let(:master_file) { FactoryGirl.create(:master_file, media_object: media_object, title: 'Test Section') } + let(:master_file_with_structure) { FactoryGirl.create(:master_file, :with_structure, media_object: media_object) } let(:playlist) { FactoryGirl.create(:playlist) } before do login_as 'administrator' + media_object.ordered_master_files = [master_file, master_file_with_structure] end it "should create a single playlist_item for a single master_file" do diff --git a/spec/models/master_file_spec.rb b/spec/models/master_file_spec.rb index 0a3c4d2c2c..48959d81b6 100644 --- a/spec/models/master_file_spec.rb +++ b/spec/models/master_file_spec.rb @@ -380,16 +380,30 @@ class MyEncoder < ActiveEncode::Base end describe "#embed_title" do - subject { FactoryGirl.create( :master_file, { media_object: FactoryGirl.create( :media_object, { title: "test" })})} + context "with structure" do + subject { FactoryGirl.create( :master_file, :with_structure, { media_object: FactoryGirl.create( :media_object, { title: "test" })})} - it "should have an appropriate title for the embed code with no label" do - expect( subject.embed_title ).to eq( "test - video.mp4" ) + it "should favor the structure item label" do + expect( subject.embed_title ).to eq( "test - CD 1" ) + end end - it "should have an appropriate title for the embed code with a label" do - subject.title = "test" + context "without structure" do + subject { FactoryGirl.create( :master_file, { media_object: FactoryGirl.create( :media_object, { title: "test" })})} + + it "should have an appropriate title for the embed code with a label" do + subject.title = "test" + expect( subject.embed_title ).to eq( "test - test" ) + end + + it "should have an appropriate title for the embed code with no label" do + expect( subject.embed_title ).to eq( "test - video.mp4" ) + end - expect( subject.embed_title ).to eq( "test - test" ) + it "should have an appropriate title for the embed code with no label or file_location" do + subject.file_location = nil + expect( subject.embed_title ).to eq( "test" ) + end end end