paginate only dossiers that we display to fix empty tabs when not on page 1

This commit is contained in:
Lisa Durand 2023-04-26 11:05:15 +02:00
parent e393132fd8
commit 74b28a995f
2 changed files with 29 additions and 12 deletions

View file

@ -17,18 +17,35 @@ module Users
before_action :store_user_location!, only: :new
def index
dossiers = Dossier.includes(:procedure).order_by_updated_at.page(page)
dossiers = Dossier.includes(:procedure).order_by_updated_at
dossiers_visibles = 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_close_to_expiration = current_user.dossiers.close_to_expiration.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.order_by_updated_at.page(page)
@dossier_transfers = DossierTransfer.for_email(current_user.email).page(page)
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.order_by_updated_at
@dossier_transfers = DossierTransfer.for_email(current_user.email)
@dossiers_close_to_expiration = current_user.dossiers.close_to_expiration.merge(dossiers_visibles)
@statut = statut(@user_dossiers, @dossiers_traites, @dossiers_invites, @dossiers_supprimes_recemment, @dossiers_supprimes_definitivement, @dossier_transfers, @dossiers_close_to_expiration, params[:statut])
@dossiers = case @statut
when 'en-cours'
@user_dossiers
when 'traites'
@dossiers_traites
when 'dossiers-invites'
@dossiers_invites
when 'dossiers-supprimes-recemment'
@dossiers_supprimes_recemment
when 'dossiers-supprimes-definitivement'
@dossiers_supprimes_definitivement
when 'dossiers-transferes'
@dossier_transfers
when 'dossiers-expirant'
@dossiers_close_to_expiration
end.page(page)
@first_brouillon_recently_updated = current_user.dossiers.visible_by_user.brouillons_recently_updated.first
end

View file

@ -62,7 +62,7 @@
active: @statut == 'dossiers-transferes',
badge: number_with_html_delimiter(@dossier_transfers.count))
.container
.fr-container
- if @search_terms.present?
%h2.page-title Résultat de la recherche pour « #{@search_terms} »
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
@ -76,22 +76,22 @@
= t('users.dossiers.header.callout.first_brouillon_recently_updated_text', time_ago: time_ago_in_words(@first_brouillon_recently_updated.created_at), libelle: @first_brouillon_recently_updated.procedure.libelle )
= link_to t('users.dossiers.header.callout.first_brouillon_recently_updated_button'), modifier_dossier_path(@first_brouillon_recently_updated), class: 'fr-btn'
= render partial: "dossiers_list", locals: { dossiers: @user_dossiers }
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
- if @statut == "traites"
= render partial: "dossiers_list", locals: { dossiers: @dossiers_traites }
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
- if @statut == "dossiers-invites"
= render partial: "dossiers_list", locals: { dossiers: @dossiers_invites }
= render partial: "dossiers_list", locals: { dossiers: @dossiers }
- if @statut == "dossiers-supprimes-recemment"
= render partial: "hidden_dossiers_list", locals: { hidden_dossiers: @dossiers_supprimes_recemment }
= render partial: "hidden_dossiers_list", locals: { hidden_dossiers: @dossiers }
- if @statut == "dossiers-supprimes-definitivement"
= render partial: "deleted_dossiers_list", locals: { deleted_dossiers: @dossiers_supprimes_definitivement }
= render partial: "deleted_dossiers_list", locals: { deleted_dossiers: @dossiers }
- if @statut == "dossiers-transferes"
= render partial: "transfered_dossiers_list", locals: { dossier_transfers: @dossier_transfers }
= render partial: "transfered_dossiers_list", locals: { dossier_transfers: @dossiers }
- if @statut == "dossiers-expirant"
= render partial: "dossiers_list", locals: { dossiers: @dossiers_close_to_expiration }
= render partial: "dossiers_list", locals: { dossiers: @dossiers }