Skip to content

Commit

Permalink
split out downloads partial
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed Aug 1, 2016
1 parent 7830796 commit e9c58bb
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 47 deletions.
49 changes: 2 additions & 47 deletions app/views/catalog/_downloads.html.erb
Original file line number Diff line number Diff line change
@@ -1,53 +1,8 @@
<% document ||= @document %>
<% if document_downloadable? %>
<div class='btn-group' itemprop='distribution' itemscope='itemscope' itemtype='http://schema.org/DataDownload'>
<% if document.direct_download.present? %>
<%= link_to(download_text(document.file_format), document.direct_download[:download], class: 'btn btn-default', 'contentUrl' => document.direct_download[:download], data: { download: 'trigger', download_type: 'direct', download_id: document.id }) %>
<% elsif document.hgl_download.present? %>
<%= link_to(download_text(document.download_types.first[0]),
download_hgl_path(id: document), data: {ajax_modal: 'trigger', download: 'trigger', download_type: 'harvard-hgl', download_id: document.id },
class: 'btn btn-default') %>
<% elsif document.iiif_download.present? %>
<%= link_to "Download JPG", iiif_jpg_url, class: 'btn btn-default', download: 'trigger' %>
<% else %>
<%= link_to(download_text(document.download_types.first[0]), '', data: { download_path: "#{download_path(document.id, type: document.download_types.first[0])}", download: 'trigger', download_type: document.download_types.first[0], download_id: document.id }, class: 'btn btn-default') %>
<% end %>
<button type='button' class='btn btn-default dropdown-toggle download-dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
<span class='caret'></span>
<span class='sr-only'>Toggle Download Dropdown</span>
</button>
<ul class='dropdown-menu' role='menu'>
<% if document.hgl_download.present? %>
<li role="presentation" class="dropdown-header">Original</li>
<li>
<%= link_to(download_text(document.download_types.first[0]),
download_hgl_path(id: document), data: {ajax_modal: 'trigger', download: 'trigger', download_type: 'harvard-hgl', download_id: document.id }) %>
</li>
<% else %>
<% if document.direct_download.present? %>
<li role="presentation" class="dropdown-header">Original</li>
<li>
<%= link_to(download_text(@document.file_format), document.direct_download[:download], 'contentUrl' => document.direct_download[:download], data: { download: 'trigger', download_type: 'direct', download_id: document.id }) %>
</li>
<% end %>
<% if document.download_types.present? || document.iiif_download.present? %>
<li role="presentation" class="dropdown-header">Generated</li>
<% end %>
<% if document.iiif_download.present? %>
<li>
<%= link_to "Download JPG", iiif_jpg_url, download: 'trigger' %>
</li>
<% end %>
<% if document.download_types.present? %>
<% document.download_types.each do |type| %>
<%= content_tag(:li) do %>
<% link_to(download_text(type[0]), '', data: { download_path: "#{download_path(document.id, type: type[0])}", download: 'trigger', download_type: type[0], download_id: document.id }) %>
<% end %>
<% end %>
<% end %>
<% end %>
</ul>
<%= render 'downloads_primary' %>
<%= render 'downloads_secondary' %>
</div>
<% elsif document.restricted? && document.same_institution? %>
<div class='panel-body'>
Expand Down
14 changes: 14 additions & 0 deletions app/views/catalog/_downloads_primary.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%# Renders the primary download that is shown first %>
<% document ||= @document %>
<% if document.direct_download.present? %>
<%= link_to(download_text(document.file_format), document.direct_download[:download], class: 'btn btn-default', 'contentUrl' => document.direct_download[:download], data: { download: 'trigger', download_type: 'direct', download_id: document.id }) %>
<% elsif document.hgl_download.present? %>
<%= link_to(download_text(document.download_types.first[0]),
download_hgl_path(id: document), data: {ajax_modal: 'trigger', download: 'trigger', download_type: 'harvard-hgl', download_id: document.id },
class: 'btn btn-default') %>
<% elsif document.iiif_download.present? %>
<%= link_to "Download JPG", iiif_jpg_url, class: 'btn btn-default', download: 'trigger' %>
<% else %>
<%= link_to(download_text(document.download_types.first[0]), '', data: { download_path: "#{download_path(document.id, type: document.download_types.first[0])}", download: 'trigger', download_type: document.download_types.first[0], download_id: document.id }, class: 'btn btn-default') %>
<% end %>
39 changes: 39 additions & 0 deletions app/views/catalog/_downloads_secondary.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<%# Renders the secondary downloads displayed in the split dropdown %>
<% document ||= @document %>

<button type='button' class='btn btn-default dropdown-toggle download-dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
<span class='caret'></span>
<span class='sr-only'>Toggle Download Dropdown</span>
</button>
<ul class='dropdown-menu' role='menu'>
<% if document.hgl_download.present? %>
<li role="presentation" class="dropdown-header">Original</li>
<li>
<%= link_to(download_text(document.download_types.first[0]),
download_hgl_path(id: document), data: {ajax_modal: 'trigger', download: 'trigger', download_type: 'harvard-hgl', download_id: document.id }) %>
</li>
<% else %>
<% if document.direct_download.present? %>
<li role="presentation" class="dropdown-header">Original</li>
<li>
<%= link_to(download_text(@document.file_format), document.direct_download[:download], 'contentUrl' => document.direct_download[:download], data: { download: 'trigger', download_type: 'direct', download_id: document.id }) %>
</li>
<% end %>
<% if document.download_types.present? || document.iiif_download.present? %>
<li role="presentation" class="dropdown-header">Generated</li>
<% end %>
<% if document.iiif_download.present? %>
<li>
<%= link_to "Download JPG", iiif_jpg_url, download: 'trigger' %>
</li>
<% end %>
<% if document.download_types.present? %>
<% document.download_types.each do |type| %>
<%= content_tag(:li) do %>
<% link_to(download_text(type[0]), '', data: { download_path: "#{download_path(document.id, type: type[0])}", download: 'trigger', download_type: type[0], download_id: document.id }) %>
<% end %>
<% end %>
<% end %>
<% end %>
</ul>
29 changes: 29 additions & 0 deletions spec/views/catalog/_downloads.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe 'catalog/_downloads.html.erb', type: :view do
context 'document is downloadable' do
it 'renders the button group with primary and secondary partials' do
expect(view).to receive(:document_downloadable?).and_return(true)
stub_template 'catalog/_downloads_primary.html.erb' => 'stubbed_primary_downloads'
stub_template 'catalog/_downloads_secondary.html.erb' => 'stubbed_secondary_downloads'
render
expect(rendered).to have_css '.btn-group'
expect(rendered).to have_content 'stubbed_primary_downloads'
expect(rendered).to have_content 'stubbed_secondary_downloads'
end
end
context 'document is not downloadable' do
let(:document) { double('document', restricted?: true, same_institution?: true) }
before(:each) do
expect(view).to receive(:document_downloadable?).and_return(false)
end

context 'when restricted & same institution' do
it 'renders login link' do
assign :document, document
render
expect(rendered).to have_css '.panel-body a'
end
end
end
end

0 comments on commit e9c58bb

Please sign in to comment.