feat(routing): can add a routing rule with not_eq operator

This commit is contained in:
Eric Leroy-Terquem 2023-08-28 16:43:08 +02:00
parent e1ab65e62a
commit d0da808325
4 changed files with 27 additions and 2 deletions

View file

@ -17,6 +17,10 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
@groupe_instructeur.routing_rule&.right || empty
end
def operator_name
@groupe_instructeur.routing_rule&.class&.name || empty
end
def targeted_champ_tag
select_tag(
'targeted_champ',
@ -39,6 +43,15 @@ class Procedure::OneGroupeManagementComponent < ApplicationComponent
.map { |tdc| [tdc.libelle, champ_value(tdc.stable_id).to_json] }
end
def operator_tag
select_tag('operator_name',
options_for_select(
[['est égal à', Logic::Eq.name], ["n'est pas égal à", Logic::NotEq.name]],
selected: operator_name
),
class: 'fr-select')
end
def value_tag
select_tag(
'value',

View file

@ -40,7 +40,8 @@
.fr-mr-2w.no-wrap si le champ
.target.fr-mr-2w
= targeted_champ_tag
.operator.fr-mr-2w.no-wrap est égal à
.operator.fr-mr-2w.no-wrap
= operator_tag
.value
= value_tag
.fr-hint-text

View file

@ -9,7 +9,13 @@ module Administrateurs
right = targeted_champ_changed? ? empty : value
groupe_instructeur.update!(routing_rule: ds_eq(left, right))
new_routing_rule = case operator_name
when Eq.name
ds_eq(left, right)
when NotEq.name
ds_not_eq(left, right)
end
groupe_instructeur.update!(routing_rule: new_routing_rule)
end
def update_defaut_groupe_instructeur
@ -27,6 +33,10 @@ module Administrateurs
Logic.from_json(params[:targeted_champ])
end
def operator_name
params[:operator_name]
end
def value
Logic.from_json(params[:value])
end

View file

@ -11,6 +11,7 @@ describe Administrateurs::RoutingController, type: :controller do
{
procedure_id: procedure.id,
targeted_champ: champ_value(drop_down_tdc.stable_id).to_json,
operator_name: Logic::Eq.name,
value: empty.to_json,
groupe_instructeur_id: gi_2.id
}