Skip to content

Commit

Permalink
Merge pull request #628 from CDLUC3/bug/pdf-formatting
Browse files Browse the repository at this point in the history
forgot to do the PR for this one before creating v5.18 👎🏻
  • Loading branch information
briri authored Jul 8, 2024
2 parents 5805294 + 1e39119 commit c6c3297
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/jobs/pdf_publisher_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def perform(obj:)
elsif obj.is_a?(Template)
@formatting = {
font_face: 'Tinos, serif',
font_size: '11',
font_size: '12',
margin: { top: '20', right: '20', bottom: '20', left: '20' }
}
@template = obj
Expand Down Expand Up @@ -131,8 +131,10 @@ def _prep_plan_for_pdf(plan:)
plan: plan,
public_plan: plan.publicly_visible?,
hash: plan.as_pdf(nil, true),
formatting: { font_face: 'Tinos, serif', font_size: '12' },
formatting: plan.settings(:export).formatting || plan.template.settings(:export).formatting,
selected_phase: plan.phases.order('phases.updated_at DESC').first
selected_phase: plan.phases.order('phases.updated_at DESC').first,
show_coversheet: true
}
end
# rubocop:enable Metrics/AbcSize
Expand Down
6 changes: 5 additions & 1 deletion app/views/branded/shared/export/pdf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
# This template is used by the PdfPublisherJob to generate the Plan's PDF so it can be sent to the DMPHub
@plan = plan
@show_coversheet = true
@show_sections_questions = true
# @show_sections_questions = true
@show_unanswered = true
@show_custom_sections = true

@show_sections = true
@show_questions = true

@show_research_outputs = plan.research_outputs.any?
@public_plan = plan.publicly_visible?
@hash = hash
Expand Down
33 changes: 33 additions & 0 deletions lib/tasks/v5.rake
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,38 @@ namespace :v5 do
end
p "done"
end

# If using AWS S3, this will generate PDF narrative documents for each public Plan and place it into the
# S3 bucket for faster retrieval. This is being done because bad bots have been crawling our public plans page
# and the auto-build PDF per-request model was crippling the servers.
#
# As public plans are updated, the PDF will be regenerated and replace the existing one in ActiveStorage
desc 'Create PDF narrative documents for all public plans so that they are downloadable from public plans page'
task rebuild_narratives: :environment do
puts 'This task MUST be run on a server because it needs access to S3!' if Rails.env.development?
return 1 if Rails.env.development?

pauser = 0
Plan.includes(:org, :funder, :grant, :answers,
roles: [user: [:org]],
template: [phases: [sections: [:questions]]],
contributors: [:org, :identifiers],
research_outputs: [:identifiers, :metadata_standards, :repositories, :license])
.where(visibility: Plan.visibilities[:publicly_visible])
.each do |plan|
next if plan.publisher_job_status == 'enqueued'

sleep 5 if pauser >= 10
p "Publishing PDF narrative to ActiveStorage for Plan #{plan.id} \"#{plan.title}\"."

# Don't retrigger all of the callbacks when just changing the status of the publisher job!
publisher_job_status = 'enqueued'
plan.save(touch: false)

PdfPublisherJob.perform_now(obj: plan)
pauser = pauser >= 11 ? 0 : (pauser += 1)
end
p "done"
end
end
# rubocop:enable Naming/VariableNumber
2 changes: 1 addition & 1 deletion public/tinymce/skins/oxide/content.inline.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/tinymce/skins/oxide/content.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/tinymce/skins/oxide/skin.js

Large diffs are not rendered by default.

0 comments on commit c6c3297

Please sign in to comment.