Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Commit

Permalink
Add embed url to audio and image
Browse files Browse the repository at this point in the history
Add test for video object

Fix failed test

Update image embed url function

Change to use image service for image embed url feature

Change embed code to use textarea

Change width & height for audio embed code

Add resize function

Fix audio display behavior
  • Loading branch information
VivianChu committed Jan 7, 2019
1 parent 7387ed1 commit 8f56e88
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 15 deletions.
8 changes: 5 additions & 3 deletions app/views/dams_objects/_admin_download.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
etc_menu_item_class = 'pull-right'
embed_glyph = '<i class="glyphicon glyphicon-share-alt"></i> Embed'.html_safe
adl_glyph = '<i class="glyphicon glyphicon-download-alt"></i> Download File'.html_safe
file_format = (defined?(format)) ? "#{format.capitalize}" : ''
embed_width = (format == 'audio') ? '629' : '560'
embed_height = (format == 'audio') ? '46' : '315'
%>

<div class="etc-menu">
Expand All @@ -27,9 +30,8 @@
<div class="modal-body">
<h4>Embed URL</h4>
<input class="embedCode" readonly="readonly" type="text" onclick="this.focus();this.select()" value="<%=embed_url%>">
<h4>Embed Video</h4>
<input class="embedCode" readonly="readonly" type="text" onclick="this.focus();this.select()" value='&lt;iframe src="<%=embed_url%>" width="560" height="315" frameborder="0"&gt;&lt;/iframe&gt;'>
<p><em>By embedding Digital Collections videos on your site, you are agreeing to our Terms of Service.</em></p>
<h4>Embed <%= file_format %></h4>
<textarea class="embedCode" readonly="readonly" rows="2" wrap="hard" onclick="this.focus();this.select()">&lt;iframe src="<%=embed_url%>" width="<%= embed_width%>" height="<%= embed_height%>" frameborder="0"&gt;&lt;/iframe&gt;</textarea>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
Expand Down
5 changes: 3 additions & 2 deletions app/views/dams_objects/_audio_viewer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
cmpid = (defined?(componentIndex)) ? "#{componentIndex}" : '0'
fieldData = @document["#{prefix}files_tesim"]
wowzaURL = grabWowzaURL(fieldData,objid,cmpid)
embed_url = "#{root_url}embed/#{objid}/#{cmpid}"
file_type = grabFileType(grabFileUse)
%>
<% if wowzaURL != nil %>

<div id="dams-audio">Loading the player...</div>

<script type="text/javascript">
Expand All @@ -32,4 +33,4 @@
</script>

<% end %>
<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath } %>
<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :embedURL => embed_url, :downloadDerivativePath => downloadDerivativePath, :format => file_type } %>
4 changes: 3 additions & 1 deletion app/views/dams_objects/_audio_viewer_complex.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
fieldData = @document["#{prefix}files_tesim"]
wowzaURL = grabWowzaURL(fieldData,objid,cmpid)
dataForDynamicLoad = "{\"file_type\":\"audio\",\"display_file_path\":\"\",\"service_file_path\":\"#{wowzaURL}\"}"
embed_url = "#{root_url}embed/#{objid}/#{cmpid}"
file_type = grabFileType(grabFileUse(:componentIndex=>cmpid))
%>
<% if access_notice.nil? && wowzaURL != nil %>
Expand All @@ -13,4 +15,4 @@

<% end %>
<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath } if access_notice.nil?%>
<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :cmpID => cmpid, :embedURL => embed_url, :downloadDerivativePath => downloadDerivativePath, :format => file_type } if access_notice.nil?%>
7 changes: 4 additions & 3 deletions app/views/dams_objects/_complex_object_viewer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
fileType = grabFileType(fileUse)
loadFirstComponent = (firstComponent != nil) ? "data=#{i}" : ''
source_file = grabSourceFile(:componentIndex=>i)

