preload all tdc once for all
This commit is contained in:
parent
4dbd44d72a
commit
ca8dc34196
2 changed files with 17 additions and 7 deletions
|
@ -113,6 +113,11 @@ class PiecesJustificativesService
|
|||
pdfs = []
|
||||
|
||||
procedure = dossiers.first.procedure
|
||||
tdc_by_id = TypeDeChamp
|
||||
.joins(:revisions)
|
||||
.where(revisions: { id: procedure.revisions })
|
||||
.to_a
|
||||
.group_by(&:id)
|
||||
|
||||
dossiers
|
||||
.includes(:champs, :champs_private, :commentaires, :individual,
|
||||
|
@ -124,7 +129,8 @@ class PiecesJustificativesService
|
|||
assigns: {
|
||||
include_infos_administration: true,
|
||||
dossier: dossier,
|
||||
procedure: procedure
|
||||
procedure: procedure,
|
||||
tdc_by_id: tdc_by_id
|
||||
})
|
||||
|
||||
a = FakeAttachment.new(
|
||||
|
|
|
@ -130,28 +130,30 @@ def add_identite_etablissement(pdf, etablissement)
|
|||
end
|
||||
|
||||
def add_single_champ(pdf, champ)
|
||||
tdc = @tdc_by_id[champ.type_de_champ_id].first
|
||||
|
||||
case champ.type
|
||||
when 'Champs::PieceJustificativeChamp', 'Champs::TitreIdentiteChamp'
|
||||
return
|
||||
when 'Champs::HeaderSectionChamp'
|
||||
add_section_title(pdf, champ.libelle)
|
||||
add_section_title(pdf, tdc.libelle)
|
||||
when 'Champs::ExplicationChamp'
|
||||
format_in_2_lines(pdf, champ.libelle, champ.description)
|
||||
format_in_2_lines(pdf, tdc.libelle, tdc.description)
|
||||
when 'Champs::CarteChamp'
|
||||
format_in_2_lines(pdf, champ.libelle, champ.to_feature_collection.to_json)
|
||||
format_in_2_lines(pdf, tdc.libelle, champ.to_feature_collection.to_json)
|
||||
when 'Champs::SiretChamp'
|
||||
pdf.font 'marianne', style: :bold do
|
||||
pdf.text champ.libelle
|
||||
pdf.text tdc.libelle
|
||||
end
|
||||
if champ.etablissement.present?
|
||||
add_identite_etablissement(pdf, champ.etablissement)
|
||||
end
|
||||
when 'Champs::NumberChamp'
|
||||
value = champ.to_s.empty? ? 'Non communiqué' : number_with_delimiter(champ.to_s)
|
||||
format_in_2_lines(pdf, champ.libelle, value)
|
||||
format_in_2_lines(pdf, tdc.libelle, value)
|
||||
else
|
||||
value = champ.to_s.empty? ? 'Non communiqué' : champ.to_s
|
||||
format_in_2_lines(pdf, champ.libelle, value)
|
||||
format_in_2_lines(pdf, tdc.libelle, value)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -206,6 +208,8 @@ end
|
|||
|
||||
prawn_document(page_size: "A4") do |pdf|
|
||||
@procedure ||= @dossier.procedure
|
||||
@tdc_by_id ||= @dossier.champs.map(&:type_de_champ).group_by(&:id)
|
||||
|
||||
pdf.font_families.update( 'marianne' => {
|
||||
normal: Rails.root.join('lib/prawn/fonts/marianne/marianne-regular.ttf' ),
|
||||
bold: Rails.root.join('lib/prawn/fonts/marianne/marianne-bold.ttf' ),
|
||||
|
|
Loading…
Reference in a new issue