add filter by procedure for user for all tabs

This commit is contained in:
Lisa Durand 2023-07-19 17:57:24 +02:00
parent 10d653359e
commit 8ed1e97ee1
8 changed files with 63 additions and 18 deletions

View file

@ -1,12 +1,13 @@
class Dossiers::UserFilterComponent < ApplicationComponent
include DossierHelper
def initialize(statut:, filter:)
def initialize(statut:, filter:, procedure_id:)
@statut = statut
@filter = filter
@procedure_id = procedure_id
end
attr_reader :statut, :filter
attr_reader :statut, :filter, :procedure_id
def render?
['en-cours', 'traites'].include?(@statut)

View file

@ -8,6 +8,7 @@
%ul.fr-menu__list.fr-p-3w
= form_with(url: dossiers_path(), method: :get ) do |f|
= f.hidden_field :statut, value: @statut
= f.hidden_field :procedure_id, value: @procedure_id
.fr-input-group
= f.label :state, t('.legend.state'), class: 'fr-label'

View file

@ -0,0 +1,15 @@
class Dossiers::UserProcedureFilterComponent < ApplicationComponent
include DossierHelper
def initialize(dossiers:)
@dossiers = dossiers
end
attr_reader :dossiers
def procedures_collection(dossiers)
dossiers.map do |dossier|
[dossier.procedure.libelle, dossier.procedure.id]
end.uniq
end
end

View file

@ -0,0 +1,3 @@
fr:
procedures:
prompt: All procedures

View file

@ -0,0 +1,3 @@
fr:
procedures:
prompt: Toutes les démarches

View file

@ -0,0 +1,3 @@
= form_with(url: dossiers_path(), method: :get ) do |f|
.fr-input-group
= f.select :procedure_id, options_for_select(procedures_collection(@dossiers), params[:procedure_id]), {prompt: t('.procedures.prompt')}, onchange: "this.form.submit();", class: 'fr-select'

View file

@ -22,14 +22,27 @@ module Users
def index
dossiers = Dossier.includes(:procedure).order_by_updated_at
dossiers_visibles = dossiers.visible_by_user
@all_dossiers = dossiers_visibles + current_user.deleted_dossiers
@all_dossiers_uniq_procedures_count = @all_dossiers.map(&:procedure).pluck(:id).uniq.count
@procedure_id = params[:procedure_id]
if @procedure_id.present?
dossiers = dossiers.where(procedures: { id: @procedure_id })
dossiers_visibles = dossiers.visible_by_user
end
@user_dossiers = current_user.dossiers.state_not_termine.merge(dossiers_visibles)
@dossiers_traites = current_user.dossiers.state_termine.merge(dossiers_visibles)
@dossiers_invites = current_user.dossiers_invites.merge(dossiers_visibles)
@dossiers_supprimes_recemment = current_user.dossiers.hidden_by_user.merge(dossiers)
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.includes(:procedure).order_by_updated_at
@dossier_transferes = dossiers_visibles.where(dossier_transfer_id: DossierTransfer.for_email(current_user.email).ids)
@dossiers_close_to_expiration = current_user.dossiers.close_to_expiration.merge(dossiers_visibles)
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.includes(:procedure).order_by_updated_at
if @procedure_id.present?
@dossiers_supprimes_definitivement = @dossiers_supprimes_definitivement.where(procedures: { id: @procedure_id })
end
@statut = statut(@user_dossiers, @dossiers_traites, @dossiers_invites, @dossiers_supprimes_recemment, @dossiers_supprimes_definitivement, @dossier_transferes, @dossiers_close_to_expiration, params[:statut])
@dossiers = case @statut

View file