objid = @document['id']
embed_url = "#{root_url}embed/#{objid}/#{i}"
if source_file != nil
download_file_path = download_path(ark,"_#{i}_#{source_file}")
source_file_path = download_path(ark,"_#{i}_#{source_file}")
Expand Down Expand Up @@ -69,7 +70,7 @@
<div data='<%=dataForDynamicLoad%>'></div>
<% end %>
<%= render :partial => 'metadata_component', :locals => {:componentIndex => i} %>
<%= render :partial => 'admin_download', :locals => {:downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } if access_notice.nil?%>
<%= render :partial => 'admin_download', :locals => {:embedURL => embed_url, :downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path, :format => fileType } if access_notice.nil?%>
<% elsif fileType == 'audio' %>
<%= render :partial => 'audio_viewer_complex', :locals => {:access_notice => access_notice, :componentIndex => i, :downloadFilePath => download_file_path, :downloadDerivativePath => nil } %>
Expand All @@ -91,7 +92,7 @@
<%= render :partial => 'data_viewer', :locals => {:objectType => 'complex', :filePath => service_file_path, :downloadDerivativePath => service_file_path, :sourcefilePath => source_file_path } if access_notice.nil?%>
<% elsif fileType == 'text' %>
<%= render :partial => 'metadata_component', :locals => {:componentIndex => i, :fileMetadata => true, :fileName => service_file} %>
<%= render :partial => 'text_viewer', :locals => {:objectType => 'complex', :downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path } if access_notice.nil?%>
<%= render :partial => 'text_viewer', :locals => {:objectType => 'complex', :downloadFilePath => download_file_path, :downloadDerivativePath => service_file_path, :embedURL => embed_url, :format => fileType } if access_notice.nil?%>
<% else %>
<%= render :partial => 'metadata_component', :locals => {:componentIndex => i} %>
<%= render :partial => 'default_viewer', :locals => {:objectType => 'complex'} %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/dams_objects/_image_viewer.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<% title=render_document_show_field_value(:document=>@document, :field=>'title_tesim') %>
<%
objid = @document['id']
cmpid = (defined?(componentIndex)) ? "#{componentIndex}" : '0'
embed_url = "#{root_url}embed/#{objid}/#{cmpid}"
file_type = grabFileType(grabFileUse)
%>
<% if displayFilePath.length > 0 && getFilesType != "PDF"%>
<%= link_to image_tag(displayFilePath, :alt => ''), zoomFilePath %>
<% else %>
Expand All @@ -14,4 +20,4 @@
<%= link_to image_tag(filePath, :alt => ''), zoomFilePath %>
<% end %>
<% end %>
<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath} %>
<%= render :partial => 'admin_download', :locals => {:embedURL => embed_url, :downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath, :format => file_type} %>
2 changes: 1 addition & 1 deletion app/views/dams_objects/_text_viewer.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render :partial => 'admin_download', :locals => {:downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath } %>
<%= render :partial => 'admin_download', :locals => {:embedURL => embedURL, :downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath, :format => format } %>
3 changes: 2 additions & 1 deletion app/views/dams_objects/_video_viewer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
fieldData = @document["#{prefix}files_tesim"]
wowzaURL = grabWowzaURL(fieldData,objid,cmpid)
embed_url = "#{root_url}embed/#{objid}/#{cmpid}"
file_type = grabFileType(grabFileUse)
%>
<% if wowzaURL != nil %>
Expand All @@ -29,4 +30,4 @@
</script>

