From 4feda01b6f4062237f6308bd82611095a5c2e162 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Fri, 2 Apr 2021 18:19:56 +0100 Subject: [PATCH 1/2] Show section numbers only if none of sections start with numbers --- app/models/champs/header_section_champ.rb | 14 ++++++++++++++ .../editable_champs/_header_section.html.haml | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/champs/header_section_champ.rb b/app/models/champs/header_section_champ.rb index 59fd78da0..ba62b4d99 100644 --- a/app/models/champs/header_section_champ.rb +++ b/app/models/champs/header_section_champ.rb @@ -22,6 +22,20 @@ class Champs::HeaderSectionChamp < Champ # The user cannot enter any information here so it doesn’t make much sense to search end + def libelle_with_section_index + if libelle_with_section_index? || siblings.any?(&:libelle_with_section_index?) + libelle + else + "#{section_index}. #{libelle}" + end + end + + private + + def libelle_with_section_index? + libelle =~ /^\d/ + end + def section_index siblings .filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:header_section) } diff --git a/app/views/shared/dossiers/editable_champs/_header_section.html.haml b/app/views/shared/dossiers/editable_champs/_header_section.html.haml index 5e40893c5..030efcd2b 100644 --- a/app/views/shared/dossiers/editable_champs/_header_section.html.haml +++ b/app/views/shared/dossiers/editable_champs/_header_section.html.haml @@ -1,5 +1,2 @@ %h2.header-section - - libelle_starts_with_number = (champ.libelle =~ /^\d/) - - if !libelle_starts_with_number - = "#{champ.section_index}." - = champ.libelle + = champ.libelle_with_section_index From 2702660d7234f8e153bf29cd90ac8d19239d7102 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 6 Apr 2021 10:06:24 +0100 Subject: [PATCH 2/2] Update app/models/champs/header_section_champ.rb Co-authored-by: Pierre de La Morinerie --- app/models/champ.rb | 5 +++++ app/models/champs/header_section_champ.rb | 12 ++++-------- app/models/type_de_champ.rb | 4 ++++ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/models/champ.rb b/app/models/champ.rb index 8cb1d8804..780f3c7b6 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -45,6 +45,7 @@ class Champ < ApplicationRecord :repetition?, :dossier_link?, :titre_identite?, + :header_section?, to: :type_de_champ scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) } @@ -86,6 +87,10 @@ class Champ < ApplicationRecord end end + def sections + siblings.filter(&:header_section?) + end + def mandatory_and_blank? mandatory? && blank? end diff --git a/app/models/champs/header_section_champ.rb b/app/models/champs/header_section_champ.rb index ba62b4d99..3ea8874a6 100644 --- a/app/models/champs/header_section_champ.rb +++ b/app/models/champs/header_section_champ.rb @@ -23,22 +23,18 @@ class Champs::HeaderSectionChamp < Champ end def libelle_with_section_index - if libelle_with_section_index? || siblings.any?(&:libelle_with_section_index?) - libelle - else + if sections.none?(&:libelle_with_section_index?) "#{section_index}. #{libelle}" + else + libelle end end - private - def libelle_with_section_index? libelle =~ /^\d/ end def section_index - siblings - .filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:header_section) } - .index(self) + 1 + sections.index(self) + 1 end end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 913975f58..88fa0585c 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -174,6 +174,10 @@ class TypeDeChamp < ApplicationRecord ]) end + def header_section? + type_champ == TypeDeChamp.type_champs.fetch(:header_section) + end + def linked_drop_down_list? type_champ == TypeDeChamp.type_champs.fetch(:linked_drop_down_list) end