@ -9,56 +9,62 @@
.dossiers-headers.sub-header
.fr-container
%h1.page-title.fr-h2= t('views.users.dossiers.index.dossiers')
- if current_user.dossiers.count > 2 || current_user.dossiers_invites.count > 2
#search-2.fr-search-bar.fr-search-bar--lg
= form_tag recherche_dossiers_path, method: :get, :role => "search", class: "flex width-100 fr-mb-5w" do
= label_tag "q", t('views.users.dossiers.search.search_file'), class: 'fr-label'
= text_field_tag "q", "#{@search_terms if @search_terms.present?}", placeholder: t('views.users.dossiers.search.search_file'), class: "fr-input"
%button.fr-btn
= t('views.users.dossiers.search.simple')
.fr-grid-row.fr-grid-row--gutters
- if current_user.dossiers.count > 2 || current_user.dossiers_invites.count > 2
.fr-col
#search-2.fr-search-bar
= form_tag recherche_dossiers_path, method: :get, :role => "search", class: "flex width-100 fr-mb-5w" do
= label_tag "q", t('views.users.dossiers.search.search_file'), class: 'fr-label'
= text_field_tag "q", "#{@search_terms if @search_terms.present?}", placeholder: t('views.users.dossiers.search.search_file'), class: "fr-input"
%button.fr-btn.fr-btn--sm
= t('views.users.dossiers.search.simple')
- if @all_dossiers_uniq_procedures_count > 1
.fr-col
= render Dossiers::UserProcedureFilterComponent.new(dossiers: @all_dossiers)
- if @search_terms.blank?
%nav.tabs{ role: 'navigation', 'aria-label': t('views.users.dossiers.secondary_menu') }
%ul
- if @user_dossiers.present?
= tab_item(t('pluralize.en_cours', count: @user_dossiers.count),
dossiers_path(statut: 'en-cours'),
dossiers_path(statut: 'en-cours', procedure_id: params[:procedure_id]),
active: @statut == 'en-cours',
badge: number_with_html_delimiter(@user_dossiers.count))
- if @dossiers_traites.present?
// TODO: when renaming this tab in "Terminé", update notify_near_deletion_to_user email wording accordingly.
= tab_item(t('pluralize.traites', count: @dossiers_traites.count),
dossiers_path(statut: 'traites'),
dossiers_path(statut: 'traites', procedure_id: params[:procedure_id]),
active: @statut == 'traites',
badge: number_with_html_delimiter(@dossiers_traites.count))
- if @dossiers_invites.present?
= tab_item(t('pluralize.dossiers_invites', count: @dossiers_invites.count),
dossiers_path(statut: 'dossiers-invites'),
dossiers_path(statut: 'dossiers-invites', procedure_id: params[:procedure_id]),
active: @statut == 'dossiers-invites',
badge: number_with_html_delimiter(@dossiers_invites.count))
- if @dossiers_close_to_expiration.count > 0
= tab_item(t('pluralize.dossiers_close_to_expiration', count: @dossiers_close_to_expiration.count),
dossiers_path(statut: 'dossiers-expirant'),
dossiers_path(statut: 'dossiers-expirant', procedure_id: params[:procedure_id]),
active: @statut == 'dossiers-expirant',
badge: number_with_html_delimiter(@dossiers_close_to_expiration.count))
- if @dossiers_supprimes_recemment.present?
= tab_item(t('pluralize.dossiers_supprimes_recemment', count: @dossiers_supprimes_recemment.count),
dossiers_path(statut: 'dossiers-supprimes-recemment'),
dossiers_path(statut: 'dossiers-supprimes-recemment', procedure_id: params[:procedure_id]),
active: @statut == 'dossiers-supprimes-recemment',
badge: number_with_html_delimiter(@dossiers_supprimes_recemment.count))
- if @dossiers_supprimes_definitivement.present?
= tab_item(t('pluralize.dossiers_supprimes_definitivement', count: @dossiers_supprimes_definitivement.count),
dossiers_path(statut: 'dossiers-supprimes-definitivement'),
dossiers_path(statut: 'dossiers-supprimes-definitivement', procedure_id: params[:procedure_id]),
active: @statut == 'dossiers-supprimes-definitivement',
badge: number_with_html_delimiter(@dossiers_supprimes_definitivement.count))
- if @dossier_transferes.present?
= tab_item(t('pluralize.dossiers_transferes', count: @dossier_transferes.count),
dossiers_path(statut: 'dossiers-transferes'),
dossiers_path(statut: 'dossiers-transferes', procedure_id: params[:procedure_id]),
active: @statut == 'dossiers-transferes',
badge: number_with_html_delimiter(@dossier_transferes.count))
@ -78,7 +84,7 @@
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
- else
= render Dossiers::UserFilterComponent.new(statut: @statut, filter: @filter)
= render Dossiers::UserFilterComponent.new(statut: @statut, filter: @filter, procedure_id: @procedure_id )
- if @statut == "dossiers-supprimes-definitivement"
-# /!\ in this context, @dossiers is a collection of DeletedDossier not Dossier