This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
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.
Merge pull request #669 from scientist-softserv/i667-install-pdfjs
I667 install pdfjs
- Loading branch information
Showing
207 changed files
with
126,539 additions
and
8 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
19 changes: 19 additions & 0 deletions
19
app/controllers/flipflop/strategies_controller_decorator.rb
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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
# OVERRIDE Flipflop v2.7.1 to allow for custom `Action` labels | ||
|
||
module Flipflop | ||
module StrategiesControllerDecorator | ||
def enable? | ||
values = StrategiesController::ENABLE_VALUES | ADDITIONAL_ENABLE_VALUES | ||
values.include?(params[:commit]) | ||
end | ||
|
||
def features_url(**_kargs) | ||
hyrax.admin_features_path | ||
end | ||
ADDITIONAL_ENABLE_VALUES = FeaturesHelper::FEATURE_ACTION_LABELS.map { |_, v| v[:on] }.to_set.freeze | ||
end | ||
end | ||
|
||
Flipflop::StrategiesController.prepend(Flipflop::StrategiesControllerDecorator) |
15 changes: 15 additions & 0 deletions
15
app/controllers/hyrax/admin/strategies_controller_decorator.rb
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,15 @@ | ||
# frozen_string_literal: true | ||
|
||
# OVERRIDE Hyrax 2.9.6 to support Flipflop 2.7.1 features | ||
|
||
module Hyrax | ||
module Admin | ||
module StrategiesControllerDecorator | ||
def features_url(**_kargs) | ||
hyrax.admin_features_path | ||
end | ||
end | ||
end | ||
end | ||
|
||
Hyrax::Admin::StrategiesController.prepend(Hyrax::Admin::StrategiesControllerDecorator) |
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 FeaturesHelper | ||
def status_for(feature) | ||
status = @feature_set.status(feature) | ||
label = @feature_set.status(feature) == :enabled ? :on : :off | ||
FEATURE_ACTION_LABELS.fetch(feature.name.to_sym, label => status)[label] | ||
end | ||
|
||
def on(feature) | ||
FEATURE_ACTION_LABELS[feature]&.[](:on) || 'on' | ||
end | ||
|
||
def off(feature) | ||
FEATURE_ACTION_LABELS[feature]&.[](:off) || 'off' | ||
end | ||
|
||
FEATURE_ACTION_LABELS = { | ||
default_pdf_viewer: { on: 'PDF.js', off: 'UV' } | ||
}.freeze | ||
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,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module PdfJsHelper | ||
def pdf_js_url(file_set_presenter) | ||
# assumes that the download path exists if the file set has been characterized | ||
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 | ||
|
||
url + "##{query_param}" | ||
end | ||
|
||
def pdf_file_set_presenter(presenter) | ||
# currently only supports one pdf per work, falls back to the first pdf file set in ordered members | ||
|
||
# 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) || | ||
external_pdf(presenter) | ||
end | ||
|
||
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 | ||
|
||
def query_param | ||
search_params = current_search_session.try(:query_params) || {} | ||
q = search_params['q'].presence || '' | ||
|
||
"search=#{q}&phrase=true" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# OVERRIDE Hyrax 3.5.0 to add PDF text to solr document when using the default PDF viewer (PDF.js) | ||
|
||
module Hyrax | ||
module FileSetIndexerDecorator | ||
def generate_solr_document | ||
return super unless Flipflop.default_pdf_viewer? | ||
|
||
super.tap do |solr_doc| | ||
solr_doc['all_text_timv'] = solr_doc['all_text_tsimv'] = pdf_text | ||
end | ||
end | ||
|
||
private | ||
|
||
def pdf_text | ||
return unless object.pdf? | ||
return unless object.original_file&.content.is_a? String | ||
|
||
text = IO.popen(['pdftotext', '-', '-'], 'r+b') do |pdftotext| | ||
pdftotext.write(object.original_file.content) | ||
pdftotext.close_write | ||
pdftotext.read | ||
end | ||
|
||
text.tr("\n", ' ') | ||
.squeeze(' ') | ||
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') # remove non-UTF-8 characters | ||
end | ||
end | ||
end | ||
|
||
Hyrax::FileSetIndexer.prepend(Hyrax::FileSetIndexerDecorator) |
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,76 @@ | ||
<% | ||
# OVERRIDE Hyrax 2.9.6 to make the default PDF viewer switch more intuitive and some styling changes. | ||
# Instead of saying on/off it says PDF.js/IIIF Print. | ||
%> | ||
|
||
<% provide :page_header do %> | ||
<h1><span class="fa fa-wrench" aria-hidden="true"></span> <%= t('.header') %></h1> | ||
<% end %> | ||
<div class="flip row"> | ||
<div class="col-md-12"> | ||
<div class="panel"> | ||
<div class="panel-body"> | ||
<div class="table-responsive"> | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th class="name"><%= t('.feature') %></th> | ||
<th class="description"><%= t('.description') %></th> | ||
<th class="action"><%= t('.action') %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @feature_set.grouped_features.each do |group, features| -%> | ||
<% if @feature_set.grouped? -%> | ||
<tr class="group"> | ||
<td></td> | ||
<td class="name" colspan="<%= 2 + @feature_set.strategies.size -%>"> | ||
<h2> | ||
<%= t(group ? group.name : :default, scope: [:flipflop, :groups], default: group ? group.title : nil) -%> | ||
</h2> | ||
</td> | ||
</tr> | ||
<% end -%> | ||
<% features.each do |feature| %> | ||
<tr data-feature="<%= feature.name.dasherize.parameterize %>"> | ||
<td class="status"> | ||
<span class="<%= @feature_set.status(feature) -%>"><%= status_for(feature) -%></span> | ||
</td> | ||
<td class="name"><%= feature.name.humanize -%></td> | ||
<td class="description"><%= feature.description -%></td> | ||
|
||
<% @feature_set.strategies.each do |strategy| -%> | ||
<% next unless strategy.is_a? Flipflop::Strategies::ActiveRecordStrategy %> | ||
<%# OVERRIDE to add min-width so Actions column can display all toggles on the same line %> | ||
<%# adjust min-width as needed for future overrides %> | ||
<td class="toggle" style="min-width: 110px;" data-strategy="<%= strategy.name.dasherize.parameterize %>"> | ||
<div class="toolbar"> | ||
<%= form_tag(hyrax.admin_feature_strategy_path(feature.key, strategy.key), method: :put) do -%> | ||
<div class="btn-group"> | ||
<%# OVERRIDE to use helper, see FeaturesHelper %> | ||
<%= submit_tag on(feature.name.to_sym), | ||
type: "submit", | ||
class: Flipflop.enabled?(feature.name.to_sym) ? 'active' : nil, | ||
disabled: !strategy.switchable? -%> | ||
|
||
<%# OVERRIDE to use helper, see FeaturesHelper %> | ||
<%= submit_tag off(feature.name.to_sym), | ||
type: "submit", | ||
class: Flipflop.enabled?(feature.name.to_sym) ? nil : 'active', | ||
disabled: !strategy.switchable? -%> | ||
</div> | ||
<% end -%> | ||
</div> | ||
</td> | ||
<% end -%> | ||
</tr> | ||
<% end -%> | ||
<% end -%> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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,7 @@ | ||
<div class="viewer-wrapper"> | ||
<iframe id="pdf-viewer" aria-label="image view" | ||
src="<%= pdf_js_url(file_set_presenter) %>" | ||
allowfullscreen="true" | ||
frameborder="0" | ||
></iframe> | ||
</div> |
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
Oops, something went wrong.