Merge pull request #9338 from demarches-simplifiees/user-dashboard/add-filter-by-procedure-outside-tabs
[refonte usager] Tableau de bord - filtrer les dossiers par démarche
This commit is contained in:
commit
8febb3d236
10 changed files with 86 additions and 24 deletions
|
@ -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)
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
= t('.button.select_filters')
|
||||
#filters.fr-collapse.fr-translate__menu.fr-menu
|
||||
%ul.fr-menu__list.fr-p-3w
|
||||
= form_with(url: dossiers_path(), method: :get ) do |f|
|
||||
= form_with(url: dossiers_path, method: :get ) do |f|
|
||||
= f.hidden_field :statut, value: @statut
|
||||
= f.hidden_field :procedure_id, value: @procedure_id, id: nil
|
||||
|
||||
.fr-input-group
|
||||
= f.label :state, t('.legend.state'), class: 'fr-label'
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
class Dossiers::UserProcedureFilterComponent < ApplicationComponent
|
||||
include DossierHelper
|
||||
|
||||
def initialize(procedures_for_select:)
|
||||
@procedures_for_select = procedures_for_select
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
fr:
|
||||
procedures:
|
||||
label: Filter by procedure
|
||||
prompt: All procedures
|
|
@ -0,0 +1,4 @@
|
|||
fr:
|
||||
procedures:
|
||||
label: Filtrer par démarche
|
||||
prompt: Toutes les démarches
|
|
@ -0,0 +1,4 @@
|
|||
= form_with(url: dossiers_path, method: :get, data: { controller: 'autosubmit' } ) do |f|
|
||||
= f.label :procedure_id, t('.procedure.label'), class: 'sr-only'
|
||||
.fr-input-group
|
||||
= f.select :procedure_id, options_for_select(@procedures_for_select, params[:procedure_id]), { prompt: t('.procedures.prompt') }, class: 'fr-select'
|
|
@ -20,16 +20,36 @@ module Users
|
|||
before_action :store_user_location!, only: :new
|
||||
|
||||
def index
|
||||
dossiers = Dossier.includes(:procedure).order_by_updated_at
|
||||
dossiers_visibles = dossiers.visible_by_user
|
||||
ordered_dossiers = Dossier.includes(:procedure).order_by_updated_at
|
||||
deleted_dossiers = current_user.deleted_dossiers.includes(:procedure).order_by_updated_at
|
||||
|
||||
user_revisions = ProcedureRevision.where(dossiers: current_user.dossiers.visible_by_user)
|
||||
invite_revisions = ProcedureRevision.where(dossiers: current_user.dossiers_invites.visible_by_user)
|
||||
deleted_dossier_procedures = Procedure.where(id: deleted_dossiers.pluck(:procedure_id))
|
||||
all_dossier_procedures = Procedure.where(revisions: user_revisions.or(invite_revisions))
|
||||
|
||||
@procedures_for_select = all_dossier_procedures
|
||||
.or(deleted_dossier_procedures)
|
||||
.distinct(:procedure_id)
|
||||
.order(:libelle)
|
||||
.pluck(:libelle, :id)
|
||||
@procedure_id = params[:procedure_id]
|
||||
|
||||
if @procedure_id.present?
|
||||
ordered_dossiers = ordered_dossiers.where(procedures: { id: @procedure_id })
|
||||
deleted_dossiers = deleted_dossiers.where(procedures: { id: @procedure_id })
|
||||
end
|
||||
|
||||
dossiers_visibles = ordered_dossiers.visible_by_user
|
||||
|
||||
@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
|
||||
@dossiers_supprimes_recemment = current_user.dossiers.hidden_by_user.merge(ordered_dossiers)
|
||||
@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 = deleted_dossiers
|
||||
|
||||
@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
|
||||
|
@ -318,6 +338,8 @@ module Users
|
|||
end
|
||||
|
||||
def recherche
|
||||
@procedures_for_select = nil
|
||||
|
||||
@search_terms = params[:q]
|
||||
return redirect_to dossiers_path if @search_terms.blank?
|
||||
|
||||
|
|
|
@ -9,56 +9,62 @@
|
|||
.dossiers-headers.sub-header
|
||||
.fr-container
|
||||
%h1.page-title.fr-h2= t('views.users.dossiers.index.dossiers')
|
||||
|
||||
.fr-grid-row.fr-grid-row--gutters
|
||||
- if current_user.dossiers.count > 2 || current_user.dossiers_invites.count > 2
|
||||
#search-2.fr-search-bar.fr-search-bar--lg
|
||||
.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
|
||||
%button.fr-btn.fr-btn--sm
|
||||
= t('views.users.dossiers.search.simple')
|
||||
- if @procedures_for_select.present?
|
||||
.fr-col
|
||||
= render Dossiers::UserProcedureFilterComponent.new(procedures_for_select: @procedures_for_select)
|
||||
|
||||
- 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
|
||||
|
|
|
@ -50,9 +50,9 @@ describe 'user access to the list of their dossiers', js: true do
|
|||
let(:dossiers_per_page) { 2 }
|
||||
|
||||
scenario 'the user can navigate through the other pages' do
|
||||
expect(page).not_to have_content(dossier_en_instruction.procedure.libelle)
|
||||
expect(page).not_to have_link(dossier_en_instruction.procedure.libelle)
|
||||
page.click_link("Suivant")
|
||||
expect(page).to have_content(dossier_en_instruction.procedure.libelle)
|
||||
expect(page).to have_link(dossier_en_instruction.procedure.libelle)
|
||||
expect(page).to have_text('5 en cours')
|
||||
expect(page).to have_text('2 traités')
|
||||
end
|
||||
|
@ -256,4 +256,16 @@ describe 'user access to the list of their dossiers', js: true do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "filter by procedure" do
|
||||
context "when dossiers are on different procedures" do
|
||||
it "can filter by procedure" do
|
||||
expect(page).to have_text('5 en cours')
|
||||
expect(page).to have_text('2 traités')
|
||||
expect(page).to have_select('procedure_id', selected: 'Toutes les démarches')
|
||||
select dossier_brouillon.procedure.libelle, from: 'procedure_id'
|
||||
expect(page).to have_text('1 en cours')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,7 @@ describe 'users/dossiers/index', type: :view do
|
|||
assign(:dossiers, Kaminari.paginate_array(user_dossiers).page(1))
|
||||
assign(:statut, statut)
|
||||
assign(:filter, filter)
|
||||
assign(:all_dossiers_uniq_procedures_count, 0)
|
||||
render
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue