From 65d23047acb3a0ad420f0d0b67dd3368bcb0c3fc Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Dec 2023 15:08:12 -0800 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=8E=81=20Add=20video=20embed=20to=20O?= =?UTF-8?q?ER=20Work=20Type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit manually adds video embed to oer model and form files. TODO: figure out why including the VideoEmbedBehavior and the VideoEmbedForm modules don't work for OER. Issue: - https://github.com/scientist-softserv/palni-palci/issues/911 --- app/forms/hyrax/oer_form.rb | 4 ++-- app/models/oer.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/forms/hyrax/oer_form.rb b/app/forms/hyrax/oer_form.rb index 458c6b363..bf0c5b30d 100644 --- a/app/forms/hyrax/oer_form.rb +++ b/app/forms/hyrax/oer_form.rb @@ -16,7 +16,7 @@ class OerForm < Hyrax::Forms::WorkForm newer_version_id previous_version_id alternate_version_id related_item_id keyword date_created files visibility_during_embargo embargo_release_date visibility_after_embargo visibility_during_lease lease_expiration_date visibility_after_lease visibility - ordered_member_ids in_works_ids member_of_collection_ids admin_set_id abstract] + ordered_member_ids in_works_ids member_of_collection_ids admin_set_id abstract video_embed] self.terms -=%i[previous_version_id newer_version_id alternate_version_id related_item_id] self.required_fields = %i[title creator resource_type date_created audience education_level learning_resource_type discipline rights_statement] @@ -24,7 +24,7 @@ class OerForm < Hyrax::Forms::WorkForm delegate :related_members_attributes=, :previous_version, :newer_version, :alternate_version, :related_item, to: :model def secondary_terms - super - [:rendering_ids] + super - [:rendering_ids] + [:video_embed] end def self.build_permitted_params diff --git a/app/models/oer.rb b/app/models/oer.rb index 874bf0a84..fbe3a4076 100644 --- a/app/models/oer.rb +++ b/app/models/oer.rb @@ -22,6 +22,15 @@ class Oer < ActiveFedora::Base validates :learning_resource_type, presence: { message: 'You must select a learning resource type.' } validates :resource_type, presence: { message: 'You must select a resource type.' } validates :discipline, presence: { message: 'You must select a discipline.' } + # 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 :audience, predicate: ::RDF::Vocab::SCHEMA.EducationalAudience do |index| index.as :stored_searchable, :facetable @@ -107,6 +116,14 @@ class Oer < 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 + # This must be included at the end, because it finalizes the metadata # schema (by adding accepts_nested_attributes) include ::Hyrax::BasicMetadata From d57efcd4b1ea12c68583219bb48b89201ff9f8ce Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Dec 2023 16:30:32 -0800 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=92=84=20rubocop=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/video_embed_behavior.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/video_embed_behavior.rb b/app/models/concerns/video_embed_behavior.rb index 8fb84b650..8b84e683f 100644 --- a/app/models/concerns/video_embed_behavior.rb +++ b/app/models/concerns/video_embed_behavior.rb @@ -6,7 +6,7 @@ module VideoEmbedBehavior included do validates :video_embed, format: { - with: /(http:\/\/|https:\/\/)(www\.)?(player\.vimeo\.com|youtube\.com\/embed)/, + with: %r{(http://|https://)(www\.)?(player\.vimeo\.com|youtube\.com/embed)}, message: "Error: must be a valid YouTube or Vimeo Embed URL." }, if: :video_embed? From f6e24542712738b231af6077944cc4157dedb7a4 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 7 Dec 2023 08:48:07 -0800 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=A7=B9=20DRY=20code=20into=20modules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit uses VideoEmbedBehavior and VideoEmbedFormBehavior modules to DRY up the video_embed related code. --- app/forms/hyrax/oer_form.rb | 5 +++-- app/forms/video_embed_form_behavior.rb | 2 +- app/models/concerns/video_embed_behavior.rb | 4 +++- app/models/oer.rb | 18 +----------------- config/locales/en.yml | 3 +++ 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/app/forms/hyrax/oer_form.rb b/app/forms/hyrax/oer_form.rb index bf0c5b30d..c48fb3cb8 100644 --- a/app/forms/hyrax/oer_form.rb +++ b/app/forms/hyrax/oer_form.rb @@ -16,15 +16,16 @@ class OerForm < Hyrax::Forms::WorkForm newer_version_id previous_version_id alternate_version_id related_item_id keyword date_created files visibility_during_embargo embargo_release_date visibility_after_embargo visibility_during_lease lease_expiration_date visibility_after_lease visibility - ordered_member_ids in_works_ids member_of_collection_ids admin_set_id abstract video_embed] + ordered_member_ids in_works_ids member_of_collection_ids admin_set_id abstract] self.terms -=%i[previous_version_id newer_version_id alternate_version_id related_item_id] self.required_fields = %i[title creator resource_type date_created audience education_level learning_resource_type discipline rights_statement] delegate :related_members_attributes=, :previous_version, :newer_version, :alternate_version, :related_item, to: :model + include VideoEmbedFormBehavior def secondary_terms - super - [:rendering_ids] + [:video_embed] + super - [:rendering_ids] end def self.build_permitted_params diff --git a/app/forms/video_embed_form_behavior.rb b/app/forms/video_embed_form_behavior.rb index 093b61ae8..35aa0cd55 100644 --- a/app/forms/video_embed_form_behavior.rb +++ b/app/forms/video_embed_form_behavior.rb @@ -7,7 +7,7 @@ module VideoEmbedFormBehavior self.terms += %i[video_embed] end - def secondary_terms + def primary_terms super + %i[video_embed] end end diff --git a/app/models/concerns/video_embed_behavior.rb b/app/models/concerns/video_embed_behavior.rb index 8b84e683f..356abc2d4 100644 --- a/app/models/concerns/video_embed_behavior.rb +++ b/app/models/concerns/video_embed_behavior.rb @@ -7,7 +7,9 @@ module VideoEmbedBehavior validates :video_embed, format: { with: %r{(http://|https://)(www\.)?(player\.vimeo\.com|youtube\.com/embed)}, - message: "Error: must be a valid YouTube or Vimeo Embed URL." + message: ->(object, data) do + I18n.t('errors.messages.valid_embed_url', default: 'must be a valid YouTube or Vimeo Embed URL.') + end }, if: :video_embed? diff --git a/app/models/oer.rb b/app/models/oer.rb index fbe3a4076..19ed59963 100644 --- a/app/models/oer.rb +++ b/app/models/oer.rb @@ -12,6 +12,7 @@ class Oer < ActiveFedora::Base pdf_splitter_service: IiifPrint::TenantConfig::PdfSplitter ) include PdfBehavior + include VideoEmbedBehavior self.indexer = OerIndexer # Change this to restrict which works can be added as a child. @@ -22,15 +23,6 @@ class Oer < ActiveFedora::Base validates :learning_resource_type, presence: { message: 'You must select a learning resource type.' } validates :resource_type, presence: { message: 'You must select a resource type.' } validates :discipline, presence: { message: 'You must select a discipline.' } - # 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 :audience, predicate: ::RDF::Vocab::SCHEMA.EducationalAudience do |index| index.as :stored_searchable, :facetable @@ -116,14 +108,6 @@ class Oer < 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 - # This must be included at the end, because it finalizes the metadata # schema (by adding accepts_nested_attributes) include ::Hyrax::BasicMetadata diff --git a/config/locales/en.yml b/config/locales/en.yml index e684f7fa5..3b2af2869 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,5 +1,8 @@ --- en: + errors: + messages: + valid_embed_url: "must be a valid YouTube or Vimeo Embed URL." single_signon: index: sign_in_with_provider: Sign in with %{provider} From eb15fd7d14346fcda6a6592901e34f78a2f881db Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 7 Dec 2023 09:37:19 -0800 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=8C=8D=20Run=20translations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/concerns/video_embed_behavior.rb | 4 ++-- config/locales/de.yml | 3 +++ config/locales/es.yml | 3 +++ config/locales/fr.yml | 3 +++ config/locales/it.yml | 3 +++ config/locales/pt-BR.yml | 3 +++ config/locales/zh.yml | 3 +++ 7 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/video_embed_behavior.rb b/app/models/concerns/video_embed_behavior.rb index 356abc2d4..27848fc76 100644 --- a/app/models/concerns/video_embed_behavior.rb +++ b/app/models/concerns/video_embed_behavior.rb @@ -7,9 +7,9 @@ module VideoEmbedBehavior validates :video_embed, format: { with: %r{(http://|https://)(www\.)?(player\.vimeo\.com|youtube\.com/embed)}, - message: ->(object, data) do + message: lambda do |_object, _data| I18n.t('errors.messages.valid_embed_url', default: 'must be a valid YouTube or Vimeo Embed URL.') - end + end }, if: :video_embed? diff --git a/config/locales/de.yml b/config/locales/de.yml index 0a15ba9e6..f0386db1f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1,5 +1,8 @@ --- de: + errors: + messages: + valid_embed_url: "muss eine gültige YouTube- oder Vimeo-Einbettungs-URL sein." activefedora: models: cdl: CDL diff --git a/config/locales/es.yml b/config/locales/es.yml index d3d377e49..ba7e846c8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1,5 +1,8 @@ --- es: + errors: + messages: + valid_embed_url: "debe ser una URL de incrustación válida de YouTube o Vimeo." activefedora: models: cdl: CDL diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 0811701bf..048f0267c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1,5 +1,8 @@ --- fr: + errors: + messages: + valid_embed_url: "doit être une URL d'incorporation valide de YouTube ou Vimeo." activefedora: models: cdl: CDL diff --git a/config/locales/it.yml b/config/locales/it.yml index 37a1fda58..dce49a5af 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -1,5 +1,8 @@ --- it: + errors: + messages: + valid_embed_url: "deve essere un URL di incorporamento valido di YouTube o Vimeo." activefedora: models: cdl: CDL diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index e6431457c..c48edf227 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -1,5 +1,8 @@ --- pt-BR: + errors: + messages: + valid_embed_url: "deve ser uma URL de incorporação válida do YouTube ou Vimeo." activefedora: models: cdl: CDL diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 05571d4ac..b4805eae4 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1,5 +1,8 @@ --- zh: + errors: + messages: + valid_embed_url: "必须是有效的YouTube或Vimeo嵌入URL。" activefedora: models: cdl: CDL From 628792aa82036841a241cd7351e9febf3fe58958 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 7 Dec 2023 10:14:51 -0800 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A7=B9=20update:=20pdf=5Fviewer=3F=20?= =?UTF-8?q?should=20be=20show=5Fpdf=5Fviewer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/themes/cultural_show/hyrax/base/show.html.erb | 2 +- app/views/themes/scholarly_show/hyrax/base/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/themes/cultural_show/hyrax/base/show.html.erb b/app/views/themes/cultural_show/hyrax/base/show.html.erb index 83c869d5d..8c9133f90 100644 --- a/app/views/themes/cultural_show/hyrax/base/show.html.erb +++ b/app/views/themes/cultural_show/hyrax/base/show.html.erb @@ -21,7 +21,7 @@
<%= render 'representative_media', presenter: @presenter, viewer: true %>
- <% elsif @presenter.pdf_viewer? %> + <% elsif @presenter.show_pdf_viewer? %>
<%= render 'pdf_js', file_set_presenter: pdf_file_set_presenter(@presenter) %>
diff --git a/app/views/themes/scholarly_show/hyrax/base/show.html.erb b/app/views/themes/scholarly_show/hyrax/base/show.html.erb index 4a0d4db30..13924621a 100644 --- a/app/views/themes/scholarly_show/hyrax/base/show.html.erb +++ b/app/views/themes/scholarly_show/hyrax/base/show.html.erb @@ -32,7 +32,7 @@ <% render 'work_description', presenter: @presenter %> - <% elsif @presenter.pdf_viewer? %> + <% elsif @presenter.show_pdf_viewer? %>
<%= render 'pdf_js', file_set_presenter: pdf_file_set_presenter(@presenter) %>