fix(routing): can create simple routing with communes and epci tdc

This commit is contained in:
Eric Leroy-Terquem 2024-01-31 15:15:06 +01:00
parent 17a471e880
commit b04f152733
2 changed files with 51 additions and 4 deletions

View file

@ -45,10 +45,16 @@ module Administrateurs
case tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
create_groups_from_territorial_tdc(tdc_options, stable_id)
rule_operator = :ds_eq
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
when TypeDeChamp.type_champs.fetch(:communes), TypeDeChamp.type_champs.fetch(:epci)
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
rule_operator = :ds_in_departement
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
when TypeDeChamp.type_champs.fetch(:regions)
rule_operator = :ds_eq
tdc_options = APIGeoService.regions.map { ["#{_1[:code]} #{_1[:name]}", _1[:code]] }
create_groups_from_territorial_tdc(tdc_options, stable_id)
create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
when TypeDeChamp.type_champs.fetch(:drop_down_list)
tdc_options = tdc.drop_down_options.reject(&:empty?)
create_groups_from_drop_down_list_tdc(tdc_options, stable_id)
@ -457,9 +463,10 @@ module Administrateurs
flash[:alert] = "Importation impossible, veuillez importer un csv suivant #{view_context.link_to('ce modèle', "/csv/import-instructeurs-test.csv")} pour une procédure sans routage ou #{view_context.link_to('celui-ci', "/csv/#{I18n.locale}/import-groupe-test.csv")} pour une procédure routée"
end
def create_groups_from_territorial_tdc(tdc_options, stable_id)
def create_groups_from_territorial_tdc(tdc_options, stable_id, rule_operator)
tdc_options.each do |label, code|
routing_rule = ds_eq(champ_value(stable_id), constant(code))
routing_rule = send(rule_operator, champ_value(stable_id), constant(code))
@procedure
.groupe_instructeurs
.find_or_create_by(label: label)