fix(conditional): dynamic title counters using css

Closes #8086
This commit is contained in:
Colin Darie 2023-02-20 16:45:00 +01:00
parent 568c2f8f4e
commit 3de089d6c7
8 changed files with 47 additions and 14 deletions

View file

@ -0,0 +1,11 @@
.counter-start-header-section {
counter-reset: headerSectionCounter;
}
.header-section {
counter-increment: headerSectionCounter;
&.header-section-counter::before {
content: counter(headerSectionCounter) ". ";
}
}

View file

@ -1,2 +1,2 @@
%h2.header-section
= @champ.libelle_with_section_index
%h2.header-section{ class: @champ.dossier.auto_numbering_section_headers_for?(@champ) ? "header-section-counter" : nil }
= @champ.libelle

View file

@ -25,14 +25,6 @@ class Champs::HeaderSectionChamp < Champ
# The user cannot enter any information here so it doesnt make much sense to search
end
def libelle_with_section_index
if sections&.none?(&:libelle_with_section_index?)
"#{section_index}. #{libelle}"
else
libelle
end
end
def libelle_with_section_index?
libelle =~ /^\d/
end

View file

@ -1291,6 +1291,10 @@ class Dossier < ApplicationRecord
false
end
def auto_numbering_section_headers_for?(champ)
sections_for(champ)&.none?(&:libelle_with_section_index?)
end
private
def create_missing_traitemets

View file

@ -10,8 +10,7 @@
- else
%tr
- if c.type_champ == TypeDeChamp.type_champs.fetch(:header_section)
%th.header-section{ colspan: 3 }
= c.libelle
%th.header-section{ colspan: 3, class: c.dossier.auto_numbering_section_headers_for?(c) ? "header-section-counter" : nil }= c.libelle
- else
%td.libelle{ class: repetition ? 'padded' : '' }
= "#{c.libelle} :"

View file

@ -1,4 +1,4 @@
%table.table.vertical.dossier-champs{ role: :presentation }
%table.table.vertical.dossier-champs.counter-start-header-section{ role: :presentation }
%tbody
- if dossier.show_groupe_instructeur_details?
%td.libelle= dossier.procedure.routing_criteria_name

View file

@ -2,7 +2,7 @@
- content_for(:notice_info) do
= render partial: "shared/dossiers/france_connect_informations_notice", locals: { user_information: dossier.france_connect_information }
.dossier-edit.container
.dossier-edit.container.counter-start-header-section
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
- if dossier.brouillon?

View file

@ -2089,6 +2089,33 @@ describe Dossier do
end
end
describe '#auto_numbering_section_headers_for?' do
let(:public_libelle) { "Infos" }
let(:private_libelle) { "Infos Private" }
let(:types_de_champ_public) { [{ type: :header_section, libelle: public_libelle }, { type: :header_section, libelle: "Details" }] }
let(:types_de_champ_private) { [{ type: :header_section, libelle: private_libelle }, { type: :header_section, libelle: "Details Private" }] }
let(:procedure) { create(:procedure, :for_individual, types_de_champ_public:, types_de_champ_private:) }
let(:dossier) { create(:dossier, procedure: procedure) }
context "with no section having number" do
it { expect(dossier.auto_numbering_section_headers_for?(dossier.champs_public[1])).to eq(true) }
it { expect(dossier.auto_numbering_section_headers_for?(dossier.champs_private[1])).to eq(true) }
end
context "with public section having number" do
let(:public_libelle) { "1 - infos" }
it { expect(dossier.auto_numbering_section_headers_for?(dossier.champs_public[1])).to eq(false) }
it { expect(dossier.auto_numbering_section_headers_for?(dossier.champs_private[1])).to eq(true) }
end
context "with private section having number" do
let(:private_libelle) { "1 - infos private" }
it { expect(dossier.auto_numbering_section_headers_for?(dossier.champs_public[1])).to eq(true) }
it { expect(dossier.auto_numbering_section_headers_for?(dossier.champs_private[1])).to eq(false) }
end
end
private
def count_for_month(processed_by_month, month)