feat(routing): filter only groups to configure

This commit is contained in:
Eric Leroy-Terquem 2023-05-16 16:05:55 +02:00
parent b059e905cd
commit 1b5f3a67eb
6 changed files with 42 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -5,5 +5,17 @@
= text_field_tag :q, @query, class: 'fr-input', type: 'search', autocomplete: 'off', placeholder: 'Rechercher par nom'
%button.fr-btn{ title: "Rechercher" } Rechercher
- if @to_configure_count > 0
%span #{ @to_configure_count } à configurer
- if show_to_configure?
.flex.align-baseline
%ul.fr-btns-group.fr-btns-group--sm
- if @query.present?
%li= link_to "Réinialiser la recherche",
admin_procedure_groupe_instructeurs_path(@procedure),
class: 'fr-btn fr-btn--tertiary-no-outline'
- else
= form_with(url: admin_procedure_groupe_instructeurs_path(@procedure),
method: :get,
data: { controller: 'autosubmit' }) do |f|
.fr-checkbox-group.fr-ml-2w.fr-py-1w
= f.check_box :filter, checked: @filter_value
= f.label :filter, "#{ @to_configure_count } à configurer"

View file

@ -389,6 +389,13 @@ module Administrateurs
procedure
.groupe_instructeurs
.where('unaccent(label) ILIKE unaccent(?)', "%#{query}%")
elsif params[:filter] == '1'
Kaminari.paginate_array(
procedure
.groupe_instructeurs
.filter(&:routing_to_configure?)
)
else
procedure.groupe_instructeurs
end

View file

@ -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?)