<% end %>
<%= render :partial => 'admin_download', :locals => {:cmpID => cmpid, :embedURL => embed_url, :downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath, :wowzaURL => wowzaURL } %>
<%= render :partial => 'admin_download', :locals => {:cmpID => cmpid, :embedURL => embed_url, :downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath, :wowzaURL => wowzaURL, :format => file_type } %>
3 changes: 2 additions & 1 deletion app/views/dams_objects/_video_viewer_complex.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
wowzaURL = grabWowzaURL(fieldData,objid,cmpid)
dataForDynamicLoad = "{\"file_type\":\"video\",\"display_file_path\":\"\",\"service_file_path\":\"#{wowzaURL}\"}"
embed_url = "#{root_url}embed/#{objid}/#{cmpid}"
file_type = grabFileType(grabFileUse(:componentIndex=>cmpid))
%>
<% if access_notice.nil? && wowzaURL != nil %>
<video controls="controls" id="dams-video-<%=componentIndex%>" data='<%=dataForDynamicLoad%>'>Loading the player...</video>
<% end %>
<%= render :partial => 'admin_download', :locals => {:cmpID => cmpid, :embedURL => embed_url, :downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath, :wowzaURL => wowzaURL } if access_notice.nil?%>
<%= render :partial => 'admin_download', :locals => {:cmpID => cmpid, :embedURL => embed_url, :downloadFilePath => downloadFilePath, :downloadDerivativePath => downloadDerivativePath, :wowzaURL => wowzaURL, :format => file_type } if access_notice.nil?%>
24 changes: 22 additions & 2 deletions app/views/dams_objects/embed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
prefix = (component_id != '0') ? "component_#{component_id}_" : ''
field_data = @document["#{prefix}files_tesim"]
wowza_url = grabWowzaURL(field_data, object_id, component_id)
file_type = grabFileType(grabFileUse)
%>
<% if wowza_url != nil %>

<% if file_type.include?("image") %>
<%
display_file = grabServiceFile
display_file_path = (display_file != 'no_display') ? file_path(object_id,"_#{display_file}") : ''
%>
<%= image_tag(display_file_path, :alt => '') %>
<% elsif wowza_url != nil%>
<video controls="controls" id="dams-video">Loading the player...</video>
<script type="text/javascript">
Expand All @@ -25,6 +31,20 @@
rtmp: {bufferlength: 3},
analytics: {enabled: false}
});
<% if file_type.include?("audio") %>
jwplayer().on('ready', function() {
resize('dams-video');
window.onresize = function() {
resize('dams-video');
};
});
function resize(id) {
let newWidth = 0.94;
let parent = document.getElementById(id).parentElement;
let currentWidth = parent.offsetWidth;
jwplayer(id).resize(currentWidth * newWidth, 40);
}
<% end %>
</script>

<% end %>
29 changes: 29 additions & 0 deletions spec/features/dams_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1626,3 +1626,32 @@
expect(page).to have_css('img.dams-search-thumbnail[src="https://library.ucsd.edu/assets/dams/site/thumb-restricted.png"]')
end
end

describe "User wants to view an Image object" do
before(:all) do
@col = DamsAssembledCollection.create( titleValue: 'Test Collection', visibility: 'public' )
@obj = DamsObject.create( titleValue: 'Object Files Test', copyright_attributes: [ {status: 'Public domain'} ],
assembledCollectionURI: [ @col.pid ], typeOfResource: 'image' )
jpeg_content = '/9j/4AAQSkZJRgABAQEAAQABAAD/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/wAALCAABAAEBAREA/8QAFAABAAAAAAAAAAAAAAAAAAAACf/EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAD8AVN//2Q=='
@obj.add_file( Base64.decode64(jpeg_content), "_1.jpg", "test.jpg" )
@obj.save
solr_index @col.pid
solr_index @obj.pid
end
after(:all) do
@obj.delete
@col.delete
end
scenario 'show a popup embed modal when user clicks on embed link' do
Capybara.javascript_driver = :poltergeist
Capybara.current_driver = Capybara.javascript_driver
sign_in_developer
visit dams_object_path @obj.pid
click_link 'Embed'
within('.modal-body') do
expect(page).to have_content('Embed URL')
expect(page).to have_content('Embed Image')
expect(page.body).to match(/embed\/#{@obj.id}\/0/)
end
end
end

0 comments on commit 8f56e88

Please sign in to comment.