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) def cast_bool(value)
ActiveRecord::Type::Boolean.new.deserialize(value) ActiveRecord::Type::Boolean.new.deserialize(value)
end end
def retrieve_procedure_presentation
@procedure_presentation ||= current_instructeur.procedure_presentation_for_procedure_id(params[:procedure_id])
end
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 module Instructeurs
class CommentairesController < ApplicationController class CommentairesController < ApplicationController
include InstructeurConcern
before_action :authenticate_instructeur_or_expert! before_action :authenticate_instructeur_or_expert!
after_action :mark_messagerie_as_read after_action :mark_messagerie_as_read
def destroy def destroy
retrieve_procedure_presentation if current_instructeur
if commentaire.sent_by?(current_instructeur) || commentaire.sent_by?(current_expert) if commentaire.sent_by?(current_instructeur) || commentaire.sent_by?(current_expert)
commentaire.soft_delete! commentaire.soft_delete!

View file

@ -7,15 +7,16 @@ module Instructeurs
include CreateAvisConcern include CreateAvisConcern
include DossierHelper include DossierHelper
include TurboChampsConcern include TurboChampsConcern
include InstructeurConcern
include ActionController::Streaming include ActionController::Streaming
include Zipline include Zipline
before_action :redirect_on_dossier_not_found, only: :show 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 :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] 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_messagerie_as_read, only: [:messagerie, :create_commentaire, :pending_correction]
after_action :mark_avis_as_read, only: [:avis, :create_avis] after_action :mark_avis_as_read, only: [:avis, :create_avis]
after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations] after_action :mark_annotations_privees_as_read, only: [:annotations_privees, :update_annotations]
@ -391,20 +392,20 @@ module Instructeurs
end end
def next def next
navigate_throw_dossier_list do |cache| navigate_through_dossiers_list do |cache|
cache.next_dossier_id(from_id: params[:dossier_id]) cache.next_dossier_id(from_id: params[:dossier_id])
end end
end end
def previous def previous
navigate_throw_dossier_list do |cache| navigate_through_dossiers_list do |cache|
cache.previous_dossier_id(from_id: params[:dossier_id]) cache.previous_dossier_id(from_id: params[:dossier_id])
end end
end end
private private
def navigate_throw_dossier_list def navigate_through_dossiers_list
dossier = dossier_scope.find(params[:dossier_id]) dossier = dossier_scope.find(params[:dossier_id])
procedure_presentation = current_instructeur.procedure_presentation_for_procedure_id(dossier.procedure.id) procedure_presentation = current_instructeur.procedure_presentation_for_procedure_id(dossier.procedure.id)
cache = Cache::ProcedureDossierPagination.new(procedure_presentation:, statut: params[:statut]) 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" redirect_back fallback_location: instructeur_dossier_path(procedure_id: procedure.id, dossier_id: dossier.id, statut: params[:statut]), alert: "Une erreur est survenue"
end end
rescue ActiveRecord::RecordNotFound 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" redirect_to instructeur_procedure_path(procedure_id: procedure.id), alert: "Une erreur est survenue"
end end

View file

@ -3,4 +3,4 @@
= render Dossiers::MessageComponent.new(commentaire: @commentaire, connected_user: @commentaire.instructeur || @commentaire.expert) = render Dossiers::MessageComponent.new(commentaire: @commentaire, connected_user: @commentaire.instructeur || @commentaire.expert)
- if current_user.instructeur? && @commentaire.dossier_correction.present? - 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)], 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)]] } [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: } = render partial: 'instructeurs/dossiers/header_bottom', locals: { dossier:, gallery_attachments: }
.fr-container .fr-container

View file

@ -1,14 +1,9 @@
#header-top.fr-container #header-top.fr-container
.flex = render Instructeurs::DossiersNavigationComponent.new(dossier:, procedure_presentation:, statut: params[:statut])
.flex.fr-mb-3w
%div %div
.flex.fr-mb-1w .fr-mt-2w.badge-group
= 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
= procedure_badge(dossier.procedure) = procedure_badge(dossier.procedure)
= status_badge(dossier.state) = status_badge(dossier.state)

View file

@ -1,6 +1,6 @@
- content_for(:title, "Annotations privées · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") - 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 #dossier-annotations-privees
.fr-container .fr-container

View file

@ -1,6 +1,6 @@
- content_for(:title, "Avis · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") - 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 .container
.fr-grid-row .fr-grid-row

View file

@ -1,6 +1,6 @@
- content_for(:title, "Avis · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") - 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 .container
.fr-grid-row .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})") - 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]) } = 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})") - 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 .personnes-impliquees.container
= render partial: 'instructeurs/dossiers/envoyer_dossier_block', locals: { dossier: @dossier, potential_recipients: @potential_recipients } = 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") - 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 .fr-container
.gallery.gallery-pieces-jointes{ "data-controller": "lightbox" } .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})") - 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 .container.groupe-instructeur

View file

@ -1,6 +1,6 @@
- content_for(:title, "Demande · Dossier nº #{@dossier.id} (#{@dossier.owner_name})") - 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? - if @dossier.etablissement&.as_degraded_mode?

View file

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

View file

@ -3,12 +3,15 @@
describe 'instructeurs/dossiers/show', type: :view do describe 'instructeurs/dossiers/show', type: :view do
let(:current_instructeur) { create(:instructeur) } let(:current_instructeur) { create(:instructeur) }
let(:dossier) { create(:dossier, :en_construction) } let(:dossier) { create(:dossier, :en_construction) }
let(:statut) { { statut: 'tous' } }
let(:procedure_presentation) { double(instructeur: current_instructeur, procedure: dossier.procedure) }
before do before do
sign_in(current_instructeur.user) sign_in(current_instructeur.user)
allow(view).to receive(:current_instructeur).and_return(current_instructeur) 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(:dossier, dossier)
assign(:procedure_presentation, procedure_presentation)
end end
subject { render } subject { render }
@ -17,6 +20,12 @@ describe 'instructeurs/dossiers/show', type: :view do
expect(subject).to have_text("Dossier nº #{dossier.id}") expect(subject).to have_text("Dossier nº #{dossier.id}")
end 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 it 'renders the dossier infos' do
expect(subject).to have_text('Identité') expect(subject).to have_text('Identité')
expect(subject).to have_text('Demande') expect(subject).to have_text('Demande')