Update app/models/champs/header_section_champ.rb
Co-authored-by: Pierre de La Morinerie <kemenaran@gmail.com>
This commit is contained in:
parent
4feda01b6f
commit
2702660d72
3 changed files with 13 additions and 8 deletions
|
@ -45,6 +45,7 @@ class Champ < ApplicationRecord
|
||||||
:repetition?,
|
:repetition?,
|
||||||
:dossier_link?,
|
:dossier_link?,
|
||||||
:titre_identite?,
|
:titre_identite?,
|
||||||
|
:header_section?,
|
||||||
to: :type_de_champ
|
to: :type_de_champ
|
||||||
|
|
||||||
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }
|
||||||
|
@ -86,6 +87,10 @@ class Champ < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sections
|
||||||
|
siblings.filter(&:header_section?)
|
||||||
|
end
|
||||||
|
|
||||||
def mandatory_and_blank?
|
def mandatory_and_blank?
|
||||||
mandatory? && blank?
|
mandatory? && blank?
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,22 +23,18 @@ class Champs::HeaderSectionChamp < Champ
|
||||||
end
|
end
|
||||||
|
|
||||||
def libelle_with_section_index
|
def libelle_with_section_index
|
||||||
if libelle_with_section_index? || siblings.any?(&:libelle_with_section_index?)
|
if sections.none?(&:libelle_with_section_index?)
|
||||||
libelle
|
|
||||||
else
|
|
||||||
"#{section_index}. #{libelle}"
|
"#{section_index}. #{libelle}"
|
||||||
|
else
|
||||||
|
libelle
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def libelle_with_section_index?
|
def libelle_with_section_index?
|
||||||
libelle =~ /^\d/
|
libelle =~ /^\d/
|
||||||
end
|
end
|
||||||
|
|
||||||
def section_index
|
def section_index
|
||||||
siblings
|
sections.index(self) + 1
|
||||||
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:header_section) }
|
|
||||||
.index(self) + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -174,6 +174,10 @@ class TypeDeChamp < ApplicationRecord
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def header_section?
|
||||||
|
type_champ == TypeDeChamp.type_champs.fetch(:header_section)
|
||||||
|
end
|
||||||
|
|
||||||
def linked_drop_down_list?
|
def linked_drop_down_list?
|
||||||
type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue