2023-03-24 10:27:32 +01:00
|
|
|
module Administrateurs
|
|
|
|
class RoutingController < AdministrateurController
|
|
|
|
include Logic
|
|
|
|
|
|
|
|
before_action :retrieve_procedure
|
|
|
|
|
|
|
|
def update
|
2023-04-07 09:51:19 +02:00
|
|
|
left = targeted_champ
|
2023-04-07 10:03:01 +02:00
|
|
|
|
|
|
|
right = targeted_champ_changed? ? empty : value
|
2023-03-24 10:27:32 +01:00
|
|
|
|
2023-08-28 16:43:08 +02:00
|
|
|
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)
|
2023-03-24 10:27:32 +01:00
|
|
|
end
|
|
|
|
|
2023-04-07 15:44:23 +02:00
|
|
|
def update_defaut_groupe_instructeur
|
|
|
|
new_defaut = @procedure.groupe_instructeurs.find(defaut_groupe_instructeur_id)
|
|
|
|
@procedure.update!(defaut_groupe_instructeur: new_defaut)
|
|
|
|
end
|
|
|
|
|
2023-03-24 10:27:32 +01:00
|
|
|
private
|
|
|
|
|
2023-04-07 10:03:01 +02:00
|
|
|
def targeted_champ_changed?
|
|
|
|
targeted_champ != groupe_instructeur.routing_rule&.left
|
|
|
|
end
|
|
|
|
|
2023-03-24 10:27:32 +01:00
|
|
|
def targeted_champ
|
2023-04-07 22:39:28 +02:00
|
|
|
Logic.from_json(params[:targeted_champ])
|
2023-03-24 10:27:32 +01:00
|
|
|
end
|
|
|
|
|
2023-08-28 16:43:08 +02:00
|
|
|
def operator_name
|
|
|
|
params[:operator_name]
|
|
|
|
end
|
|
|
|
|
2023-03-24 10:27:32 +01:00
|
|
|
def value
|
2023-04-07 22:39:28 +02:00
|
|
|
Logic.from_json(params[:value])
|
2023-03-27 15:14:01 +02:00
|
|
|
end
|
|
|
|
|
2023-04-07 09:45:50 +02:00
|
|
|
def groupe_instructeur
|
|
|
|
@groupe_instructeur ||= @procedure.groupe_instructeurs.find(groupe_instructeur_id)
|
|
|
|
end
|
|
|
|
|
2023-03-24 10:27:32 +01:00
|
|
|
def groupe_instructeur_id
|
2023-04-07 22:39:28 +02:00
|
|
|
params[:groupe_instructeur_id]
|
2023-03-24 10:27:32 +01:00
|
|
|
end
|
|
|
|
|
2023-04-07 15:44:23 +02:00
|
|
|
def defaut_groupe_instructeur_id
|
2023-04-07 22:39:28 +02:00
|
|
|
params[:defaut_groupe_instructeur_id]
|
2023-03-24 10:27:32 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|