Merge pull request #10602 from demarches-simplifiees/fix-routing-fields-list
Correctif : ouvre l‘assistant de routage à tous les types de champ conditionnables
This commit is contained in:
commit
337eaff3f0
9 changed files with 68 additions and 20 deletions
|
@ -4,7 +4,7 @@ fr:
|
|||
Le routage permet d’acheminer les dossiers vers différents groupes d’instructeurs.
|
||||
routing_configuration_notice_2_html: |
|
||||
<p>Pour le configurer, votre formulaire doit comporter
|
||||
au moins un champ de type « choix simple », « communes », « epci », « départements » ou « régions ».</p>
|
||||
au moins un champ de type %{conditionable_types}.</p>
|
||||
<p>Ajoutez ce champ dans la page <a href="%{path}">« Configuration des champs »</a>.</p>
|
||||
delete_title: Aucun dossier ne sera supprimé. Les groupes d'instructeurs vont être supprimés. Seuls les instructeurs du groupe « %{defaut_label} » resteront affectés à la démarche.
|
||||
delete_confirmation: |
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
ROUTAGE_URL,
|
||||
title: t('.routage_doc.title'),
|
||||
**helpers.external_link_attributes)
|
||||
- if @procedure.active_revision.routable_types_de_champ.none?
|
||||
%p.fr-mt-2w= t('.routing_configuration_notice_2_html', path: champs_admin_procedure_path(@procedure))
|
||||
- if @procedure.active_revision.conditionable_types_de_champ.none?
|
||||
%p.fr-mt-2w= t('.routing_configuration_notice_2_html', path: champs_admin_procedure_path(@procedure), conditionable_types: TypeDeChamp.humanized_conditionable_types)
|
||||
- elsif @procedure.groupe_instructeurs.active.one?
|
||||
= link_to 'Configurer le routage', options_admin_procedure_groupe_instructeurs_path(@procedure, state: :choix), class: 'fr-btn'
|
||||
|
||||
|
|
|
@ -25,6 +25,9 @@ module Administrateurs
|
|||
|
||||
def options
|
||||
@procedure = procedure
|
||||
if params[:state] == 'choix' && @procedure.active_revision.simple_routable_types_de_champ.none?
|
||||
configurate_routage_custom
|
||||
end
|
||||
end
|
||||
|
||||
def ajout
|
||||
|
@ -41,7 +44,7 @@ module Administrateurs
|
|||
@procedure = procedure
|
||||
stable_id = params[:create_simple_routing][:stable_id].to_i
|
||||
|
||||
tdc = @procedure.active_revision.routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }
|
||||
tdc = @procedure.active_revision.simple_routable_types_de_champ.find { |tdc| tdc.stable_id == stable_id }
|
||||
|
||||
case tdc.type_champ
|
||||
when TypeDeChamp.type_champs.fetch(:departements)
|
||||
|
@ -86,18 +89,22 @@ module Administrateurs
|
|||
|
||||
def wizard
|
||||
if params[:choice][:state] == 'routage_custom'
|
||||
new_label = procedure.defaut_groupe_instructeur.label + ' bis'
|
||||
procedure.groupe_instructeurs
|
||||
.create({ label: new_label, instructeurs: [current_administrateur.instructeur] })
|
||||
|
||||
procedure.toggle_routing
|
||||
|
||||
redirect_to admin_procedure_groupe_instructeurs_path(procedure)
|
||||
configurate_routage_custom
|
||||
elsif params[:choice][:state] == 'routage_simple'
|
||||
redirect_to simple_routing_admin_procedure_groupe_instructeurs_path
|
||||
end
|
||||
end
|
||||
|
||||
def configurate_routage_custom
|
||||
new_label = procedure.defaut_groupe_instructeur.label + ' bis'
|
||||
procedure.groupe_instructeurs
|
||||
.create({ label: new_label, instructeurs: [current_administrateur.instructeur] })
|
||||
|
||||
procedure.toggle_routing
|
||||
|
||||
redirect_to admin_procedure_groupe_instructeurs_path(procedure)
|
||||
end
|
||||
|
||||
def destroy_all_groups_but_defaut
|
||||
reaffecter_all_dossiers_to_defaut_groupe
|
||||
procedure.groupe_instructeurs_but_defaut.each(&:destroy!)
|
||||
|
|
|
@ -265,8 +265,8 @@ class ProcedureRevision < ApplicationRecord
|
|||
[coordinate, coordinate&.type_de_champ]
|
||||
end
|
||||
|
||||
def routable_types_de_champ
|
||||
types_de_champ_public.filter(&:routable?)
|
||||
def simple_routable_types_de_champ
|
||||
types_de_champ_public.filter(&:simple_routable?)
|
||||
end
|
||||
|
||||
def conditionable_types_de_champ
|
||||
|
|
|
@ -110,7 +110,7 @@ class TypeDeChamp < ApplicationRecord
|
|||
expression_reguliere: 'expression_reguliere'
|
||||
}
|
||||
|
||||
ROUTABLE_TYPES = [
|
||||
SIMPLE_ROUTABLE_TYPES = [
|
||||
type_champs.fetch(:drop_down_list),
|
||||
type_champs.fetch(:communes),
|
||||
type_champs.fetch(:departements),
|
||||
|
@ -642,14 +642,20 @@ class TypeDeChamp < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def routable?
|
||||
type_champ.in?(ROUTABLE_TYPES)
|
||||
def simple_routable?
|
||||
type_champ.in?(SIMPLE_ROUTABLE_TYPES)
|
||||
end
|
||||
|
||||
def conditionable?
|
||||
Logic::ChampValue::MANAGED_TYPE_DE_CHAMP.values.include?(type_champ)
|
||||
end
|
||||
|
||||
def self.humanized_conditionable_types
|
||||
Logic::ChampValue::MANAGED_TYPE_DE_CHAMP.values.map do
|
||||
"« #{I18n.t(_1, scope: [:activerecord, :attributes, :type_de_champ, :type_champs])} »"
|
||||
end.to_sentence(last_word_connector: ' ou ')
|
||||
end
|
||||
|
||||
def invalid_regexp?
|
||||
self.errors.delete(:expression_reguliere)
|
||||
self.errors.delete(:expression_reguliere_exemple_text)
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
%div{ data: { 'action': "click->enable-submit-if-checked#click" } }
|
||||
.notice
|
||||
Sélectionner le champ à partir duquel créer des groupes d’instructeurs
|
||||
- buttons_content = @procedure.active_revision.routable_types_de_champ.map { |tdc| { label: tdc.libelle, value: tdc.stable_id } }
|
||||
- buttons_content = @procedure.active_revision.simple_routable_types_de_champ.map { |tdc| { label: tdc.libelle, value: tdc.stable_id } }
|
||||
= render Dsfr::RadioButtonListComponent.new(form: f,
|
||||
target: :stable_id,
|
||||
buttons: buttons_content)
|
||||
|
|
|
@ -793,6 +793,41 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#options' do
|
||||
context 'with a simple routable type de champ' do
|
||||
let!(:procedure) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: [
|
||||
{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }
|
||||
],
|
||||
administrateurs: [admin])
|
||||
end
|
||||
before { get :options, params: { procedure_id: procedure.id, state: 'choix' } }
|
||||
|
||||
it do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include('Choix du type de routage')
|
||||
expect(procedure.reload.routing_enabled).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a conditionable but not simple routable type de champ' do
|
||||
let!(:procedure) do
|
||||
create(:procedure,
|
||||
types_de_champ_public: [
|
||||
{ type: :integer_number }
|
||||
],
|
||||
administrateurs: [admin])
|
||||
end
|
||||
before { get :options, params: { procedure_id: procedure.id, state: 'choix' } }
|
||||
|
||||
it do
|
||||
expect(response).to redirect_to(admin_procedure_groupe_instructeurs_path(procedure))
|
||||
expect(procedure.reload.routing_enabled).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#create_simple_routing' do
|
||||
context 'with a drop_down_list type de champ' do
|
||||
let!(:procedure3) do
|
||||
|
|
|
@ -12,7 +12,7 @@ describe 're_routing_dossiers' do
|
|||
|
||||
dossier2.champs.last.update(value: 'Allier')
|
||||
|
||||
tdc = procedure.active_revision.routable_types_de_champ.first
|
||||
tdc = procedure.active_revision.simple_routable_types_de_champ.first
|
||||
|
||||
tdc_options = APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:code]] }
|
||||
|
||||
|
|
|
@ -1144,7 +1144,7 @@ describe ProcedureRevision do
|
|||
}
|
||||
end
|
||||
|
||||
describe '#routable_types_de_champ' do
|
||||
describe '#simple_routable_types_de_champ' do
|
||||
let(:procedure) do
|
||||
create(:procedure, types_de_champ_public: [
|
||||
{ type: :text, libelle: 'l1' },
|
||||
|
@ -1156,6 +1156,6 @@ describe ProcedureRevision do
|
|||
])
|
||||
end
|
||||
|
||||
it { expect(draft.routable_types_de_champ.pluck(:libelle)).to eq(['l2', 'l3', 'l4', 'l5', 'l6']) }
|
||||
it { expect(draft.simple_routable_types_de_champ.pluck(:libelle)).to eq(['l2', 'l3', 'l4', 'l5', 'l6']) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue