-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For applications that have already installed IiifPrint, you'll need to manually add the following to your `config/routes.rb` file: ```ruby mount IiifPrint::Engine, at: '/' ``` Related to: - #292 - #294 Co-authored-by: LaRita Robinson <[email protected]>
- Loading branch information
Showing
8 changed files
with
123 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module IiifPrint | ||
# Responsible for coordinating the request to resplit a PDF. | ||
class SplitPdfsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def create | ||
@file_set = FileSet.where(id: params[:file_set_id]).first | ||
authorize_create_split_request!(@file_set) | ||
IiifPrint::Jobs::RequestSplitPdfJob.perform_later(file_set: @file_set, user: current_user) | ||
respond_to do |wants| | ||
wants.html { redirect_to polymorphic_path([main_app, @file_set]), flash: t("iiif_print.file_set.split_submitted", id: @file_set.id) } | ||
wants.json { render json: { id: @file_set.id, to_param: @file_set.to_param }, status: :ok } | ||
end | ||
end | ||
|
||
private | ||
|
||
## | ||
# @param file_set [FileSet] | ||
def authorize_create_split_request!(file_set) | ||
# NOTE: Duplicates logic of Hyrax: https://github.com/samvera/hyrax/blob/b334e186e77691d7da8ed59ff27f091be1c2a700/app/controllers/hyrax/file_sets_controller.rb#L234-L241 | ||
# | ||
# Namely if we don't have a file_set we need not proceed. | ||
raise CanCan::AccessDenied unless file_set | ||
|
||
## | ||
# Rely on CanCan's authorize! method. We could add the :split_pdf action to the ability | ||
# class. But we're pigging backing on the idea that you can do this if you can edit the work. | ||
authorize!(:edit, file_set) | ||
raise "Expected #{file_set.class} ID=#{file_set.id} #to_param=#{file_set.to_param} to be a PDF. Instead found mime_type of #{file_set.mime_type}." unless file_set.pdf? | ||
|
||
work = IiifPrint.parent_for(file_set) | ||
raise WorkNotConfiguredToSplitFileSetError.new(file_set: file_set, work: work) unless work&.iiif_print_config&.pdf_splitter_job&.presence | ||
|
||
true | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<div class="form-actions"> | ||
<% if Hyrax.config.analytics? %> | ||
<% # turbolinks needs to be turned off or the page will use the cache and the %> | ||
<% # analytics graph will not show unless the page is refreshed. %> | ||
<%= link_to t('.analytics'), @presenter.stats_path, id: 'stats', class: 'btn btn-default', data: { turbolinks: false } %> | ||
<% end %> | ||
<% if @presenter.editor? && !workflow_restriction?(@presenter) %> | ||
<%= link_to t(".edit_this", type: @presenter.human_readable_type), edit_polymorphic_path([main_app, @presenter]), | ||
class: 'btn btn-default' %> | ||
<%= link_to t(".delete_this", type: @presenter.human_readable_type), [main_app, @presenter], | ||
class: 'btn btn-danger', data: { confirm: t(".confirm_delete_this", type: @presenter.human_readable_type) }, | ||
method: :delete %> | ||
<% end %> | ||
|
||
<% if @presenter.editor? && @presenter.pdf? %> | ||
<%= link_to t("iiif_print.file_set.split_this"), split_pdf_path(@presenter), | ||
class: 'btn btn-default', data: { confirm: t("iiif_print.file_set.confirm_split_this") }, | ||
method: :post %> | ||
<% end %> | ||
|
||
<%= render 'social_media' %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
IiifPrint::Engine.routes.draw do | ||
post "split_pdfs/:file_set_id" => "split_pdfs#create", as: :split_pdf | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module IiifPrint | ||
module Jobs | ||
## | ||
# Encapsulates logic for cleanup when the PDF is destroyed after pdf splitting into child works | ||
class RequestSplitPdfJob < IiifPrint::Jobs::ApplicationJob | ||
## | ||
# @param file_set [FileSet] | ||
# @param user [User] | ||
# rubocop:disable Metrics/MethodLength | ||
def perform(file_set:, user:) | ||
return true if file_set.pdf? | ||
|
||
work = IiifPrint.parent_for(file_set) | ||
|
||
# Woe is ye who changes the configuration of the model, thus removing the splitting. | ||
raise WorkNotConfiguredToSplitFileSetError.new(work: work, file_set: file_set) unless work&.iiif_print_config&.pdf_splitter_job&.presence | ||
|
||
# clean up any existing spawned child works of this file_set | ||
IiifPrint::SplitPdfs::DestroyPdfChildWorksService.conditionally_destroy_spawned_children_of( | ||
file_set: file_set, | ||
work: work | ||
) | ||
|
||
location = Hyrax::WorkingDirectory.find_or_retrieve(file_set.files.first.id, file_set.id) | ||
|
||
# submit a job to split pdf into child works | ||
work.iiif_print_config.pdf_splitter_job.perform_later( | ||
file_set, | ||
[location], | ||
user, | ||
work.admin_set_id, | ||
0 # A no longer used parameter; but we need to preserve the method signature (for now) | ||
) | ||
end | ||
# rubocop:enable Metrics/MethodLength | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.