2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-21 11:42:30 +01:00
|
|
|
module DossierSectionsConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2024-03-14 13:34:20 +01:00
|
|
|
def sections_for(type_de_champ)
|
2023-02-21 11:42:30 +01:00
|
|
|
@sections = Hash.new do |hash, parent|
|
|
|
|
case parent
|
|
|
|
when :public
|
2024-03-14 13:34:20 +01:00
|
|
|
hash[parent] = revision.types_de_champ_public.filter(&:header_section?)
|
2023-02-21 11:42:30 +01:00
|
|
|
when :private
|
2024-03-14 13:34:20 +01:00
|
|
|
hash[parent] = revision.types_de_champ_private.filter(&:header_section?)
|
2023-02-21 11:42:30 +01:00
|
|
|
else
|
2024-03-14 13:34:20 +01:00
|
|
|
hash[parent] = revision.children_of(parent).filter(&:header_section?)
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
end
|
2024-03-14 13:34:20 +01:00
|
|
|
@sections[revision.parent_of(type_de_champ) || (type_de_champ.public? ? :public : :private)]
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
|
2024-03-14 13:34:20 +01:00
|
|
|
def auto_numbering_section_headers_for?(type_de_champ)
|
2024-09-19 11:09:01 +02:00
|
|
|
return false if revision.child?(type_de_champ)
|
2023-03-09 16:15:56 +01:00
|
|
|
|
2024-03-14 13:34:20 +01:00
|
|
|
sections_for(type_de_champ)&.none? { _1.libelle =~ /^\d/ }
|
2023-02-21 11:42:30 +01:00
|
|
|
end
|
|
|
|
|
2024-03-14 13:34:20 +01:00
|
|
|
def index_for_section_header(type_de_champ)
|
|
|
|
types_de_champ = type_de_champ.private? ? revision.types_de_champ_private : revision.types_de_champ_public
|
2023-02-21 11:42:30 +01:00
|
|
|
index = 1
|
2024-03-14 13:34:20 +01:00
|
|
|
types_de_champ.each do |tdc|
|
|
|
|
if tdc.repetition?
|
|
|
|
index_in_repetition = revision.children_of(tdc).find_index { _1.stable_id == type_de_champ.stable_id }
|
2023-03-06 16:27:33 +01:00
|
|
|
return "#{index}.#{index_in_repetition + 1}" if index_in_repetition
|
|
|
|
else
|
2024-03-14 13:34:20 +01:00
|
|
|
return index if tdc.stable_id == type_de_champ.stable_id
|
|
|
|
next unless project_champ(tdc, nil).visible?
|
2023-02-21 11:42:30 +01:00
|
|
|
|
2024-03-14 13:34:20 +01:00
|
|
|
index += 1 if tdc.header_section?
|
2023-03-06 16:27:33 +01:00
|
|
|
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
|