feat(routing): add routing component
This commit is contained in:
parent
3cede55d41
commit
e950363d21
6 changed files with 107 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
@import "colors";
|
||||
@import "constants";
|
||||
|
||||
form.form > .conditionnel {
|
||||
.conditionnel {
|
||||
|
||||
.condition-error {
|
||||
background: $background-red;
|
||||
|
|
66
app/components/procedure/routing_rules_component.rb
Normal file
66
app/components/procedure/routing_rules_component.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
class Procedure::RoutingRulesComponent < ApplicationComponent
|
||||
include Logic
|
||||
|
||||
def initialize(revision:, groupe_instructeurs:)
|
||||
@revision = revision
|
||||
@groupe_instructeurs = groupe_instructeurs
|
||||
end
|
||||
|
||||
def rows
|
||||
@groupe_instructeurs.active.map do |gi|
|
||||
[gi.routing_rule&.left, gi.routing_rule&.right, gi]
|
||||
end
|
||||
end
|
||||
|
||||
def targeted_champ_tag(targeted_champ, row_index)
|
||||
select_tag(
|
||||
'targeted_champ',
|
||||
options_for_select(targeted_champs_for_select, selected: targeted_champ&.stable_id),
|
||||
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), selected: value),
|
||||
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, tdc.stable_id] }
|
||||
end
|
||||
|
||||
def available_values_for_select(targeted_champ)
|
||||
return [] if targeted_champ.nil?
|
||||
targeted_champ.options(@revision.types_de_champ_public)
|
||||
end
|
||||
|
||||
def values_for_select(targeted_champ)
|
||||
empty_target_for_select + available_values_for_select(targeted_champ)
|
||||
end
|
||||
|
||||
def input_id_for(name, row_index)
|
||||
"#{name}-#{row_index}"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
fr:
|
||||
select: Sélectionner
|
||||
apply_routing_rules: Appliquer des règles de routage
|
||||
routing_rules_notice: |
|
||||
Ajoutez des règles de routage à partir de champs créés dans le formulaire.
|
||||
Si les mêmes règles de routage sont appliquées à plusieurs groupes,
|
||||
les dossiers seront routés vers le premier groupe affiché dans la liste.
|
|
@ -0,0 +1,26 @@
|
|||
.card#routing-rules
|
||||
.card-title
|
||||
= t('.apply_routing_rules')
|
||||
%p.notice
|
||||
= t('.routing_rules_notice')
|
||||
.conditionnel.mt-2.width-100
|
||||
%table.condition-table.mt-2.width-100
|
||||
%thead
|
||||
%tr
|
||||
%th.far-left
|
||||
%th.target Champ cible du routage
|
||||
%th.operator Opérateur
|
||||
%th.value Valeur
|
||||
%th.delete-column
|
||||
.conditionnel.mt-2.width-100
|
||||
- rows.each.with_index do |(targeted_champ, value, groupe_instructeur), row_index|
|
||||
= form_tag admin_procedure_routing_rules_path, method: :post, class: 'form width-100' do
|
||||
%table.condition-table.mt-2.width-100
|
||||
%tbody
|
||||
%tr{ data: { controller: 'autosave' } }
|
||||
%td.far-left Router vers « #{groupe_instructeur.label} » si
|
||||
%td.target= targeted_champ_tag(targeted_champ, row_index)
|
||||
%td.operator Est égal à
|
||||
%td.value= value_tag(targeted_champ, value, row_index)
|
||||
%td.delete-column
|
||||
= hidden_groupe_instructeur_tag(groupe_instructeur.id)
|
|
@ -25,3 +25,7 @@
|
|||
= render partial: 'administrateurs/groupe_instructeurs/routing', locals: { procedure: @procedure }
|
||||
|
||||
= render partial: 'administrateurs/groupe_instructeurs/edit', locals: { procedure: @procedure, groupes_instructeurs: @groupes_instructeurs }
|
||||
|
||||
- if @procedure.routing_enabled?
|
||||
= render(Procedure::RoutingRulesComponent.new(revision: @procedure.active_revision,
|
||||
groupe_instructeurs: @procedure.groupe_instructeurs))
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
= turbo_stream.replace 'routing-rules', render(Procedure::RoutingRulesComponent.new(revision: @procedure.active_revision,
|
||||
groupe_instructeurs: @procedure.groupe_instructeurs))
|
Loading…
Reference in a new issue