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

🎁 Add video embed to OER Work Type #931

Merged
merged 6 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions app/forms/hyrax/oer_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ 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]

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
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/video_embed_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
ShanaLMoore marked this conversation as resolved.
Show resolved Hide resolved
message: "Error: must be a valid YouTube or Vimeo Embed URL."
},
if: :video_embed?
Expand Down
17 changes: 17 additions & 0 deletions app/models/oer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down