diff --git a/Gemfile b/Gemfile index 1eddd7b5..ef3a9e0d 100644 --- a/Gemfile +++ b/Gemfile @@ -146,3 +146,5 @@ gem 'iiif_print', git: 'https://github.com/scientist-softserv/iiif_print.git', b gem 'order_already' gem 'redis', '~> 4.0' gem 'redlock', '~> 1.2.1' +# locking to 5.1.0 because it was throwing errors on 5.3.0 in development +gem 'simple_form', '5.1.0' diff --git a/Gemfile.lock b/Gemfile.lock index 756d4b4b..a09ae49f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1035,7 +1035,7 @@ GEM faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - simple_form (5.3.0) + simple_form (5.1.0) actionpack (>= 5.2) activemodel (>= 5.2) simplecov (0.16.1) @@ -1225,6 +1225,7 @@ DEPENDENCIES secure_headers selenium-webdriver sentry-raven + simple_form (= 5.1.0) simplecov solr_wrapper (~> 2.0) spring (~> 1.7) diff --git a/app/helpers/pdf_js_helper.rb b/app/helpers/pdf_js_helper.rb index 653ee81d..29e50f68 100644 --- a/app/helpers/pdf_js_helper.rb +++ b/app/helpers/pdf_js_helper.rb @@ -3,13 +3,13 @@ module PdfJsHelper def pdf_js_url(file_set_presenter) # assumes that the download path exists if the file set has been characterized - path = if file_set_presenter.mime_type - hyrax.download_path(file_set_presenter.id) - else - file_set_presenter.solr_document["import_url_ssim"].first - end + url = if file_set_presenter.mime_type + "/pdf.js/web/viewer.html?file=#{hyrax.download_path(file_set_presenter.id)}" + else + file_set_presenter.solr_document["import_url_ssim"].first + end - "/pdf.js/web/viewer.html?file=#{path}##{query_param}" + url + "##{query_param}" end def pdf_file_set_presenter(presenter) @@ -18,18 +18,23 @@ def pdf_file_set_presenter(presenter) # Commenting this line out because even PDFs that were not split will still have a representative media # which will be used first in this logic, consider uncommenting once all imports finish # representative_presenter(presenter) || - first_file_set_pdf(presenter) + external_pdf(presenter) end - def first_file_set_pdf(presenter) - pdf_file_set_presenters = presenter.file_set_presenters.select(&:pdf?) - reader, archival = pdf_file_set_presenters.partition do |fsp| + def external_pdf(presenter) + reader, archival = pdf_file_set_presenters(presenter.file_set_presenters).partition do |fsp| fsp.solr_document["import_url_ssim"]&.first&.include? "READER" end reader.first || archival.first end + def pdf_file_set_presenters(presenters) + presenters.select(&:pdf?).presence || presenters.select do |file_set_presenter| + file_set_presenter.solr_document["label_ssi"].downcase.end_with? ".pdf" + end + end + def representative_presenter(presenter) presenter.file_set_presenters.find { |file_set_presenter| file_set_presenter.id == presenter.representative_id } end diff --git a/app/presenters/hyku/work_show_presenter.rb b/app/presenters/hyku/work_show_presenter.rb index 5b631f9a..daaf34d6 100644 --- a/app/presenters/hyku/work_show_presenter.rb +++ b/app/presenters/hyku/work_show_presenter.rb @@ -31,13 +31,17 @@ def video_embed_viewer def pdf_viewer? return unless Flipflop.default_pdf_viewer? - return unless file_set_presenters.any?(&:pdf?) + return unless file_set_presenters.any?(&:pdf?) || pdf_extension? # If all of the member_presenters are file_set presenters, return true # this also means that there are no child works member_presenters.all? { |presenter| presenter.is_a? Hyrax::FileSetPresenter } end + def pdf_extension? + file_set_presenters.any? { |fsp| fsp.label.downcase.end_with?('.pdf') } + end + def viewer? iiif_viewer? || video_embed_viewer? || pdf_viewer? end