Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ Administrateur, je veux que le libellé par défaut d'un nouveau champ soit adapté au type de champ choisi #11210

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 18 additions & 4 deletions app/models/type_de_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ def self.dump(options)

serialize :condition, LogicSerializer

after_initialize :set_dynamic_type
after_create :populate_stable_id

attr_reader :dynamic_type

scope :public_only, -> { where(private: false) }
Expand Down Expand Up @@ -209,11 +206,15 @@ def self.dump(options)
allow_blank: true
}

after_initialize :set_dynamic_type
after_create :populate_stable_id

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? }

before_save :remove_attachment, if: -> { type_champ_changed? }
before_validation :set_drop_down_list_options, if: -> { type_champ_changed? }

def valid?(context = nil)
super
Expand All @@ -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
Loading