2023-02-21 11:42:30 +01:00
|
|
|
module DossierSectionsConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
def sections_for(champ)
|
|
|
|
@sections = Hash.new do |hash, parent|
|
|
|
|
case parent
|
|
|
|
when :public
|
2023-11-28 17:29:32 +01:00
|
|
|
hash[parent] = champs_for_revision(:public, true).filter(&:header_section?)
|
2023-02-21 11:42:30 +01:00
|
|
|
when :private
|
2023-11-28 17:29:32 +01:00
|
|
|
hash[parent] = champs_for_revision(:private, true).filter(&:header_section?)
|
2023-02-21 11:42:30 +01:00
|
|
|
else
|
2023-11-28 17:29:32 +01:00
|
|
|
hash[parent] = champs_for_revision(parent.type_de_champ).filter(&:header_section?)
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
@sections[champ.parent || (champ.public? ? :public : :private)]
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_numbering_section_headers_for?(champ)
|
2023-03-09 16:15:56 +01:00
|
|
|
return false if champ.child?
|
|
|
|
|
2023-02-21 11:42:30 +01:00
|
|
|
sections_for(champ)&.none?(&:libelle_with_section_index?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_for_section_header(champ)
|
2023-11-28 17:29:32 +01:00
|
|
|
champs = champ.private? ? champs_for_revision(:private, true) : champs_for_revision(:public, true)
|
2023-02-21 11:42:30 +01:00
|
|
|
index = 1
|
|
|
|
champs.each do |c|
|
2023-03-06 16:27:33 +01:00
|
|
|
if c.repetition?
|
|
|
|
index_in_repetition = c.rows.flatten.filter { _1.stable_id == champ.stable_id }.find_index(champ)
|
|
|
|
return "#{index}.#{index_in_repetition + 1}" if index_in_repetition
|
|
|
|
else
|
|
|
|
return index if c.stable_id == champ.stable_id
|
|
|
|
next unless c.visible?
|
2023-02-21 11:42:30 +01:00
|
|
|
|
2023-03-06 16:27:33 +01:00
|
|
|
index += 1 if c.type_de_champ.header_section?
|
|
|
|
end
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
2023-03-06 16:27:33 +01:00
|
|
|
index
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|