Merge pull request #9164 from demarches-simplifiees/after-routing-new-ux
ETQ administateur je peux filtrer les groupes d'instructeurs à configurer
This commit is contained in:
commit
751901fbc6
13 changed files with 87 additions and 21 deletions
|
@ -1,11 +1,12 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Procedure::GroupesManagementComponent < ApplicationComponent
|
||||
def initialize(procedure:, groupe_instructeurs:, query:)
|
||||
def initialize(procedure:, groupe_instructeurs:, query:, to_configure_filter:)
|
||||
@procedure = procedure
|
||||
@groupe_instructeurs = groupe_instructeurs
|
||||
@query = query
|
||||
@total = groupe_instructeurs.total_count
|
||||
@to_configure_filter = to_configure_filter
|
||||
end
|
||||
|
||||
def table_header
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
- content_for(:title, 'Groupes')
|
||||
%h1 Gestion des groupes
|
||||
|
||||
= render Procedure::GroupesSearchComponent.new(procedure: @procedure, query: @query, to_configure_count: @procedure.groupe_instructeurs.filter(&:routing_to_configure?).count)
|
||||
= render Procedure::GroupesSearchComponent.new(procedure: @procedure,
|
||||
query: @query,
|
||||
to_configure_count: @procedure.groupe_instructeurs.filter(&:routing_to_configure?).count,
|
||||
to_configure_filter: @to_configure_filter)
|
||||
|
||||
.fr-table.fr-table--no-caption.fr-table--layout-fixed.fr-mt-2w
|
||||
%table
|
||||
|
@ -21,8 +24,10 @@
|
|||
%span= gi.label
|
||||
- if gi.closed
|
||||
%p.fr-badge.fr-badge--info.fr-badge--sm.fr-ml-1w inactif
|
||||
- elsif gi.routing_to_configure?
|
||||
%p.fr-badge.fr-badge--warning.fr-badge--sm.fr-ml-1w à configurer
|
||||
- elsif gi.invalid_rule?
|
||||
%p.fr-badge.fr-badge--warning.fr-badge--sm.fr-ml-1w règle invalide
|
||||
- elsif gi.non_unique_rule?
|
||||
%p.fr-badge.fr-badge--warning.fr-badge--sm.fr-ml-1w règle déjà attribuée à #{gi.groups_with_same_rule}
|
||||
|
||||
%span.fr-mr-1w
|
||||
#{gi.dossiers.visible_by_administration.size}
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
class Procedure::GroupesSearchComponent < ApplicationComponent
|
||||
def initialize(procedure:, query:, to_configure_count:)
|
||||
@procedure, @query, @to_configure_count = procedure, query, to_configure_count
|
||||
def initialize(procedure:, query:, to_configure_count:, to_configure_filter:)
|
||||
@procedure = procedure
|
||||
@query = query
|
||||
@to_configure_count = to_configure_count
|
||||
@to_configure_filter = to_configure_filter
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def show_to_configure?
|
||||
@to_configure_count > 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
fr:
|
||||
to_configure_filter:
|
||||
one: "Filtrer %{count} groupe à configurer"
|
||||
other: "Filtrer les %{count} groupes à configurer"
|
|
@ -1,9 +1,20 @@
|
|||
= form_for admin_procedure_groupe_instructeurs_path(@procedure),
|
||||
method: :get do
|
||||
= form_with(url: admin_procedure_groupe_instructeurs_path(@procedure),
|
||||
method: :get) do
|
||||
#header-search.fr-search-bar.fr-mb-2w{ role: "search" }
|
||||
= label_tag :q, 'Rechercher par nom', class: 'fr-label'
|
||||
= text_field_tag :q, @query, class: 'fr-input', type: 'search', autocomplete: 'off', placeholder: 'Rechercher par nom'
|
||||
%button.fr-btn{ title: "Rechercher" } Rechercher
|
||||
- if @query.present?
|
||||
= link_to "Réinitialiser la recherche",
|
||||
admin_procedure_groupe_instructeurs_path(@procedure),
|
||||
class: 'fr-link'
|
||||
- if show_to_configure?
|
||||
.flex.align-baseline
|
||||
%ul.fr-btns-group.fr-btns-group--sm
|
||||
%li.fr-checkbox-group.fr-ml-1w.fr-py-1w
|
||||
.title.font-weight-bold.fr-mb-1w
|
||||
%span.fr-icon-filter-fill.fr-icon--sm.fr-mr-1w{ 'aria-hidden': 'true' }
|
||||
Filtre
|
||||
|
||||
- if @to_configure_count > 0
|
||||
%span #{ @to_configure_count } à configurer
|
||||
= check_box_tag :filter, '1', @to_configure_filter, data: { controller: 'autosubmit' }
|
||||
= label_tag :filter, t('.to_configure_filter', count: @to_configure_count)
|
||||
|
|
|
@ -31,8 +31,10 @@
|
|||
|
||||
.flex
|
||||
%p.fr-mb-1w.fr-mr-2w Routage
|
||||
- if @groupe_instructeur.routing_to_configure?
|
||||
%p.fr-mb-1w.fr-badge.fr-badge--warning.fr-badge--sm à configurer
|
||||
- if @groupe_instructeur.invalid_rule?
|
||||
%p.fr-mb-1w.fr-badge.fr-badge--warning.fr-badge--sm règle invalide
|
||||
- elsif @groupe_instructeur.non_unique_rule?
|
||||
%p.fr-mb-1w.fr-badge.fr-badge--warning.fr-badge--sm règle déjà attribuée à #{@groupe_instructeur.groups_with_same_rule}
|
||||
|
||||
.flex.align-baseline.fr-mb-1w
|
||||
.fr-mr-2w.no-wrap si le champ
|
||||
|
|
|
@ -393,6 +393,10 @@ module Administrateurs
|
|||
procedure.groupe_instructeurs
|
||||
end
|
||||
|
||||
if params[:filter] == '1'
|
||||
groupes = Kaminari.paginate_array(groupes.filter(&:routing_to_configure?))
|
||||
end
|
||||
|
||||
groupes
|
||||
.page(params[:page])
|
||||
.per(ITEMS_PER_PAGE)
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# procedure_id :bigint not null
|
||||
#
|
||||
class GroupeInstructeur < ApplicationRecord
|
||||
include Logic
|
||||
DEFAUT_LABEL = 'défaut'
|
||||
belongs_to :procedure, -> { with_discarded }, inverse_of: :groupe_instructeurs, optional: false
|
||||
has_many :assign_tos, dependent: :destroy
|
||||
|
@ -85,9 +86,26 @@ class GroupeInstructeur < ApplicationRecord
|
|||
end
|
||||
|
||||
def routing_to_configure?
|
||||
invalid_rule? || non_unique_rule?
|
||||
end
|
||||
|
||||
def invalid_rule?
|
||||
rule = routing_rule
|
||||
return true if !(rule.is_a?(Logic::Eq) && rule.left.is_a?(Logic::ChampValue) && rule.right.is_a?(Logic::Constant))
|
||||
!routing_rule_matches_tdc?
|
||||
return true if !routing_rule_matches_tdc?
|
||||
end
|
||||
|
||||
def non_unique_rule?
|
||||
return false if invalid_rule?
|
||||
routing_rule.in?(other_groupe_instructeurs.map(&:routing_rule))
|
||||
end
|
||||
|
||||
def groups_with_same_rule
|
||||
return if routing_rule.nil?
|
||||
other_groupe_instructeurs
|
||||
.filter { |gi| !gi.routing_rule.nil? && gi.routing_rule.right != empty && gi.routing_rule == routing_rule }
|
||||
.map(&:label)
|
||||
.join(', ')
|
||||
end
|
||||
|
||||
def other_groupe_instructeurs
|
||||
|
|
|
@ -2,7 +2,7 @@ module RoutingEngine
|
|||
def self.compute(dossier)
|
||||
return if dossier.forced_groupe_instructeur
|
||||
|
||||
matching_groupe = dossier.procedure.groupe_instructeurs.active.reject(&:routing_to_configure?).find do |gi|
|
||||
matching_groupe = dossier.procedure.groupe_instructeurs.active.reject(&:invalid_rule?).find do |gi|
|
||||
gi.routing_rule&.compute(dossier.champs)
|
||||
end
|
||||
matching_groupe ||= dossier.procedure.defaut_groupe_instructeur
|
||||
|
|
|
@ -11,4 +11,7 @@
|
|||
available_instructeur_emails: @available_instructeur_emails,
|
||||
disabled_as_super_admin: administrateur_as_manager?)
|
||||
- else
|
||||
= render Procedure::GroupesManagementComponent.new(procedure: @procedure, groupe_instructeurs: @groupes_instructeurs, query: params[:q])
|
||||
= render Procedure::GroupesManagementComponent.new(procedure: @procedure,
|
||||
groupe_instructeurs: @groupes_instructeurs,
|
||||
query: params[:q],
|
||||
to_configure_filter: params[:filter].present?)
|
||||
|
|
|
@ -23,7 +23,7 @@ describe Procedure::OneGroupeManagementComponent, type: :component do
|
|||
procedure.reload
|
||||
subject
|
||||
end
|
||||
it { expect(page).to have_text('à configurer') }
|
||||
it { expect(page).to have_text('règle invalide') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
|
||||
it do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include('à configurer')
|
||||
expect(response.body).to include('règle invalide')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -81,7 +81,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
|
||||
it do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).not_to include('à configurer')
|
||||
expect(response.body).not_to include('règle invalide')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -96,7 +96,7 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
|
||||
it do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include('à configurer')
|
||||
expect(response.body).to include('règle invalide')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,7 +36,7 @@ describe 'The routing with rules', js: true do
|
|||
|
||||
expect(page).to have_text('Gestion des groupes')
|
||||
expect(page).to have_text('3 groupes')
|
||||
expect(page).not_to have_text('À configurer')
|
||||
expect(page).not_to have_text('à configurer')
|
||||
|
||||
click_on 'littéraire'
|
||||
expect(page).to have_select("targeted_champ", selected: "Spécialité")
|
||||
|
@ -49,13 +49,14 @@ describe 'The routing with rules', js: true do
|
|||
expect(page).to have_select("value", selected: "scientifique")
|
||||
end
|
||||
|
||||
scenario 'Routage personnalisé' do
|
||||
scenario 'Routage avancé' do
|
||||
steps_to_routing_configuration
|
||||
|
||||
choose('Avancé', allow_label_click: true)
|
||||
click_on 'Continuer'
|
||||
|
||||
expect(page).to have_text('Gestion des groupes')
|
||||
expect(page).to have_text('règle invalide')
|
||||
|
||||
# update defaut groupe
|
||||
click_on 'défaut'
|
||||
|
@ -112,9 +113,16 @@ describe 'The routing with rules', js: true do
|
|||
|
||||
click_on 'littéraire'
|
||||
|
||||
within('.target') { select('Spécialité') }
|
||||
within('.value') { select('scientifique') }
|
||||
|
||||
expect(page).to have_text('règle déjà attribuée à scientifique')
|
||||
|
||||
within('.target') { select('Spécialité') }
|
||||
within('.value') { select('littéraire') }
|
||||
|
||||
expect(page).not_to have_text('règle déjà attribuée à scientifique')
|
||||
|
||||
procedure.groupe_instructeurs.where(closed: false).each { |gi| wait_until { gi.reload.routing_rule.present? } }
|
||||
|
||||
# add a group without routing rules
|
||||
|
|
Loading…
Reference in a new issue