fix(dossiers): pluck procedure information for user dossiers

This commit is contained in:
Paul Chavard 2023-07-24 16:48:05 +02:00
parent 1290cf5f29
commit 8cdedded45
4 changed files with 26 additions and 26 deletions

View file

@ -1,15 +1,7 @@
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
def initialize(procedures_for_select:)
@procedures_for_select = procedures_for_select
end
end

View file

@ -1,3 +1,3 @@
= form_with(url: dossiers_path(), method: :get ) do |f|
= form_with(url: dossiers_path, method: :get, data: { controller: 'autosubmit' } ) 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'
= f.select :procedure_id, options_for_select(@procedures_for_select, params[:procedure_id]), { prompt: t('.procedures.prompt') }, class: 'fr-select'

View file

@ -20,28 +20,35 @@ module Users
before_action :store_user_location!, only: :new
def index
dossiers = Dossier.includes(:procedure).order_by_updated_at
@all_dossiers = dossiers.visible_by_user + current_user.deleted_dossiers
@all_dossiers_uniq_procedures_count = @all_dossiers.map(&:procedure).pluck(:id).uniq.count
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?
dossiers = dossiers.where(procedures: { id: @procedure_id })
ordered_dossiers = ordered_dossiers.where(procedures: { id: @procedure_id })
deleted_dossiers = deleted_dossiers.where(procedures: { id: @procedure_id })
end
dossiers_visibles = dossiers.visible_by_user
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_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 = 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
@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])
@ -335,7 +342,8 @@ module Users
end
def recherche
@all_dossiers_uniq_procedures_count = 0
@procedures_for_select = nil
@search_terms = params[:q]
return redirect_to dossiers_path if @search_terms.blank?

View file

@ -19,9 +19,9 @@
= 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
- if @procedures_for_select.present?
.fr-col
= render Dossiers::UserProcedureFilterComponent.new(dossiers: @all_dossiers)
= 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') }