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-04-07 09:45:50 +02:00
|
|
|
groupe_instructeur.update!(routing_rule: ds_eq(left, right))
|
2023-03-24 10:27:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
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 09:51:19 +02:00
|
|
|
Logic.from_json(routing_params[:targeted_champ])
|
2023-03-24 10:27:32 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
2023-04-07 09:51:19 +02:00
|
|
|
Logic.from_json(routing_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
|
|
|
|
routing_params[:groupe_instructeur_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def routing_params
|
|
|
|
params.permit(:targeted_champ, :value, :groupe_instructeur_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|