chore(conditions): update controllers and routes
This commit is contained in:
parent
979b5101ae
commit
4d95f49c82
6 changed files with 241 additions and 172 deletions
|
@ -42,7 +42,7 @@ module Administrateurs
|
|||
private
|
||||
|
||||
def build_condition_component
|
||||
TypesDeChampEditor::ConditionsComponent.new(
|
||||
Conditions::ChampsConditionsComponent.new(
|
||||
tdc: @tdc,
|
||||
upper_tdcs: @upper_tdcs,
|
||||
procedure_id: @procedure.id
|
||||
|
@ -50,7 +50,7 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def condition_form
|
||||
ConditionForm.new(condition_params.merge({ upper_tdcs: @upper_tdcs }))
|
||||
ConditionForm.new(condition_params.merge({ source_tdcs: @upper_tdcs }))
|
||||
end
|
||||
|
||||
def retrieve_coordinate_and_uppers
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
module Administrateurs
|
||||
class RoutingController < AdministrateurController
|
||||
include Logic
|
||||
|
||||
before_action :retrieve_procedure
|
||||
|
||||
def update
|
||||
left = targeted_champ
|
||||
|
||||
right = targeted_champ_changed? ? empty : value
|
||||
|
||||
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
|
||||
new_defaut = @procedure.groupe_instructeurs.find(defaut_groupe_instructeur_id)
|
||||
@procedure.update!(defaut_groupe_instructeur: new_defaut)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def targeted_champ_changed?
|
||||
targeted_champ != groupe_instructeur.routing_rule&.left
|
||||
end
|
||||
|
||||
def targeted_champ
|
||||
Logic.from_json(params[:targeted_champ])
|
||||
end
|
||||
|
||||
def operator_name
|
||||
params[:operator_name]
|
||||
end
|
||||
|
||||
def value
|
||||
Logic.from_json(params[:value])
|
||||
end
|
||||
|
||||
def groupe_instructeur
|
||||
@groupe_instructeur ||= @procedure.groupe_instructeurs.find(groupe_instructeur_id)
|
||||
end
|
||||
|
||||
def groupe_instructeur_id
|
||||
params[:groupe_instructeur_id]
|
||||
end
|
||||
|
||||
def defaut_groupe_instructeur_id
|
||||
params[:defaut_groupe_instructeur_id]
|
||||
end
|
||||
end
|
||||
end
|
79
app/controllers/administrateurs/routing_rules_controller.rb
Normal file
79
app/controllers/administrateurs/routing_rules_controller.rb
Normal file
|
@ -0,0 +1,79 @@
|
|||
module Administrateurs
|
||||
class RoutingRulesController < AdministrateurController
|
||||
include Logic
|
||||
before_action :retrieve_procedure, :retrieve_tdcs
|
||||
before_action :retrieve_groupe_instructeur, except: [:update_defaut_groupe_instructeur]
|
||||
|
||||
def update
|
||||
condition = condition_form.to_condition
|
||||
@groupe_instructeur.update!(routing_rule: condition)
|
||||
|
||||
@routing_rule_component = build_routing_rule_component
|
||||
end
|
||||
|
||||
def add_row
|
||||
condition = Logic.add_empty_condition_to(@groupe_instructeur.routing_rule)
|
||||
@groupe_instructeur.update!(routing_rule: condition)
|
||||
|
||||
@routing_rule_component = build_routing_rule_component
|
||||
end
|
||||
|
||||
def delete_row
|
||||
condition = condition_form.delete_row(row_index).to_condition
|
||||
@groupe_instructeur.update!(routing_rule: condition)
|
||||
|
||||
@routing_rule_component = build_routing_rule_component
|
||||
end
|
||||
|
||||
def change_targeted_champ
|
||||
condition = condition_form.change_champ(row_index).to_condition
|
||||
@groupe_instructeur.update!(routing_rule: condition)
|
||||
|
||||
@routing_rule_component = build_routing_rule_component
|
||||
end
|
||||
|
||||
def update_defaut_groupe_instructeur
|
||||
new_defaut = @procedure.groupe_instructeurs.find(defaut_groupe_instructeur_id)
|
||||
@procedure.update!(defaut_groupe_instructeur: new_defaut)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def groupe_instructeur_id
|
||||
params[:groupe_instructeur_id]
|
||||
end
|
||||
|
||||
def defaut_groupe_instructeur_id
|
||||
params[:defaut_groupe_instructeur_id]
|
||||
end
|
||||
|
||||
def build_routing_rule_component
|
||||
Conditions::RoutingRulesComponent.new(
|
||||
groupe_instructeur: @groupe_instructeur
|
||||
)
|
||||
end
|
||||
|
||||
def condition_form
|
||||
ConditionForm.new(routing_rule_params.merge({ source_tdcs: @source_tdcs }))
|
||||
end
|
||||
|
||||
def retrieve_tdcs
|
||||
@source_tdcs = @procedure.active_revision.types_de_champ
|
||||
end
|
||||
|
||||
def retrieve_groupe_instructeur
|
||||
@groupe_instructeur = @procedure.groupe_instructeurs.find(groupe_instructeur_id)
|
||||
end
|
||||
|
||||
def routing_rule_params
|
||||
params
|
||||
.require(:groupe_instructeur)
|
||||
.require(:condition_form)
|
||||
.permit(:top_operator_name, rows: [:targeted_champ, :operator_name, :value])
|
||||
end
|
||||
|
||||
def row_index
|
||||
params[:row_index].to_i
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue