remove old logic

This commit is contained in:
simon lehericey 2023-05-09 14:36:26 +02:00 committed by LeSim
parent 6c188a867d
commit 9004dd9758
8 changed files with 6 additions and 264 deletions

View file

@ -1,82 +0,0 @@
class Procedure::RoutingRulesComponent < ApplicationComponent
include Logic
def initialize(revision:, groupe_instructeurs:)
@revision = revision
@groupe_instructeurs = groupe_instructeurs
@procedure_id = revision.procedure_id
end
def rows
@groupe_instructeurs.active.map do |gi|
if gi.routing_rule.present?
[gi.routing_rule.left, gi.routing_rule.right, gi]
else
[empty, empty, gi]
end
end
end
def can_route?
available_targets_for_select.present?
end
def targeted_champ_tag(targeted_champ, row_index)
select_tag(
'targeted_champ',
options_for_select(targeted_champs_for_select, selected: targeted_champ.to_json),
id: input_id_for('targeted_champ', row_index)
)
end
def value_tag(targeted_champ, value, row_index)
select_tag(
'value',
options_for_select(
values_for_select(targeted_champ, row_index),
selected: value.to_json
),
id: input_id_for('value', row_index)
)
end
def hidden_groupe_instructeur_tag(groupe_instructeur_id)
hidden_field_tag(
'groupe_instructeur_id',
groupe_instructeur_id
)
end
private
def targeted_champs_for_select
empty_target_for_select + available_targets_for_select
end
def empty_target_for_select
[[t('.select'), empty.to_json]]
end
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, champ_value(tdc.stable_id).to_json] }
end
def available_values_for_select(targeted_champ)
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, row_index)
(empty_target_for_select + available_values_for_select(targeted_champ))
# add id to help morph render selected option
.map { |(libelle, json)| [libelle, json, { id: "#{row_index}-option-#{libelle}" }] }
end
def input_id_for(name, row_index)
"#{name}-#{row_index}"
end
end

View file

@ -1,11 +0,0 @@
---
fr:
select: Sélectionner
apply_routing_rules: Règles de routage
routing_rules_notice_html: |
<p>Ajoutez des règles de routage à partir de champs « choix simple » créés dans le <a href="%{path}">formulaire</a>.</p>
<p>Les dossiers seront routées vers le premier groupe affiché dont la règle correspond.</p>
routing_rules_warning_html: |
<p>Pour appliquer des règles de routage, votre formulaire doit comporter
au moins un champ « choix simple ».</p>
<p>Ajoutez ce champ dans la page <a href="%{path}">« Configuration des champs »</a>.</p>

View file

@ -1,40 +0,0 @@
.card#routing-rules
%h2.card-title= t('.apply_routing_rules')
- if can_route?
.notice
= t('.routing_rules_notice_html', path: champs_admin_procedure_path(@procedure_id))
.mt-2.width-100
%table.routing-rules-table.mt-2.width-100
%thead
%tr
%th.far-left Router vers
%th.if
%th.target Champ cible du routage
%th.operator
%th.value Valeur
.mt-2.width-100
- rows.each.with_index do |(targeted_champ, value, groupe_instructeur), row_index|
= form_tag admin_procedure_routing_rules_path(@procedure_id),
method: :post,
class: "form width-100 gi-#{groupe_instructeur.id}",
data: { controller: 'autosave' } do
= hidden_groupe_instructeur_tag(groupe_instructeur.id)
%table.routing-rules-table.condition-table.mt-2.width-100
%tbody
%tr
%td.far-left= groupe_instructeur.label
%td.if si
%td.target= targeted_champ_tag(targeted_champ, row_index)
%td.operator est égal à
%td.value= value_tag(targeted_champ, value, row_index)
= form_tag admin_procedure_update_defaut_groupe_instructeur_path(@procedure_id),
class: 'form flex align-baseline defaut-groupe',
data: { controller: 'autosave' } do
= label_tag :defaut_groupe_instructeur_id, 'Et si aucune règle ne correspond, router vers :'
= select_tag :defaut_groupe_instructeur_id,
options_for_select(@groupe_instructeurs.pluck(:label, :id), selected: @revision.procedure.defaut_groupe_instructeur.id),
class: 'width-100'
- else
.notice= t('.routing_rules_warning_html', path: champs_admin_procedure_path(@procedure_id))