feat(dossier/pdf): header sections numbering
This commit is contained in:
parent
3de089d6c7
commit
d7880f7e58
3 changed files with 60 additions and 1 deletions
|
@ -1295,6 +1295,18 @@ class Dossier < ApplicationRecord
|
||||||
sections_for(champ)&.none?(&:libelle_with_section_index?)
|
sections_for(champ)&.none?(&:libelle_with_section_index?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def index_for_section_header(champ)
|
||||||
|
champs = champ.private? ? champs_private : champs_public
|
||||||
|
|
||||||
|
index = 1
|
||||||
|
champs.each do |c|
|
||||||
|
return index if c.stable_id == champ.stable_id
|
||||||
|
next unless c.visible?
|
||||||
|
|
||||||
|
index += 1 if c.type_de_champ.header_section?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_missing_traitemets
|
def create_missing_traitemets
|
||||||
|
|
|
@ -141,7 +141,13 @@ def add_single_champ(pdf, champ)
|
||||||
when 'Champs::PieceJustificativeChamp', 'Champs::TitreIdentiteChamp'
|
when 'Champs::PieceJustificativeChamp', 'Champs::TitreIdentiteChamp'
|
||||||
return
|
return
|
||||||
when 'Champs::HeaderSectionChamp'
|
when 'Champs::HeaderSectionChamp'
|
||||||
add_section_title(pdf, tdc.libelle)
|
libelle = if @dossier.auto_numbering_section_headers_for?(champ)
|
||||||
|
"#{@dossier.index_for_section_header(champ)}. #{champ.libelle}"
|
||||||
|
else
|
||||||
|
champ.libelle
|
||||||
|
end
|
||||||
|
|
||||||
|
add_section_title(pdf, libelle)
|
||||||
when 'Champs::ExplicationChamp'
|
when 'Champs::ExplicationChamp'
|
||||||
format_in_2_lines(pdf, tdc.libelle, strip_tags(tdc.description))
|
format_in_2_lines(pdf, tdc.libelle, strip_tags(tdc.description))
|
||||||
when 'Champs::CarteChamp'
|
when 'Champs::CarteChamp'
|
||||||
|
|
|
@ -2116,6 +2116,47 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#index_for_section_header' do
|
||||||
|
include Logic
|
||||||
|
let(:number_stable_id) { 99 }
|
||||||
|
let(:types_de_champ) {
|
||||||
|
[
|
||||||
|
{ type: :header_section, libelle: "Infos" }, { type: :integer_number, stable_id: number_stable_id },
|
||||||
|
{ type: :header_section, libelle: "Details", condition: ds_eq(champ_value(99), constant(5)) }, { type: :header_section, libelle: "Conclusion" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public: types_de_champ) }
|
||||||
|
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||||
|
|
||||||
|
let(:headers) { dossier.champs_public.select { _1.header_section? } }
|
||||||
|
|
||||||
|
let(:number_value) { nil }
|
||||||
|
|
||||||
|
before do
|
||||||
|
dossier.champs_public.find { _1.stable_id == number_stable_id }.update(value: number_value)
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when there are invisible sections" do
|
||||||
|
it "index accordingly header sections" do
|
||||||
|
expect(dossier.index_for_section_header(headers[0])).to eq(1)
|
||||||
|
expect(headers[1]).not_to be_visible
|
||||||
|
expect(dossier.index_for_section_header(headers[2])).to eq(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when all headers are visible" do
|
||||||
|
let(:number_value) { 5 }
|
||||||
|
it "index accordingly header sections" do
|
||||||
|
expect(dossier.index_for_section_header(headers[0])).to eq(1)
|
||||||
|
expect(headers[1]).to be_visible
|
||||||
|
expect(dossier.index_for_section_header(headers[1])).to eq(2)
|
||||||
|
expect(dossier.index_for_section_header(headers[2])).to eq(3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def count_for_month(processed_by_month, month)
|
def count_for_month(processed_by_month, month)
|
||||||
|
|
Loading…
Reference in a new issue