a11yist/app/models/pdf_documents/customer_report.rb

168 lines
5.7 KiB
Ruby
Raw Normal View History

2024-09-05 22:54:38 +02:00
# frozen_string_literal: true
2024-07-21 02:57:13 +02:00
module PdfDocuments
class CustomerReport < Base
private
def generate
2024-11-24 03:16:36 +01:00
move_down 130
logo(width: 250, xs: false)
move_down 40
2024-07-22 01:29:09 +02:00
heading1 params.report.name
2024-11-24 03:16:36 +01:00
move_down 20
@prawn_document.text "#{I18n.l params.report.updated_at.to_date, format: :long}"
move_down 40
safe_display(params.report.comment) do
rich_text _1
move_down 30
end
@prawn_document.font_size(8) do
@prawn_document.draw_text("Dokument erstellt am #{Time.current.strftime('%d %B %Y')} um #{Time.current.strftime('%H:%M:%S')}", at: [0, 0])
end
@prawn_document.start_new_page
2024-11-24 00:58:36 +01:00
@pages = {}
2024-07-22 01:29:09 +02:00
2024-11-23 21:11:01 +01:00
params.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
2024-11-24 00:58:36 +01:00
new_page(required_space: 200) if element_index > 1
2024-11-23 23:12:06 +01:00
without_page_break do
heading2 "#{element_index} #{element.title}"
2024-11-24 03:16:36 +01:00
@prawn_document.text("<b>Pfad:</b> #{element.page.path}", inline_format: true)
safe_display(element.screenshot) do
image(_1.variant(:thumbnail), height: 160)
move_down(15)
end
2024-11-23 23:12:06 +01:00
end
2024-11-23 21:11:01 +01:00
rich_text element.description
2024-11-23 23:12:06 +01:00
move_down(10)
2024-07-21 02:57:13 +02:00
2024-11-23 21:11:01 +01:00
success_criteria.each.with_index(1) do |success_criterion, sc_index|
2024-11-24 03:40:48 +01:00
@pages[success_criterion] = @prawn_document.page_number
2024-11-23 23:12:06 +01:00
success_criterion_row(success_criterion, [ element_index, sc_index ])
2024-07-21 02:57:13 +02:00
end
end
2024-11-24 03:16:36 +01:00
@prawn_document.start_new_page
heading1("Anhang: Richtlinien")
params.report.export[:success_criteria].group_by(&:check).sort_by{ |c, _scs| c.external_number }.each do |check, criteria|
heading2(check.display_label)
2024-11-24 03:40:48 +01:00
@pages[check] = @prawn_document.page_number
2024-11-24 03:16:36 +01:00
{
external_number: { label: "WCAG Nummer" },
external_url: { label: "WCAG Link" },
conformity_level: { label: "Konformität" },
conformity_notice_de: { label: "Anmerkung Konformität", rich: true },
priority: { label: "Priorität" },
criterion_de: { label: "Kriterium/Grundlage", rich: true },
exemption_details_de: { label: "Ausnahmen", rich: true },
criterion_details_de: { label: "Verstehen", rich: true },
example_de: { label: "Beispiel", rich: true },
annotation_de: { label: "Anmerkung", rich: true }
}.each do |attribute, options|
v = check.send(attribute)
safe_display(v) do
text("<b>#{options[:label]}</b>", inline_format: true)
if options[:rich]
rich_text(_1)
else
text(_1)
end
end
end
if check.links.any?
2024-11-24 03:40:48 +01:00
move_down 5
2024-11-24 03:16:36 +01:00
text("<b>Links</b>", inline_format: true)
2024-11-24 03:40:48 +01:00
move_down 5
2024-11-24 03:16:36 +01:00
check.links.group_by(&:link_category).each do |cat, links|
2024-11-24 03:40:48 +01:00
rich_text(%Q(
2024-11-24 11:03:44 +01:00
<span>#{cat.name}</span>
2024-11-24 03:16:36 +01:00
<ul>
2024-11-24 11:03:44 +01:00
#{links.map{ "<li><a href='#{_1.url}'>#{_1.text}</a></li>" }.join() }
2024-11-24 03:16:36 +01:00
</ul>
2024-11-24 03:40:48 +01:00
))
2024-11-24 03:16:36 +01:00
end
end
text("<b>Erfolgskriterien</b>", inline_format: true)
text criteria.map(&:number).sort.join(", ")
end
2024-11-24 00:58:36 +01:00
string = "Seite <page> / <total>"
# Green page numbers 1 to 7
options = {
2024-11-24 03:16:36 +01:00
at: [ @prawn_document.bounds.right - 150, 776 ],
2024-11-24 00:58:36 +01:00
width: 150,
align: :right,
2024-11-24 03:16:36 +01:00
start_count_at: 2,
page_filter: ->(x) { x > 1 }
2024-11-24 00:58:36 +01:00
}
@prawn_document.number_pages string, options
2024-11-24 03:16:36 +01:00
@prawn_document.repeat(2..) do
@prawn_document.text_box "<b>#{params.report.name}</b>", at: [ 50, 777 ], inline_format: true, width: 300
@prawn_document.bounding_box([0, 766], width: 532) do
hr
end
@prawn_document.bounding_box([0, 796], width: 200, height: 200) do
logo
end
end
2024-11-24 01:32:24 +01:00
2024-11-24 00:58:36 +01:00
x = params
p = @pages
@prawn_document.outline.define do
x.report.export[:elements].each.with_index(1) do |(element, success_criteria), element_index|
section("#{element_index} #{element.title}") do
success_criteria.each.with_index(1) do |sc, sc_index|
2024-11-24 03:40:48 +01:00
page(title: "#{element_index}.#{sc_index} #{sc.title}", destination: p[sc])
2024-11-24 00:58:36 +01:00
end
end
end
2024-11-24 03:40:48 +01:00
section("Anhang: Richtlinien") do
x.report.export[:success_criteria].group_by(&:check).sort_by{ |c, _scs| c.external_number }.each do |check, _criteria|
page(title: check.display_label, destination: p[check])
end
end
2024-11-24 00:58:36 +01:00
end
2024-07-21 02:57:13 +02:00
end
2024-11-23 21:11:01 +01:00
private
def success_criterion_row(success_criterion, index)
heading3 "#{index.join(".")} #{success_criterion.title}"
safe_display(success_criterion.test_comment) do
2024-11-23 23:12:06 +01:00
without_page_break do
heading4 "Kommentar"
rich_text success_criterion.test_comment
end
2024-11-23 21:11:01 +01:00
end
safe_display(success_criterion.quick_criterion) do
2024-11-23 23:12:06 +01:00
without_page_break do
heading4 "Kriterium"
rich_text success_criterion.quick_criterion
end
2024-11-23 21:11:01 +01:00
end
safe_display(success_criterion.quick_fail) do
2024-11-23 23:12:06 +01:00
without_page_break do
heading4 "Fail"
rich_text success_criterion.quick_fail
end
2024-11-23 21:11:01 +01:00
end
safe_display(success_criterion.quick_fix) do
2024-11-23 23:12:06 +01:00
without_page_break do
heading4 "Fix"
rich_text success_criterion.quick_fix
end
2024-11-23 21:11:01 +01:00
end
2024-11-23 23:12:06 +01:00
heading4("Protokollnummer")
text(success_criterion.number)
2024-11-24 11:03:44 +01:00
safe_display(success_criterion.check.external_url) do
heading4("WCAG")
text("<link href='#{_1}'>#{success_criterion.check.external_number || _1}</link>", inline_format: true)
end
2024-11-23 23:12:06 +01:00
move_down(10)
2024-11-23 21:11:01 +01:00
end
2024-07-21 02:57:13 +02:00
end
end