refactor(routing): use selerialized logic in select value

This commit is contained in:
simon lehericey 2023-04-07 09:51:19 +02:00
parent 16565d099a
commit e27e18fdaf
2 changed files with 16 additions and 16 deletions

View file

@ -9,7 +9,11 @@ class Procedure::RoutingRulesComponent < ApplicationComponent
def rows
@groupe_instructeurs.active.map do |gi|
[gi.routing_rule&.left, gi.routing_rule&.right, gi]
if gi.routing_rule.present?
[gi.routing_rule.left, gi.routing_rule.right, gi]
else
[empty, empty, gi]
end
end
end
@ -20,7 +24,7 @@ class Procedure::RoutingRulesComponent < ApplicationComponent
def targeted_champ_tag(targeted_champ, row_index)
select_tag(
'targeted_champ',
options_for_select(targeted_champs_for_select, selected: targeted_champ&.stable_id),
options_for_select(targeted_champs_for_select, selected: targeted_champ.to_json),
id: input_id_for('targeted_champ', row_index)
)
end
@ -28,7 +32,7 @@ class Procedure::RoutingRulesComponent < ApplicationComponent
def value_tag(targeted_champ, value, row_index)
select_tag(
'value',
options_for_select(values_for_select(targeted_champ), selected: value),
options_for_select(values_for_select(targeted_champ), selected: value.to_json),
id: input_id_for('value', row_index)
)
end
@ -53,12 +57,14 @@ class Procedure::RoutingRulesComponent < ApplicationComponent
def available_targets_for_select
@revision.types_de_champ_public
.filter { |tdc| [:drop_down_list].include?(tdc.type_champ.to_sym) }
.map { |tdc| [tdc.libelle, tdc.stable_id] }
.map { |tdc| [tdc.libelle, champ_value(tdc.stable_id).to_json] }
end
def available_values_for_select(targeted_champ)
return [] if targeted_champ.nil?
targeted_champ.options(@revision.types_de_champ_public)
return [] if targeted_champ.is_a?(Logic::Empty)
targeted_champ
.options(@revision.types_de_champ_public)
.map { |tdc| [tdc.first, constant(tdc.first).to_json] }
end
def values_for_select(targeted_champ)

View file

@ -5,8 +5,8 @@ module Administrateurs
before_action :retrieve_procedure
def update
left = champ_value(targeted_champ)
right = parsed_value
left = targeted_champ
right = value
groupe_instructeur.update!(routing_rule: ds_eq(left, right))
end
@ -14,17 +14,11 @@ module Administrateurs
private
def targeted_champ
routing_params[:targeted_champ].to_i
Logic.from_json(routing_params[:targeted_champ])
end
def value
routing_params[:value]
end
def parsed_value
term = Logic.from_json(value) rescue nil
term.presence || constant(value)
Logic.from_json(routing_params[:value])
end
def groupe_instructeur