Merge pull request #5108 from betagouv/improve-pdf

PDF vide - Ajout de descriptions manquantes
This commit is contained in:
Keirua 2020-05-05 21:01:50 +02:00 committed by GitHub
commit 132cfcb6c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,9 +7,9 @@ def render_in_2_columns(pdf, label, text)
pdf.text "\n"
end
def format_in_2_lines(pdf, label, nb_lines = 1)
add_single_line(pdf, label, 12, :bold)
def format_in_2_lines(pdf, champ, nb_lines = 1)
add_single_line(pdf, champ.libelle, 12, :bold)
add_optionnal_description(pdf, champ)
height = 10 * (nb_lines+1)
pdf.bounding_box([0, pdf.cursor],:width => 460,:height => height) do
pdf.stroke_bounds
@ -89,37 +89,45 @@ def add_explanation(pdf, explanation)
add_single_line(pdf, explanation, 9, :italic)
end
def add_optionnal_description(pdf, champ)
add_explanation(pdf, champ.description.strip + "\n\n") if champ.description.present?
end
def render_single_champ(pdf, champ)
case champ.type
when 'Champs::RepetitionChamp'
raise 'There should not be a RepetitionChamp here !'
when 'Champs::PieceJustificativeChamp'
add_single_line(pdf, 'Pièce justificative à joindre', 12, :bold)
pdf.text champ.libelle
pdf.text champ.description
add_single_line(pdf, 'Pièce justificative à joindre en complément du dossier', 12, :bold)
format_with_checkbox(pdf, champ.libelle)
add_optionnal_description(pdf, champ)
pdf.text "\n"
when 'Champs::YesNoChamp', 'Champs::CheckboxChamp'
add_libelle(pdf, champ)
add_optionnal_description(pdf, champ)
add_explanation(pdf, 'Cochez la mention applicable')
format_with_checkbox(pdf, 'Oui')
format_with_checkbox(pdf, 'Non')
pdf.text "\n"
when 'Champs::CiviliteChamp'
add_libelle(pdf, champ)
add_optionnal_description(pdf, champ)
format_with_checkbox(pdf, Individual::GENDER_FEMALE)
format_with_checkbox(pdf, Individual::GENDER_MALE)
pdf.text "\n"
when 'Champs::HeaderSectionChamp'
add_single_line(pdf, champ.libelle, 18, :bold)
add_optionnal_description(pdf, champ)
pdf.text "\n"
when 'Champs::ExplicationChamp'
add_libelle(pdf, champ)
pdf.text champ.description
pdf.text "\n"
when 'Champs::AddressChamp', 'Champs::CarteChamp', 'Champs::TextareaChamp'
format_in_2_lines(pdf, champ.libelle, 3)
format_in_2_lines(pdf, champ, 5)
when 'Champs::DropDownListChamp'
add_libelle(pdf, champ)
add_optionnal_description(pdf, champ)
add_explanation(pdf, 'Cochez la mention applicable, une seule valeur possible')
champ.drop_down_list.options.reject(&:blank?).each do |option|
format_with_checkbox(pdf, option)
@ -127,6 +135,7 @@ def render_single_champ(pdf, champ)
pdf.text "\n"
when 'Champs::MultipleDropDownListChamp'
add_libelle(pdf, champ)
add_optionnal_description(pdf, champ)
add_explanation(pdf, 'Cochez la mention applicable, plusieurs valeurs possibles')
champ.drop_down_list.options.reject(&:blank?).each do |option|
format_with_checkbox(pdf, option)
@ -144,7 +153,7 @@ def render_single_champ(pdf, champ)
when 'Champs::SiretChamp'
add_identite_etablissement(pdf, champ.libelle)
else
format_in_2_lines(pdf, champ.libelle)
format_in_2_lines(pdf, champ)
end
end
@ -190,6 +199,7 @@ prawn_document(page_size: "A4") do |pdf|
pdf.text "\n"
add_title(pdf, 'Formulaire')
add_single_line(pdf, @procedure.description + "\n", 12, :italic) if @procedure.description.present?
add_champs(pdf, @dossier.champs)
add_page_numbering(pdf)
add_procedure(pdf, @dossier)