feat(Instructeurs#*): plugs next/prev dossier component on all required routes

This commit is contained in:
mfo 2024-11-29 11:56:34 +01:00
parent f993393eb2
commit eea5758753
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
18 changed files with 51 additions and 30 deletions

View file

@ -426,8 +426,4 @@ class ApplicationController < ActionController::Base
def cast_bool(value)
ActiveRecord::Type::Boolean.new.deserialize(value)
end
def retrieve_procedure_presentation
@procedure_presentation ||= current_instructeur.procedure_presentation_for_procedure_id(params[:procedure_id])
end
end

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
module InstructeurConcern
extend ActiveSupport::Concern
included do
def retrieve_procedure_presentation
@procedure_presentation ||= current_instructeur.procedure_presentation_for_procedure_id(params[:procedure_id])
end
end
end

View file

@ -2,10 +2,12 @@
module Instructeurs
class CommentairesController < ApplicationController
include InstructeurConcern
before_action :authenticate_instructeur_or_expert!
after_action :mark_messagerie_as_read
def destroy
retrieve_procedure_presentation if current_instructeur
if commentaire.sent_by?(current_instructeur) || commentaire.sent_by?(current_expert)
commentaire.soft_delete!

View file

@ -7,15 +7,16 @@ module Instructeurs
include CreateAvisConcern
include DossierHelper
include TurboChampsConcern
include InstructeurConcern
include ActionController::Streaming
include Zipline
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
before_action :retrieve_procedure_presentation, only: [:annotations_privees, :avis_new, :avis, :messagerie, :personnes_impliquees, :pieces_jointes, :reaffectation, :show, :dossier_labels, :passer_en_instruction, :repasser_en_construction, :repasser_en_instruction, :terminer, :pending_correction, :create_avis, :create_commentaire]
after_action :mark_demande_as_read, only: :show
after_action :mark_messagerie_as_read, only: [:messagerie, :create_commentaire, :pending_correction]
after_action :mark_avis_as_read, only: [:avis, :create_avis]
after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations]
@ -391,20 +392,20 @@ module Instructeurs
end
def next
navigate_throw_dossier_list do |cache|
navigate_through_dossiers_list do |cache|
cache.next_dossier_id(from_id: params[:dossier_id])
end
end
def previous
navigate_throw_dossier_list do |cache|
navigate_through_dossiers_list do |cache|
cache.previous_dossier_id(from_id: params[:dossier_id])
end
end
private
def navigate_throw_dossier_list
def navigate_through_dossiers_list
dossier = dossier_scope.find(params[:dossier_id])
procedure_presentation = current_instructeur.procedure_presentation_for_procedure_id(dossier.procedure.id)
cache = Cache::ProcedureDossierPagination.new(procedure_presentation:, statut: params[:statut])
@ -417,6 +418,10 @@ module Instructeurs
redirect_back fallback_location: instructeur_dossier_path(procedure_id: procedure.id, dossier_id: dossier.id, statut: params[:statut]), alert: "Une erreur est survenue"
end
rescue ActiveRecord::RecordNotFound
Sentry.capture_message(
"Navigation through dossier failed => ActiveRecord::RecordNotFound",
extra: { dossier_id: params[:dossier_id] }
)
redirect_to instructeur_procedure_path(procedure_id: procedure.id), alert: "Une erreur est survenue"
end

View file

@ -3,4 +3,4 @@
= render Dossiers::MessageComponent.new(commentaire: @commentaire, connected_user: @commentaire.instructeur || @commentaire.expert)
- if current_user.instructeur? && @commentaire.dossier_correction.present?
= turbo_stream.replace 'header-top', partial: 'instructeurs/dossiers/header_top', locals: { dossier: @commentaire.dossier }
= turbo_stream.replace 'header-top', partial: 'instructeurs/dossiers/header_top', locals: { dossier: @commentaire.dossier, procedure_presentation: @procedure_presentation }

View file

@ -10,7 +10,7 @@
locals: { steps: [[t('show_procedure', scope: [:layouts, :breadcrumb], libelle: dossier.procedure.libelle.truncate(22)), instructeur_procedure_path(dossier.procedure)],
[t('show_dossier', scope: [:layouts, :breadcrumb], dossier_id: dossier.id, owner_name: dossier.owner_name)]] }
= render partial: 'instructeurs/dossiers/header_top', locals: { dossier: }
= render partial: 'instructeurs/dossiers/header_top', locals: { dossier:, procedure_presentation: }
= render partial: 'instructeurs/dossiers/header_bottom', locals: { dossier:, gallery_attachments: }
.fr-container

View file

