refactor(type de champ): extract codes_and_names method

This commit is contained in:
Eric Leroy-Terquem 2023-08-22 17:13:09 +02:00
parent 7e3fc68c53
commit 8d0fffe44f
3 changed files with 8 additions and 2 deletions

View file

@ -42,7 +42,7 @@ module Administrateurs
tdc_options = case tdc.type_champ tdc_options = case tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements) when TypeDeChamp.type_champs.fetch(:departements)
APIGeoService.departements.map { "#{_1[:code]} #{_1[:name]}" } tdc.codes_and_names
when TypeDeChamp.type_champs.fetch(:drop_down_list) when TypeDeChamp.type_champs.fetch(:drop_down_list)
tdc.drop_down_options.reject(&:empty?) tdc.drop_down_options.reject(&:empty?)
end end

View file

@ -108,7 +108,7 @@ class GroupeInstructeur < ApplicationRecord
options = case routing_tdc.type_champ options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements) when TypeDeChamp.type_champs.fetch(:departements)
APIGeoService.departements.map { "#{_1[:code]} #{_1[:name]}" } routing_tdc.codes_and_names
when TypeDeChamp.type_champs.fetch(:drop_down_list) when TypeDeChamp.type_champs.fetch(:drop_down_list)
routing_tdc.options_with_drop_down_other routing_tdc.options_with_drop_down_other
end end

View file

@ -477,6 +477,12 @@ class TypeDeChamp < ApplicationRecord
end end
end end
def codes_and_names
if departement?
APIGeoService.departements.map { "#{_1[:code]} #{_1[:name]}" }
end
end
# historicaly we added a blank ("") option by default to avoid wrong selection # historicaly we added a blank ("") option by default to avoid wrong selection
# see self.parse_drop_down_list_value # see self.parse_drop_down_list_value
# then rails decided to add this blank ("") option when the select is required # then rails decided to add this blank ("") option when the select is required