From c6ab05dcc5d1b8198090b9bfcf6c68fea625f142 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Fri, 13 Sep 2024 19:07:32 +0200 Subject: [PATCH] fix(gallery): display pieces_jointes tab if any attachments --- .../instructeurs/dossiers_controller.rb | 31 +++++++++++-------- .../dossiers/_header_bottom.html.haml | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index dec97f6d4..632eb1ac2 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -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 diff --git a/app/views/instructeurs/dossiers/_header_bottom.html.haml b/app/views/instructeurs/dossiers/_header_bottom.html.haml index 1af884845..76f64be42 100644 --- a/app/views/instructeurs/dossiers/_header_bottom.html.haml +++ b/app/views/instructeurs/dossiers/_header_bottom.html.haml @@ -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])