From 8ed1e97ee14695d692f9b1d4de987ed2d18feb85 Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Wed, 19 Jul 2023 17:57:24 +0200 Subject: [PATCH] add filter by procedure for user for all tabs --- .../dossiers/user_filter_component.rb | 5 +-- .../user_filter_component.html.haml | 1 + .../user_procedure_filter_component.rb | 15 ++++++++ .../user_procedure_filter_component.en.yml | 3 ++ .../user_procedure_filter_component.fr.yml | 3 ++ .../user_procedure_filter_component.html.haml | 3 ++ app/controllers/users/dossiers_controller.rb | 15 +++++++- app/views/users/dossiers/index.html.haml | 36 +++++++++++-------- 8 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 app/components/dossiers/user_procedure_filter_component.rb create mode 100644 app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.en.yml create mode 100644 app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.fr.yml create mode 100644 app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.html.haml diff --git a/app/components/dossiers/user_filter_component.rb b/app/components/dossiers/user_filter_component.rb index 24061ec9a..acbb62b66 100644 --- a/app/components/dossiers/user_filter_component.rb +++ b/app/components/dossiers/user_filter_component.rb @@ -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) diff --git a/app/components/dossiers/user_filter_component/user_filter_component.html.haml b/app/components/dossiers/user_filter_component/user_filter_component.html.haml index a2aa06cdd..603eda044 100644 --- a/app/components/dossiers/user_filter_component/user_filter_component.html.haml +++ b/app/components/dossiers/user_filter_component/user_filter_component.html.haml @@ -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' diff --git a/app/components/dossiers/user_procedure_filter_component.rb b/app/components/dossiers/user_procedure_filter_component.rb new file mode 100644 index 000000000..176a39fee --- /dev/null +++ b/app/components/dossiers/user_procedure_filter_component.rb @@ -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 diff --git a/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.en.yml b/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.en.yml new file mode 100644 index 000000000..45c1425e5 --- /dev/null +++ b/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.en.yml @@ -0,0 +1,3 @@ +fr: + procedures: + prompt: All procedures diff --git a/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.fr.yml b/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.fr.yml new file mode 100644 index 000000000..cef208e21 --- /dev/null +++ b/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.fr.yml @@ -0,0 +1,3 @@ +fr: + procedures: + prompt: Toutes les démarches diff --git a/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.html.haml b/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.html.haml new file mode 100644 index 000000000..69f44a401 --- /dev/null +++ b/app/components/dossiers/user_procedure_filter_component/user_procedure_filter_component.html.haml @@ -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' diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 8f9fed8d8..26051c8ec 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -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 diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml index f3a56b745..04d35a736 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -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