feat(routing): add departements options to value tag

This commit is contained in:
Eric Leroy-Terquem 2023-08-22 10:37:22 +02:00
parent ac823c1b25
commit 4be9352781
2 changed files with 20 additions and 4 deletions

View file

@ -58,8 +58,18 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
def available_values_for_select(targeted_champ)
return [] if targeted_champ.is_a?(Logic::Empty)
targeted_champ
.options(@revision.types_de_champ_public)
.map { |(label, value)| [label, constant(value).to_json] }
case @revision.types_de_champ_public.find_by(stable_id: targeted_champ.stable_id).type_champ
when TypeDeChamp.type_champs.fetch(:departements)
departements_for_select
when TypeDeChamp.type_champs.fetch(:drop_down_list)
targeted_champ
.options(@revision.types_de_champ_public)
.map { |(label, value)| [label, constant(value).to_json] }
end
end
def departements_for_select
APIGeoService.departements.map { ["#{_1[:code]} #{_1[:name]}", constant("#{_1[:code]} #{_1[:name]}").to_json] }
end
end

View file

@ -105,7 +105,13 @@ class GroupeInstructeur < ApplicationRecord
def routing_rule_matches_tdc?
routing_tdc = procedure.active_revision.types_de_champ.find_by(stable_id: routing_rule.left.stable_id)
options = routing_tdc.options_with_drop_down_other
options = case routing_tdc.type_champ
when TypeDeChamp.type_champs.fetch(:departements)
APIGeoService.departements.map { "#{_1[:code]} #{_1[:name]}" }
when TypeDeChamp.type_champs.fetch(:drop_down_list)
routing_tdc.options_with_drop_down_other
end
routing_rule.right.value.in?(options)
end