Skip to content

Commit

Permalink
🎁 Add video embed to Generic Work
Browse files Browse the repository at this point in the history
This commit allows videos to be embedded into a Generic Work. When the value is present, an embedded video should display.

related:
- https://github.com/scientist-softserv/atla-hyku/pull/34/files

Issue:
- #911
  • Loading branch information
ShanaLMoore committed Dec 6, 2023
1 parent 3f80715 commit b834101
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 6 deletions.
10 changes: 10 additions & 0 deletions RepoREADME.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,13 @@ Multi-tenant mode:
```bash
rake tenantize:task[workflow:setup]
```
### Youtube/Vimeo Video Player For Works
- Works will have the option to add a youtube or vimeo player via an embed link
- This link must be a correctly formatted embed link from either youtube or vimeo.
- To find this link:
- Navigate to the url of the video you would like to include.
- Click the "share" button
- You will see a link or a section called "Embed". View the embed code for the video
- Copy JUST the link. The link will be formatted as so for Youtube and Vimeo respectively:
- https://www.youtube.com/embed/Znf73dsFdC8
- https://player.vimeo.com/video/467264493?h=b089de0eab
8 changes: 5 additions & 3 deletions app/assets/stylesheets/viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
.viewer {
height: 100%;
padding: 10px;
iframe {
// position: absolute;
}
}

#viewer-modal {
Expand All @@ -21,3 +18,8 @@
margin-bottom: 10px;
}
}

.video-embed-viewer {
aspect-ratio: 16 / 9;
width: 100%;
}
6 changes: 5 additions & 1 deletion app/forms/hyrax/generic_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ class GenericWorkForm < Hyrax::Forms::WorkForm
include HydraEditor::Form::Permissions
include PdfFormBehavior

self.terms = [:admin_note] + self.terms # rubocop:disable Style/RedundantSelf
self.terms = [:admin_note, :video_embed] + 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
18 changes: 18 additions & 0 deletions app/models/generic_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ class GenericWork < ActiveFedora::Base

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 @@ -32,6 +42,14 @@ 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/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SolrDocument
attribute :library_catalog_identifier, Solr::String, 'library_catalog_identifier_tesim'
attribute :chronology_note, Solr::String, 'chronology_note_tesim'
attribute :based_near, Solr::Array, 'based_near_tesim'
attribute :video_embed, Solr::String, 'video_embed_tesim'

field_semantics.merge!(
contributor: 'contributor_tesim',
Expand Down
7 changes: 7 additions & 0 deletions app/presenters/hyku/work_show_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ def parent_works(current_user = nil)
end
end

def video_embed_viewer?
extract_video_embed_presence
end

private

def extract_video_embed_presence
solr_document[:video_embed_tesim].present?
end

def extract_from_identifier(rgx)
if solr_document['identifier_tesim'].present?
ref = solr_document['identifier_tesim'].map do |str|
Expand Down
24 changes: 24 additions & 0 deletions app/views/hyrax/base/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%# OVERRIDE Hyrax 3.6.0 to remove the broken error alerts from form validations %>
<%= simple_form_for [main_app, @form],
html: {
data: { behavior: 'work-form',
'param-key' => @form.model_name.param_key },
multipart: true
} do |f| %>
<%# OVERRIDE Here to remove broken error alert from form validation %>
<% if Flipflop.batch_upload? && !f.object.persisted? %>
<% provide :metadata_tab do %>
<p class="switch-upload-type"><%= t('.batch_upload_hint') %> <%= link_to t('.batch_link'), hyrax.new_batch_upload_path(payload_concern: @form.model.class) %></p>
<% end %>
<% end %>
<%= render 'hyrax/base/guts4form', f: f, tabs: form_tabs_for(form: f.object) %>
<% end %>

<script type="text/javascript">
Blacklight.onLoad(function() {
<%# This causes the page to switch back to the default template if they've
previously visited the batch download page in this Turbolinks session %>
$("#fileupload").fileupload('option', 'downloadTemplateId', 'template-download')
});
</script>
3 changes: 3 additions & 0 deletions app/views/hyrax/base/_video_embed_viewer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="col-sm-12">
<iframe class='video-embed-viewer' src="<%="#{@presenter.solr_document[:video_embed_tesim].first}"%>" title="Video Player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>
4 changes: 3 additions & 1 deletion app/views/hyrax/base/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<div class="panel-body">
<div class="row">
<%= render 'workflow_actions_widget', presenter: @presenter %>
<% if @presenter.iiif_viewer? %>
<% if @presenter.video_embed_viewer? %>
<%= render 'video_embed_viewer', presenter: @presenter %>
<% elsif @presenter.iiif_viewer? %>
<div class="col-sm-12">
<%= render 'representative_media', presenter: @presenter, viewer: true %>
</div>
Expand Down
41 changes: 41 additions & 0 deletions app/views/layouts/hyrax/dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%# OVERRIDE from Hyrax 3.6.0 to hide broken flash messages on the dashboard edit work pages %>

<!DOCTYPE html>
<html lang="<%= I18n.locale.to_s %>" prefix="og:http://ogp.me/ns#">
<head>
<%= render partial: 'layouts/head_tag_content' %>
<%= content_for(:head) %>
</head>

<body class="dashboard">
<div class="skip-to-content">
<%= link_to "Skip to Content", "#skip-to-content" %>
</div>
<%= render '/masthead' %>
<%= content_for(:navbar) %>
<div id="content-wrapper" role="main">
<div class="sidebar maximized">
<%= render 'hyrax/dashboard/sidebar' %>
</div>
<div class="main-content maximized">
<%# OVERRIDE here to hide broken flash messages on the dashboard edit work pages. %>
<%# regex includes only the paths for works since this is the only known place flash messages are broken. %>
<%= render '/flash_msg' %>
<%= render_breadcrumbs builder: Hyrax::BootstrapBreadcrumbsBuilder %>
<% if content_for?(:page_header) %>
<div class="row">
<div class="col-xs-12 main-header">
<%= yield(:page_header) %>
</div>
</div>
<% end %>

<a name="skip-to-content" id="skip-to-content"></a>
<%= content_for?(:content) ? yield(:content) : yield %>

</div>

</div><!-- /#content-wrapper -->
<%= render 'shared/ajax_modal' %>
</body>
</html>
4 changes: 3 additions & 1 deletion config/initializers/bulkrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
}

config.field_mappings['Bulkrax::BagitParser'] = parser_mappings
config.field_mappings['Bulkrax::CsvParser'] = parser_mappings
config.field_mappings['Bulkrax::CsvParser'] = parser_mappings.merge(
{'video_embed' => { from: ['video_embed'] }}
)

# Add to, or change existing mappings as follows
# e.g. to exclude date
Expand Down
1 change: 1 addition & 0 deletions config/locales/hyrax.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ en:
resource_type: Pre-defined categories to describe the type of content being uploaded, such as &quot;article&quot; or &quot;dataset.&quot; More than one type may be selected.
subject: Headings or index terms describing what the work is about; these do need to conform to an existing vocabulary.
title: A name to aid in identifying a work.
video_embed: "If you enter an embed link for a video, it must be a properly formatted url beginning with 'http://' or 'https://'. It also needs to contain a valid link to a hosted video that can appear in an iframe. <br /><br /><i>Examples:<br/>https://player.vimeo.com/video/467264493?h=b089de0eab<br/>https://www.youtube.com/embed/Znf73dsFdC8</i>"
labels:
collection:
size: Size
Expand Down

0 comments on commit b834101

Please sign in to comment.