From bf0748774dbd09b8b6186cf46adeca7866fcf677 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Dec 2023 10:16:26 -0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=8E=81=20Video=20Embed:=20CDL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds video embed to CDL work type. Issue: - https://github.com/scientist-softserv/palni-palci/issues/911 --- app/forms/hyrax/cdl_form.rb | 6 +++++- app/models/cdl.rb | 18 ++++++++++++++++++ app/presenters/hyku/work_show_presenter.rb | 4 ++++ app/views/hyrax/base/show.html.erb | 21 ++++++++++++++------- 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/forms/hyrax/cdl_form.rb b/app/forms/hyrax/cdl_form.rb index cf05df61a..5a351bd96 100644 --- a/app/forms/hyrax/cdl_form.rb +++ b/app/forms/hyrax/cdl_form.rb @@ -8,9 +8,13 @@ class CdlForm < Hyrax::Forms::WorkForm include HydraEditor::Form::Permissions include PdfFormBehavior # 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[contributing_library library_catalog_identifier admin_note video_embed] + self.terms # rubocop:disable Style/RedundantSelf self.terms += %i[resource_type additional_information bibliographic_citation chronology_note] self.terms -= %i[based_near] self.required_fields = %i[title creator keyword rights_statement resource_type] + + def secondary_terms + super + %i[video_embed] + end end end diff --git a/app/models/cdl.rb b/app/models/cdl.rb index e75aa746b..698402e8d 100644 --- a/app/models/cdl.rb +++ b/app/models/cdl.rb @@ -16,6 +16,16 @@ class Cdl < ActiveFedora::Base self.indexer = CdlIndexer 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 @@ -44,6 +54,14 @@ class Cdl < 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 diff --git a/app/presenters/hyku/work_show_presenter.rb b/app/presenters/hyku/work_show_presenter.rb index c6777a2bf..fd43da0fd 100644 --- a/app/presenters/hyku/work_show_presenter.rb +++ b/app/presenters/hyku/work_show_presenter.rb @@ -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? || pdf_viewer? + end + def parent_works(current_user = nil) @parent_works ||= begin docs = solr_document.load_parent_docs diff --git a/app/views/hyrax/base/show.html.erb b/app/views/hyrax/base/show.html.erb index 7866a0fe4..f30a36836 100644 --- a/app/views/hyrax/base/show.html.erb +++ b/app/views/hyrax/base/show.html.erb @@ -29,14 +29,21 @@
<%= render 'pdf_js', file_set_presenter: pdf_file_set_presenter(@presenter) %>
+ <% else %> +
+ <%= 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 %> +
+ <% end %> + <% if @presenter.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 %> + + <%#= render 'analytics_button', presenter: @presenter %> +
<% end %> -
- <%= 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 %> - - <%#= render 'analytics_button', presenter: @presenter %> -
<%= render 'work_description', presenter: @presenter %> <%= render 'metadata', presenter: @presenter %> From a9b2399b560aed9ee66892b8974c9f535d950c87 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Dec 2023 10:51:23 -0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8E=81=20Video=20Embed:=20Image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds video embed to CDL work type. Issue: - #911 --- app/forms/hyrax/image_form.rb | 6 +++++- app/models/concerns/video_embed_behavior.rb | 22 +++++++++++++++++++++ app/models/image.rb | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/models/concerns/video_embed_behavior.rb diff --git a/app/forms/hyrax/image_form.rb b/app/forms/hyrax/image_form.rb index 17009fbf4..c32bc883a 100644 --- a/app/forms/hyrax/image_form.rb +++ b/app/forms/hyrax/image_form.rb @@ -8,8 +8,12 @@ class ImageForm < Hyrax::Forms::WorkForm self.model_class = ::Image include PdfFormBehavior - self.terms = [:admin_note] + self.terms # rubocop:disable Style/RedundantSelf + self.terms = [:admin_note, :video_embed] + self.terms # rubocop:disable Style/RedundantSelf self.terms += %i[resource_type extent 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 diff --git a/app/models/concerns/video_embed_behavior.rb b/app/models/concerns/video_embed_behavior.rb new file mode 100644 index 000000000..8fb84b650 --- /dev/null +++ b/app/models/concerns/video_embed_behavior.rb @@ -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 diff --git a/app/models/image.rb b/app/models/image.rb index 798181b1f..3e8d6bebe 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -9,6 +9,7 @@ class Image < ActiveFedora::Base pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter ) include PdfBehavior + include VideoEmbedBehavior self.indexer = ImageIndexer From 8d997e4133dae27ea22445f97defedd0b6fa9726 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Dec 2023 10:54:50 -0800 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A7=B9=20DRY=20up=20repetitive=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CDL and GenericWork models inherits from VideoEmbedBehavior. This DRYs up identical code being repeated in various places. --- app/models/cdl.rb | 15 +-------------- app/models/generic_work.rb | 19 +------------------ 2 files changed, 2 insertions(+), 32 deletions(-) diff --git a/app/models/cdl.rb b/app/models/cdl.rb index 698402e8d..1b10c491b 100644 --- a/app/models/cdl.rb +++ b/app/models/cdl.rb @@ -12,20 +12,11 @@ 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.' } - # 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 @@ -58,10 +49,6 @@ class Cdl < ActiveFedora::Base 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 diff --git a/app/models/generic_work.rb b/app/models/generic_work.rb index f69ba5b85..a336473a3 100644 --- a/app/models/generic_work.rb +++ b/app/models/generic_work.rb @@ -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 @@ -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 From 755e4f5cd0c58aa3f45d04aeab3d05652d5d75fd Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Dec 2023 11:05:23 -0800 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A7=B9=20Create=20a=20module=20for=20?= =?UTF-8?q?video=20embed=20form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit DRYs up repetitive code by creating a VideoEmbedFormBehavior module. --- app/forms/hyrax/cdl_form.rb | 7 ++----- app/forms/hyrax/generic_work_form.rb | 7 ++----- app/forms/hyrax/image_form.rb | 7 ++----- app/forms/video_embed_form_behavior.rb | 13 +++++++++++++ app/models/cdl.rb | 4 ---- app/presenters/hyku/work_show_presenter.rb | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) create mode 100644 app/forms/video_embed_form_behavior.rb diff --git a/app/forms/hyrax/cdl_form.rb b/app/forms/hyrax/cdl_form.rb index 5a351bd96..0163bd7e5 100644 --- a/app/forms/hyrax/cdl_form.rb +++ b/app/forms/hyrax/cdl_form.rb @@ -7,14 +7,11 @@ 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 video_embed] + self.terms # rubocop:disable Style/RedundantSelf + 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] self.terms -= %i[based_near] self.required_fields = %i[title creator keyword rights_statement resource_type] - - def secondary_terms - super + %i[video_embed] - end end end diff --git a/app/forms/hyrax/generic_work_form.rb b/app/forms/hyrax/generic_work_form.rb index 724c9f90b..3e1079eb1 100644 --- a/app/forms/hyrax/generic_work_form.rb +++ b/app/forms/hyrax/generic_work_form.rb @@ -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 diff --git a/app/forms/hyrax/image_form.rb b/app/forms/hyrax/image_form.rb index c32bc883a..5e2d39a15 100644 --- a/app/forms/hyrax/image_form.rb +++ b/app/forms/hyrax/image_form.rb @@ -7,13 +7,10 @@ class ImageForm < Hyrax::Forms::WorkForm include Hyrax::FormTerms self.model_class = ::Image include PdfFormBehavior + include VideoEmbedFormBehavior - self.terms = [:admin_note, :video_embed] + self.terms # rubocop:disable Style/RedundantSelf + self.terms = [:admin_note] + self.terms # rubocop:disable Style/RedundantSelf self.terms += %i[resource_type extent 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 diff --git a/app/forms/video_embed_form_behavior.rb b/app/forms/video_embed_form_behavior.rb new file mode 100644 index 000000000..093b61ae8 --- /dev/null +++ b/app/forms/video_embed_form_behavior.rb @@ -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 diff --git a/app/models/cdl.rb b/app/models/cdl.rb index 1b10c491b..95b1d0132 100644 --- a/app/models/cdl.rb +++ b/app/models/cdl.rb @@ -45,10 +45,6 @@ class Cdl < 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 - include ::Hyrax::BasicMetadata # This line must be kept below all others that set up properties, # including `include ::Hyrax::BasicMetadata`. All properties must diff --git a/app/presenters/hyku/work_show_presenter.rb b/app/presenters/hyku/work_show_presenter.rb index fd43da0fd..d2aadf543 100644 --- a/app/presenters/hyku/work_show_presenter.rb +++ b/app/presenters/hyku/work_show_presenter.rb @@ -93,7 +93,7 @@ def show_pdf_download_button? end def viewer? - iiif_viewer? || video_embed_viewer? || pdf_viewer? + iiif_viewer? || video_embed_viewer? || show_pdf_viewer? end def parent_works(current_user = nil)