-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎁 Add toggle for pdf viewer and download button
This commit will add two properties for all work types to allow for the pdf viewer and download button to be toggled on and off on the work show page. These two options will exist on the forms for each work type on the files tab. This will also hide the default download button on PDF.js so the users can only download from the newly introduced download button.
- Loading branch information
Showing
25 changed files
with
298 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
module PdfFormBehavior | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
class_attribute :hidden_terms | ||
|
||
self.terms += %i[show_pdf_viewer show_pdf_download_button] | ||
self.hidden_terms = %i[show_pdf_viewer show_pdf_download_button] | ||
# Not sure why this is needed but the form was not working without it | ||
# it was getting a Unpermitted parameter error for these terms | ||
permitted_params << %i[show_pdf_viewer show_pdf_download_button] | ||
end | ||
|
||
def hidden?(key) | ||
hidden_terms.include? key.to_sym | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module RDF | ||
class CustomShowPdfViewerTerm < Vocabulary('http://id.loc.gov/vocabulary/identifiers/') | ||
property 'show_pdf_viewer' | ||
end | ||
|
||
class CustomShowPdfDownloadButtonTerm < Vocabulary('http://id.loc.gov/vocabulary/identifiers/') | ||
property 'show_pdf_download_button' | ||
end | ||
end | ||
|
||
module PdfBehavior | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
property :show_pdf_viewer, predicate: RDF::CustomShowPdfViewerTerm.show_pdf_viewer, multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
property :show_pdf_download_button, | ||
predicate: RDF::CustomShowPdfDownloadButtonTerm.show_pdf_download_button, | ||
multiple: false do |index| | ||
index.as :stored_searchable | ||
end | ||
|
||
after_initialize :set_default_show_pdf_viewer, :set_default_show_pdf_download_button | ||
end | ||
|
||
private | ||
|
||
# This is here so that the checkbox is checked by default | ||
def set_default_show_pdf_viewer | ||
self.show_pdf_viewer ||= '1' | ||
end | ||
|
||
def set_default_show_pdf_download_button | ||
self.show_pdf_download_button ||= '1' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<% if can?(:download, file_set_id) && (Site.account.settings[:allow_downloads].nil? || Site.account.settings[:allow_downloads].to_i.nonzero?) %> | ||
<div class="download-pdf-controls"> | ||
<% if @presenter.representative_presenter.present? && presenter.file_set_presenters.any?(&:pdf?) %> | ||
<%= button_tag type: 'button', | ||
id: "download-pdf-button", | ||
data: { label: @presenter.representative_presenter.id, | ||
path: hyrax.download_path(presenter.representative_presenter) }, | ||
class: "btn btn-success btn-block download-pdf-button center-block", | ||
onclick: "window.open(this.dataset.path, '_blank');" do %> | ||
Download PDF | ||
<% end %> | ||
<% end %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<%# OVERRIDE HYRAX 3.5.0 to add show_pdf_viewer to files tab %> | ||
<%# OVERRIDE begin %> | ||
<% if render_show_pdf_behavior_checkbox? %> | ||
<%= render partial: 'show_pdf_viewer', locals: { f: f } %> | ||
<%= render partial: 'show_pdf_download_button', locals: { f: f } %> | ||
<% end %> | ||
<%# OVERRIDE end %> | ||
<div id="fileupload"> | ||
<!-- Redirect browsers with JavaScript disabled to the origin page --> | ||
<noscript><input type="hidden" name="redirect" value="<%= main_app.root_path %>" /></noscript> | ||
<!-- The table listing the files available for upload/download --> | ||
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table> | ||
<% if Hyrax.config.browse_everything? %> | ||
<%= t('hyrax.base.form_files.local_upload_browse_everything_html', contact_href: link_to(t("hyrax.upload.alert.contact_href_text"), hyrax.contact_form_index_path)) %> | ||
<% else %> | ||
<%= t('hyrax.base.form_files.local_upload_html') %> | ||
<% end %> | ||
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload --> | ||
<div class="fileupload-buttonbar"> | ||
<div class="row"> | ||
<div class="col-xs-12"> | ||
<div class="fileinput-button" id="add-files"> | ||
<input id="addfiles" type="file" style="display:none;" name="files[]" multiple /> | ||
<button type="button" class="btn btn-success" onclick="document.getElementById('addfiles').click();"> | ||
<span class="glyphicon glyphicon-plus"></span> | ||
<span><%= t(".add_files") %></span> | ||
</button> | ||
</div> | ||
<div class="fileinput-button"> | ||
<input id="addfolder" type="file" style="display:none;" name="files[]" multiple directory webkitdirectory /> | ||
<button type="button" class="btn btn-success" onclick="document.getElementById('addfolder').click();"> | ||
<span class="glyphicon glyphicon-plus"></span> | ||
<span><%= t(".add_folder") %></span> | ||
</button> | ||
</div> | ||
<% if Hyrax.config.browse_everything? %> | ||
<%= button_tag(type: 'button', class: 'btn btn-success', id: "browse-btn", | ||
'data-toggle' => 'browse-everything', 'data-route' => browse_everything_engine.root_path, | ||
'data-target' => "#{f.object.persisted? ? "#edit_#{f.object.model.model_name.param_key}_#{f.object.model.id}" : "#new_#{f.object.model.model_name.param_key}"}" ) do %> | ||
<span class="glyphicon glyphicon-plus"></span> | ||
<%= t('hyrax.upload.browse_everything.browse_files_button') %> | ||
<% end %> | ||
<% end %> | ||
<button type="reset" id="file-upload-cancel-btn" class="btn btn-warning cancel hidden"> | ||
<span class="glyphicon glyphicon-ban-circle"></span> | ||
<span><%= t('.cancel_upload') %></span> | ||
</button> | ||
<!-- The global file processing state --> | ||
<span class="fileupload-process"></span> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-xs-12"> | ||
<!-- The global progress state --> | ||
<div class="fileupload-progress fade"> | ||
<!-- The global progress bar --> | ||
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100"> | ||
<div class="progress-bar progress-bar-success" style="width:0%;"></div> | ||
</div> | ||
<!-- The extended global progress state --> | ||
<div class="progress-extended"> </div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="dropzone"> | ||
<%= t('hyrax.base.form_files.dropzone') %> | ||
</div> | ||
</div> | ||
|
||
<%= render 'hyrax/uploads/js_templates' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%# OVERRIDE: Hyrax 3.5.0 to add support for PDF.js %> | ||
<% if presenter.representative_id.present? && presenter.representative_presenter.present? %> | ||
<% if defined?(viewer) && viewer && presenter.iiif_viewer?%> | ||
<%= iiif_viewer_display presenter %> | ||
<% elsif presenter.pdf_viewer? %> | ||
<%= render 'pdf_js', file_set_presenter: pdf_file_set_presenter(@presenter) %> | ||
<% else %> | ||
<%= render media_display_partial(presenter.representative_presenter), file_set: presenter.representative_presenter %> | ||
<% end %> | ||
<% else %> | ||
<% alt = block_for(name: 'default_work_image_text') || 'Default work thumbnail' %> | ||
<%= image_tag default_work_image, class: "canonical-image", alt: alt %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= f.input :show_pdf_download_button, | ||
label: "Show Download PDF button", | ||
required: f.object.required?(:show_pdf_download_button), | ||
as: :boolean %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%= f.input :show_pdf_viewer, | ||
label: "Show PDF.js Viewer", | ||
required: f.object.required?(:show_pdf_viewer), | ||
as: :boolean %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<%# Overridden from Hyrax 3.5.0 - To add extra download restrictions %> | ||
<% if (can?(:download, file_set.id) || can?(:destroy, file_set.id) || can?(:edit, file_set.id)) && !workflow_restriction?(@parent) %> | ||
<% if can?(:download, file_set.id) && !(can?(:edit, file_set.id) || can?(:destroy, file_set.id)) %> | ||
<% if (Site.account.settings[:allow_downloads].nil? || Site.account.settings[:allow_downloads].to_i.nonzero?) && | ||
(@presenter.show_pdf_download_button? && file_set.pdf? || !file_set.pdf?) %> | ||
<%= link_to t('.download'), | ||
hyrax.download_path(file_set), | ||
class: 'btn btn-default btn-sm', | ||
title: t('.download_title', file_set: file_set), | ||
target: "_blank", | ||
id: "file_download", | ||
data: { label: file_set.id, work_id: @presenter.id, collection_ids: @presenter.member_of_collection_ids } %> | ||
<% end %> | ||
<% else %> | ||
<div class="btn-group"> | ||
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button" id="dropdownMenu_<%= file_set.id %>" aria-haspopup="true" aria-expanded="false"> | ||
<span class="sr-only"><%= t('.press_to') %> </span> | ||
<%= t('.header') %> | ||
<span class="caret" aria-hidden="true"></span> | ||
</button> | ||
|
||
<ul role="menu" class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu_<%= file_set.id %>"> | ||
<% if can?(:edit, file_set.id) %> | ||
<li role="menuitem" tabindex="-1"> | ||
<%= link_to t('.edit'), edit_polymorphic_path([main_app, file_set]), | ||
{ title: t('.edit_title', file_set: file_set) } %> | ||
</li> | ||
|
||
<li role="menuitem" tabindex="-1"> | ||
<%= link_to t('.versions'), edit_polymorphic_path([main_app, file_set], anchor: 'versioning_display'), | ||
{ title: t('.versions_title') } %> | ||
</li> | ||
<% end %> | ||
<% if can?(:destroy, file_set.id) %> | ||
<li role="menuitem" tabindex="-1"> | ||
<%= link_to t('.delete'), polymorphic_path([main_app, file_set]), | ||
method: :delete, title: t('.delete_title', file_set: file_set), | ||
data: { confirm: t('.delete_confirm', file_set: file_set, application_name: application_name) } %> | ||
</li> | ||
<% end %> | ||
<% if can?(:download, file_set.id) && (Site.account.settings[:allow_downloads].nil? || Site.account.settings[:allow_downloads].to_i.nonzero?) %> | ||
<li role="menuitem" tabindex="-1"> | ||
<%= link_to t('.download'), | ||
hyrax.download_path(file_set), | ||
title: t('.download_title', file_set: file_set), | ||
target: "_blank", | ||
id: "file_download", | ||
class: "download", | ||
data: { label: file_set.id, work_id: @presenter.id, collection_ids: @presenter.member_of_collection_ids } %> | ||
</li> | ||
<% end %> | ||
|
||
</ul> | ||
</div> | ||
<% end %> | ||
<% end %> |
Oops, something went wrong.