Skip to content

Commit

Permalink
adds generated JPG download functionality
Browse files Browse the repository at this point in the history
whenever IIIF endpoint present in references; bypasses download
controller to avoid caching
  • Loading branch information
sgbalogh committed Feb 16, 2016
1 parent 2800ce1 commit c23f503
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/helpers/geoblacklight_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def document_downloadable?
document_available? && @document.downloadable?
end

def iiif_jpg_url
@document.references.iiif.endpoint.sub! 'info.json', 'full/full/0/default.jpg'
end

def snippit(text)
if text
if text.length > 150
Expand Down
6 changes: 5 additions & 1 deletion app/models/concerns/geoblacklight/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def restricted?
end

def downloadable?
(direct_download || download_types.present?) && available?
(direct_download || download_types.present? || iiif_download) && available?
end

def references
Expand All @@ -43,6 +43,10 @@ def same_institution?
fetch(:dct_provenance_s).downcase == Settings.INSTITUTION.downcase
end

def iiif_download
return references.iiif.to_hash unless references.iiif.blank?
end

def item_viewer
ItemViewer.new(references)
end
Expand Down
12 changes: 11 additions & 1 deletion app/views/catalog/_downloads.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<%= 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[:layer_slug_s] },
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[:layer_slug_s], type: document.download_types.first[0])}", download: 'trigger', download_type: document.download_types.first[0], download_id: document[:layer_slug_s] }, class: 'btn btn-default') %>
<% end %>
Expand All @@ -29,8 +31,16 @@
<%= link_to(download_text(@document[:dc_format_s]), document.direct_download[:download], 'contentUrl' => document.direct_download[:download], data: { download: 'trigger', download_type: 'direct', download_id: document[:layer_slug_s] }) %>
</li>
<% end %>
<% if document.download_types.present? %>
<% 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[:layer_slug_s], type: type[0])}", download: 'trigger', download_type: type[0], download_id: document[:layer_slug_s] }) %>
Expand Down
1 change: 1 addition & 0 deletions config/locales/geoblacklight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ en:
references:
wms: 'Web Mapping Service (WMS)'
wfs: 'Web Feature Service (WFS)'
iiif: 'International Image Interoperability Framework (IIIF)'
iso19139: 'ISO 19139'
mods: 'MODS'
fgdc: 'FGDC'
Expand Down
1 change: 1 addition & 0 deletions lib/generators/geoblacklight/templates/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TIMEOUT_WMS: 4
WEBSERVICES_SHOWN:
- 'wms'
- 'wfs'
- 'iiif'
- 'feature_layer'
- 'tiled_map_layer'
- 'dynamic_map_layer'
Expand Down
8 changes: 8 additions & 0 deletions spec/features/download_layer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
find('a', text: 'Download KMZ').click
expect(page).to have_css('a', text: 'Your file mit-us-ma-e25zcta5dct-2000-kmz.kmz is ready for download')
end
scenario 'jpg download option should be present under toggle' do
visit catalog_path('princeton-02870w62c')
expect(page).to have_css('li a', text: 'Download JPG')
end
scenario 'clicking jpg download button should redirect to external image' do
visit catalog_path('princeton-02870w62c')
expect(page).to have_css("a.btn.btn-default[href='http://libimages.princeton.edu/loris2/pudl0076%2Fmap_pownall%2F00000001.jp2/full/full/0/default.jpg']", text: 'Download JPG')
end
scenario 'options should be available under toggle' do
visit catalog_path('mit-us-ma-e25zcta5dct-2000')
find('button.download-dropdown-toggle').click
Expand Down
17 changes: 17 additions & 0 deletions spec/helpers/geoblacklight_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@
expect(geoblacklight_basemap).to eq 'positron'
end
end

describe '#iiif_jpg_url' do
let(:document) { SolrDocument.new(document_attributes) }
let(:document_attributes) do
{
dct_references_s: {
'http://iiif.io/api/image' => 'https://example.edu/image/info.json'
}.to_json
}
end

it 'returns JPG download URL when given URL to a IIIF info.json' do
assign(:document, document)
expect(helper.iiif_jpg_url).to eq 'https://example.edu/image/full/full/0/default.jpg'
end
end

describe '#render_web_services' do
let(:reference) { double(type: 'wms') }
it 'with a reference to a defined partial' do
Expand Down
20 changes: 20 additions & 0 deletions spec/models/concerns/geoblacklight/solr_document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@
end
end
end
describe 'iiif_download' do
describe 'with a IIIF download' do
let(:document_attributes) do
{
dct_references_s: {
'http://iiif.io/api/image' => 'https://example.edu/images/info.json'
}.to_json
}
end
it 'returns a IIIF download hash' do
expect(document.iiif_download[:iiif]).to eq('https://example.edu/images/info.json')
end
end
describe 'without a IIIF download' do
let(:document_attributes) { {} }
it 'returns nil' do
expect(document.iiif_download).to be_nil
end
end
end
describe 'item_viewer' do
let(:document_attributes) { {} }
it 'is a ItemViewer' do
Expand Down

0 comments on commit c23f503

Please sign in to comment.