Skip to content

Commit

Permalink
[#10960] Display a default label for type champ
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagn committed Jan 14, 2025
1 parent 31443e1 commit 46fff8f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def champ_libelle
if annotations?
"Nouvelle annotation"
else
"Nouveau champ"
nil
end
end
end
14 changes: 14 additions & 0 deletions app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def self.dump(options)
}

before_validation :check_mandatory
before_validation :set_default_libelle, if: -> { type_champ_changed? }
before_validation :normalize_libelle
before_validation :set_drop_down_list_options, if: -> { type_champ_changed? }

Expand Down Expand Up @@ -235,6 +236,19 @@ def type_champ=(value)
set_dynamic_type
end

def set_default_libelle
libelle_was_default = libelle == default_libelle(type_champ_was)
self.libelle = default_libelle(type_champ) if libelle_was_default
end

def default_libelle(type_champ)
return if type_champ.blank?

I18n.t(type_champ,
scope: [:activerecord, :attributes, :type_de_champ, :default_libelle],
default: I18n.t(type_champ, scope: [:activerecord, :attributes, :type_de_champ, :type_champs]))
end

def params_for_champ
{
private: private?,
Expand Down
18 changes: 14 additions & 4 deletions config/locales/models/type_de_champ/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,23 @@ en:
cnaf: 'Data from Caisse nationale des allocations familiales'
dgfip: 'Data from Direction générale des Finances publiques'
pole_emploi: 'Pôle emploi status'
mesri: "Data from Ministère de l’Enseignement Supérieur, de la Recherche et de l’Innovation"
epci: "EPCI"
cojo: "Accreditation Paris 2024"
mesri: 'Data from Ministère de l’Enseignement Supérieur, de la Recherche et de l’Innovation'
epci: 'EPCI'
cojo: 'Accreditation Paris 2024'
expression_reguliere: 'Regular expression'
referentiel: 'External data to configure (advanced)'
default_libelle:
annuaire_education: Educational institution
dossier_link: File number submitted on Démarches Simplifiées
epci: Public establishments for intercommunal cooperation (EPCI)
iban: IBAN
siret: SIRET number
titre_identite: Identity document
phone: Phone number
rna: RNA number
rnf: RNF number
errors:
type_de_champ:
attributes:
header_section_level:
gap_error: "An header section with %{level} is missing."
gap_error: 'An header section with %{level} is missing.'
13 changes: 13 additions & 0 deletions config/locales/models/type_de_champ/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ fr:
cojo: "Accréditation Paris 2024"
expression_reguliere: 'Expression régulière'
referentiel: 'Référentiel à configurer (avancé)'
default_libelle:
annuaire_education: Établissement
communes: Commune
departements: Département
dossier_link: Numéro de dossier déposé sur Démarches Simplifiées
epci: Établissements publics de coopération intercommunale (EPCI)
iban: IBAN
regions: Région
siret: Numéro SIRET
titre_identite: Pièce d'identité
phone: Numéro de téléphone
rna: Numéro RNA
rnf: Numéro RNF
errors:
type_de_champ:
attributes:
Expand Down
19 changes: 19 additions & 0 deletions spec/models/type_de_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,25 @@ def never_valid
it { expect(create(:type_de_champ, libelle: " fix me ").libelle).to eq("fix me") }
end

describe '#set_default_libelle' do
let(:type_de_champ) { create(:type_de_champ, type_champ: :header_section, libelle: libelle) }
let(:libelle) { nil }

it { expect(type_de_champ.libelle).to eq("Titre de section") }

context "when the type champ is changed" do
before { type_de_champ.update(type_champ: :dossier_link) }

it { expect(type_de_champ.libelle).to eq("Numéro de dossier déposé sur Démarches Simplifiées") }

context "when the libelle is customized" do
let(:libelle) { "Customized libelle" }

it { expect(type_de_champ.libelle).to eq("Customized libelle") }
end
end
end

describe '#safe_filename' do
subject { build(:type_de_champ, libelle:).libelle_as_filename }

Expand Down

0 comments on commit 46fff8f

Please sign in to comment.