@ -1,14 +1,9 @@
#header-top.fr-container
.flex
= render Instructeurs::DossiersNavigationComponent.new(dossier:, procedure_presentation:, statut: params[:statut])
.flex.fr-mb-3w
%div
.flex.fr-mb-1w
= render Instructeurs::BackButtonComponent.new(to: instructeur_procedure_path(dossier.procedure, statut: params[:statut]))
%h1.fr-h3.fr-mb-1w
= t('show_dossier', scope: [:layouts, :breadcrumb], dossier_id: dossier.id, owner_name: dossier.owner_name)
= link_to dossier.procedure.libelle.truncate_words(10), instructeur_procedure_path(dossier.procedure), title: dossier.procedure.libelle, class: "fr-link"
.fr-mt-2w.fr-badge-group
.fr-mt-2w.badge-group
= procedure_badge(dossier.procedure)
= status_badge(dossier.state)

View file

@ -1,6 +1,6 @@
- content_for(:title, "Annotations privées · Dossier nº #{@dossier.id} (#{@dossier.owner_name})")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
#dossier-annotations-privees
.fr-container

View file

@ -1,6 +1,6 @@
- content_for(:title, "Avis · Dossier nº #{@dossier.id} (#{@dossier.owner_name})")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
.container
.fr-grid-row

View file

@ -1,6 +1,6 @@
- content_for(:title, "Avis · Dossier nº #{@dossier.id} (#{@dossier.owner_name})")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
.container
.fr-grid-row

View file

@ -1 +1 @@
= turbo_stream.replace 'header-top', partial: 'header_top', locals: { dossier: @dossier }
= turbo_stream.replace 'header-top', partial: 'header_top', locals: { dossier: @dossier, procedure_presentation: @procedure_presentation }

View file

@ -1,5 +1,5 @@
- content_for(:title, "Messagerie · Dossier nº #{@dossier.id} (#{@dossier.owner_name})")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
= render partial: "shared/dossiers/messagerie", locals: { dossier: @dossier, connected_user: current_instructeur, messagerie_seen_at: @messagerie_seen_at , new_commentaire: @commentaire, form_url: commentaire_instructeur_dossier_path(@dossier.procedure, @dossier, statut: params[:statut]) }

View file

@ -1,6 +1,6 @@
- content_for(:title, "Personnes impliquées · Dossier nº #{@dossier.id} (#{@dossier.owner_name})")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
.personnes-impliquees.container
= render partial: 'instructeurs/dossiers/envoyer_dossier_block', locals: { dossier: @dossier, potential_recipients: @potential_recipients }

View file

@ -1,6 +1,6 @@
- content_for(:title, "Pièces jointes")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
.fr-container
.gallery.gallery-pieces-jointes{ "data-controller": "lightbox" }

View file

@ -1,6 +1,6 @@
- content_for(:title, "Réaffectation · Dossier nº #{@dossier.id} (#{@dossier.owner_name})")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
.container.groupe-instructeur

View file

@ -1,6 +1,6 @@
- content_for(:title, "Demande · Dossier nº #{@dossier.id} (#{@dossier.owner_name})")
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments }
= render partial: "header", locals: { dossier: @dossier, gallery_attachments: @gallery_attachments, procedure_presentation: @procedure_presentation }
- if @dossier.etablissement&.as_degraded_mode?

View file

@ -3,12 +3,15 @@
describe 'instructeurs/dossiers/annotations_privees', type: :view do
let(:current_instructeur) { create(:instructeur) }
let(:dossier) { create(:dossier, :en_construction) }
let(:procedure_presentation) { double(instructeur: current_instructeur, procedure: dossier.procedure) }
before do
sign_in(current_instructeur.user)
allow(view).to receive(:current_instructeur).and_return(current_instructeur)
allow(controller).to receive(:params).and_return({ statut: 'a-suivre' })
assign(:dossier, dossier)
assign(:procedure_presentation, procedure_presentation)
end
subject { render }

View file

@ -3,12 +3,15 @@
describe 'instructeurs/dossiers/show', type: :view do
let(:current_instructeur) { create(:instructeur) }
let(:dossier) { create(:dossier, :en_construction) }
let(:statut) { { statut: 'tous' } }
let(:procedure_presentation) { double(instructeur: current_instructeur, procedure: dossier.procedure) }
before do
sign_in(current_instructeur.user)
allow(view).to receive(:current_instructeur).and_return(current_instructeur)
allow(controller).to receive(:params).and_return(statut: 'a-suivre')
allow(controller).to receive(:params).and_return(statut:)
assign(:dossier, dossier)
assign(:procedure_presentation, procedure_presentation)
end
subject { render }
@ -17,6 +20,12 @@ describe 'instructeurs/dossiers/show', type: :view do
expect(subject).to have_text("Dossier nº #{dossier.id}")
end
context 'when procedure statut / page was saved in session' do
it 'renders back button with saved state' do
expect(subject).to have_selector("a[href=\"#{instructeur_procedure_path(dossier.procedure, statut: statut)}\"]")
end
end
it 'renders the dossier infos' do
expect(subject).to have_text('Identité')
expect(subject).to have_text('Demande')