Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎁 I911 Video Embed: Image Work Type #928

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/forms/hyrax/cdl_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CdlForm < Hyrax::Forms::WorkForm
self.model_class = ::Cdl
include HydraEditor::Form::Permissions
include PdfFormBehavior
include VideoEmbedFormBehavior
# List these terms first after the "Additional fields" divider
self.terms = %i[contributing_library library_catalog_identifier admin_note] + self.terms # rubocop:disable Style/RedundantSelf
self.terms += %i[resource_type additional_information bibliographic_citation chronology_note]
Expand Down
7 changes: 2 additions & 5 deletions app/forms/hyrax/generic_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ class GenericWorkForm < Hyrax::Forms::WorkForm
self.model_class = ::GenericWork
include HydraEditor::Form::Permissions
include PdfFormBehavior
include VideoEmbedFormBehavior

self.terms = [:admin_note, :video_embed] + terms
self.terms = [:admin_note] + terms
self.terms += %i[resource_type additional_information bibliographic_citation]
self.required_fields = %i[title creator keyword rights_statement resource_type]

def secondary_terms
super + %i[video_embed]
end
end
end
1 change: 1 addition & 0 deletions app/forms/hyrax/image_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ImageForm < Hyrax::Forms::WorkForm
include Hyrax::FormTerms
self.model_class = ::Image
include PdfFormBehavior
include VideoEmbedFormBehavior

self.terms = [:admin_note] + self.terms # rubocop:disable Style/RedundantSelf
self.terms += %i[resource_type extent additional_information bibliographic_citation]
Expand Down
13 changes: 13 additions & 0 deletions app/forms/video_embed_form_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_sting_literal: true

module VideoEmbedFormBehavior
extend ActiveSupport::Concern

included do
self.terms += %i[video_embed]
end

def secondary_terms
super + %i[video_embed]
end
end
1 change: 1 addition & 0 deletions app/models/cdl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Cdl < ActiveFedora::Base
pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter
)
include PdfBehavior
include VideoEmbedBehavior

self.indexer = CdlIndexer
validates :title, presence: { message: 'Your work must have a title.' }
Expand Down
22 changes: 22 additions & 0 deletions app/models/concerns/video_embed_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module VideoEmbedBehavior
extend ActiveSupport::Concern

included do
validates :video_embed,
format: {
with: /(http:\/\/|https:\/\/)(www\.)?(player\.vimeo\.com|youtube\.com\/embed)/,
message: "Error: must be a valid YouTube or Vimeo Embed URL."
},
if: :video_embed?

property :video_embed, predicate: ::RDF::URI("https://atla.com/terms/video_embed"), multiple: false do |index|
index.as :stored_searchable
end
end

def video_embed?
video_embed.present?
end
end
19 changes: 1 addition & 18 deletions app/models/generic_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,12 @@ class GenericWork < ActiveFedora::Base
pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter
)
include PdfBehavior
include VideoEmbedBehavior

self.indexer = GenericWorkIndexer

validates :title, presence: { message: 'Your work must have a title.' }

# rubocop:disable Style/RegexpLiteral
validates :video_embed,
format: {
# regex matches only youtube & vimeo urls that are formatted as embed links.
with: /(http:\/\/|https:\/\/)(www\.)?(player\.vimeo\.com|youtube\.com\/embed)/,
message: "Error: must be a valid YouTube or Vimeo Embed URL."
},
if: :video_embed?
# rubocop:enable Style/RegexpLiteral

property :additional_information, predicate: ::RDF::Vocab::DC.accessRights do |index|
index.as :stored_searchable
end
Expand All @@ -42,14 +33,6 @@ class GenericWork < ActiveFedora::Base
index.as :stored_searchable, :facetable
end

property :video_embed, predicate: ::RDF::URI("https://atla.com/terms/video_embed"), multiple: false do |index|
index.as :stored_searchable
end

def video_embed?
video_embed.present?
end

include ::Hyrax::BasicMetadata
# This line must be kept below all others that set up properties,
# including `include ::Hyrax::BasicMetadata`. All properties must
Expand Down
1 change: 1 addition & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Image < ActiveFedora::Base
pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter
)
include PdfBehavior
include VideoEmbedBehavior

self.indexer = ImageIndexer

Expand Down
4 changes: 4 additions & 0 deletions app/presenters/hyku/work_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ def show_pdf_download_button?
show_pdf_download_button.first.to_i.positive?
end

def viewer?
iiif_viewer? || video_embed_viewer? || show_pdf_viewer?
end

def parent_works(current_user = nil)
@parent_works ||= begin
docs = solr_document.load_parent_docs
Expand Down
21 changes: 14 additions & 7 deletions app/views/hyrax/base/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@
<div class="col-sm-12">
<%= render 'pdf_js', file_set_presenter: pdf_file_set_presenter(@presenter) %>
</div>
<% else %>
<div class="col-sm-3 text-center">
<%= render 'representative_media', presenter: @presenter, viewer: false %>
<%= render('download_pdf', presenter: @presenter, file_set_id: @presenter.file_set_presenters.first.id) if @presenter.show_pdf_download_button? %>
<%= render 'citations', presenter: @presenter %>
</div>
<% end %>
<% if @presenter.viewer? %>
<div class="col-sm-3 text-center">
<%= render('download_pdf', presenter: @presenter, file_set_id: @presenter.file_set_presenters.first.id) if @presenter.show_pdf_download_button? %>
<%= render 'citations', presenter: @presenter %>
<!-- analytics_button is disabled until future fix -->
<%#= render 'analytics_button', presenter: @presenter %>
</div>
<% end %>
<div class="col-sm-3 text-center">
<%= render 'representative_media', presenter: @presenter, viewer: false unless @presenter.iiif_viewer? || @presenter.show_pdf_viewer? %>
<%= render('download_pdf', presenter: @presenter, file_set_id: @presenter.file_set_presenters.first.id) if @presenter.show_pdf_download_button? %>
<%= render 'citations', presenter: @presenter %>
<!-- analytics_button is disabled until future fix -->
<%#= render 'analytics_button', presenter: @presenter %>
</div>
<div class="col-sm-9">
<%= render 'work_description', presenter: @presenter %>
<%= render 'metadata', presenter: @presenter %>
Expand Down