fix(gallery): display pieces_jointes tab if any attachments

This commit is contained in:
Eric Leroy-Terquem 2024-09-13 19:07:32 +02:00
parent 4f42e00f4e
commit c6ab05dcc5
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
2 changed files with 19 additions and 14 deletions

View file

@ -13,6 +13,7 @@ module Instructeurs
before_action :redirect_on_dossier_not_found, only: :show
before_action :redirect_on_dossier_in_batch_operation, only: [:archive, :unarchive, :follow, :unfollow, :passer_en_instruction, :repasser_en_construction, :repasser_en_instruction, :terminer, :restore, :destroy, :extend_conservation]
before_action :set_gallery_attachments, only: [:show, :pieces_jointes, :annotations_privees, :avis, :messagerie, :personnes_impliquees, :reaffectation]
after_action :mark_demande_as_read, only: :show
after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire, :pending_correction]
@ -373,19 +374,6 @@ module Instructeurs
def pieces_jointes
@dossier = current_instructeur.dossiers.find(params[:dossier_id])
champs_attachments = @dossier
.champs
.filter { _1.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) }
.flat_map(&:piece_justificative_file)
commentaires_attachments = @dossier
.commentaires
.map(&:piece_jointe)
.map(&:attachments)
.flatten
@gallery_attachments = champs_attachments + commentaires_attachments
@pieces_jointes_seen_at = current_instructeur.follows.find_by(dossier: dossier)&.pieces_jointes_seen_at
end
@ -499,5 +487,22 @@ module Instructeurs
redirect_back(fallback_location: instructeur_dossier_path(procedure, dossier_in_batch))
end
end
def set_gallery_attachments
@dossier = current_instructeur.dossiers.find(params[:dossier_id])
champs_attachments = @dossier
.champs
.filter { _1.class.in?([Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp]) }
.flat_map(&:piece_justificative_file)
commentaires_attachments = @dossier
.commentaires
.map(&:piece_jointe)
.map(&:attachments)
.flatten
@gallery_attachments = champs_attachments + commentaires_attachments
end
end
end

View file

@ -7,7 +7,7 @@
instructeur_dossier_path(dossier.procedure, dossier),
notification: notifications_summary[:demande])
- if dossier.champs.map(&:piece_justificative_file).flatten.any?
- if @gallery_attachments.present?
= dynamic_tab_item(t('views.instructeurs.dossiers.tab_steps.attachments'),
pieces_jointes_instructeur_dossier_path(dossier.procedure, dossier),
notification: notifications_summary[:pieces_jointes])