implement turbostream back for state change in dossier view

This commit is contained in:
Lisa Durand 2023-02-24 15:48:29 +01:00
parent b03748d3dd
commit 6487e2c27e
8 changed files with 64 additions and 36 deletions

View file

@ -134,8 +134,16 @@ module Instructeurs
end
@dossier = dossier
respond_to do |format|
format.turbo_stream do
render :change_state
end
format.html do
redirect_back(fallback_location: instructeur_procedure_path(procedure))
end
end
end
def repasser_en_construction
begin
@ -146,8 +154,16 @@ module Instructeurs
end
@dossier = dossier
respond_to do |format|
format.turbo_stream do
render :change_state
end
format.html do
redirect_back(fallback_location: instructeur_procedure_path(procedure))
end
end
end
def repasser_en_instruction
begin
@ -158,8 +174,16 @@ module Instructeurs
end
@dossier = dossier
respond_to do |format|
format.turbo_stream do
render :change_state
end
format.html do
redirect_back(fallback_location: instructeur_procedure_path(procedure))
end
end
end
def terminer
motivation = params[:dossier] && params[:dossier][:motivation]

View file

@ -6,7 +6,8 @@
archived: dossier.archived,
dossier_is_followed: current_instructeur&.follow?(dossier),
close_to_expiration: dossier.close_to_expiration?,
hidden_by_administration: dossier.hidden_by_administration? }
hidden_by_administration: dossier.hidden_by_administration?,
post_method: {data: { turbo_method: :post }}}
%li.instruction-button
= render partial: "instruction_button", locals: { dossier: dossier }

View file

@ -1 +1 @@
= turbo_stream.update_all '.header-actions', partial: 'header_actions', locals: { dossier: @dossier }
= turbo_stream.update_all '.sub-header', partial: 'header', locals: { dossier: @dossier }

View file

@ -3,7 +3,7 @@
= link_to restore_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: "fr-btn fr-icon-refresh-line" do
= t('views.instructeurs.dossiers.restore')
- elsif close_to_expiration || Dossier::TERMINE.include?(state)
%li
%li{ 'data-turbo': 'true' }
- if close_to_expiration
= link_to(repousser_expiration_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: "fr-btn") do
= t('instructeurs.dossiers.header.banner.button_delay_expiration')
@ -15,7 +15,7 @@
= link_to('', instructeur_dossier_path(procedure_id, dossier_id), method: :delete, class: 'fr-btn fr-btn--secondary fr-icon-delete-line icon-only danger', title: t('views.instructeurs.dossiers.delete_dossier'))
- else
= link_to(repasser_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-edit-line') do
= link_to repasser_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), { class: 'fr-btn fr-btn--secondary fr-icon-edit-line' }.deep_merge!(post_method) do
Repasser en instruction
= link_to( archive_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-icon-folder-2-line') do
@ -25,12 +25,12 @@
- elsif Dossier::EN_CONSTRUCTION_OU_INSTRUCTION.include?(state)
- if Dossier.states[:en_construction] == state
%li
= link_to passer_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-edit-line' do
%li{ 'data-turbo': 'true' }
= link_to passer_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), { class: 'fr-btn fr-btn--secondary fr-icon-edit-line' }.deep_merge!(post_method) do
Passer en instruction
- elsif Dossier.states[:en_instruction] == state
%li
= link_to repasser_en_construction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-draft-line' do
%li{ 'data-turbo': 'true' }
= link_to repasser_en_construction_instructeur_dossier_path(procedure_id, dossier_id), { class: 'fr-btn fr-btn--secondary fr-icon-draft-line' }.deep_merge!(post_method) do
Repasser en construction

View file

@ -180,7 +180,8 @@
archived: p.archived,
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: @statut == 'expirant',
hidden_by_administration: @statut == 'supprimes_recemment' }
hidden_by_administration: @statut == 'supprimes_recemment',
post_method: { method: :post } }
%tfoot
%tr
%td.force-table-100{ colspan: @procedure_presentation.displayed_fields_for_headers.size + 2 }= paginate @filtered_sorted_paginated_ids

View file

@ -97,7 +97,8 @@
archived: p.archived,
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: nil,
hidden_by_administration: nil }
hidden_by_administration: nil,
post_method: { method: :post } }
- else
%td

View file

@ -153,16 +153,16 @@ describe Instructeurs::DossiersController, type: :controller do
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
it { expect(instructeur.follow?(dossier)).to be true }
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) }
it { expect(flash.notice).to eq("Dossier passé en instruction.") }
it { expect(response).to have_http_status(:ok) }
it { expect(response.body).to include('.sub-header') }
context 'when the dossier has already been put en_instruction' do
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure))
expect(flash.alert).to eq("Le dossier est déjà en instruction.")
expect(response).to have_http_status(:ok)
expect(response.body).to include('Le dossier est déjà en instruction.')
end
end
@ -174,8 +174,8 @@ describe Instructeurs::DossiersController, type: :controller do
end
it 'warns about the error' do
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure))
expect(flash.alert).to eq("Le dossier est en ce moment accepté : il nest pas possible de le passer en instruction.")
expect(response).to have_http_status(:ok)
expect(response.body).to include('Le dossier est en ce moment accepté : il nest pas possible de le passer en instruction.')
end
end
@ -199,16 +199,16 @@ describe Instructeurs::DossiersController, type: :controller do
end
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) }
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) }
it { expect(flash.notice).to eq("Dossier repassé en construction.") }
it { expect(response).to have_http_status(:ok) }
it { expect(response.body).to include('.sub-header') }
context 'when the dossier has already been put en_construction' do
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure))
expect(flash.alert).to eq("Le dossier est déjà en construction.")
expect(response).to have_http_status(:ok)
expect(response.body).to include('Le dossier est déjà en construction.')
end
end
@ -235,8 +235,8 @@ describe Instructeurs::DossiersController, type: :controller do
context 'when the dossier is refuse' do
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) }
it { expect(flash.notice).to eq("Le dossier #{dossier.id} a été repassé en instruction.") }
it { expect(response).to have_http_status(:ok) }
it { expect(response.body).to include('.sub-header') }
end
context 'when the dossier has already been put en_instruction' do
@ -244,8 +244,8 @@ describe Instructeurs::DossiersController, type: :controller do
it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure))
expect(flash.alert).to eq("Le dossier est déjà en instruction.")
expect(response).to have_http_status(:ok)
expect(response.body).to include('Le dossier est déjà en instruction.')
end
end
@ -254,8 +254,7 @@ describe Instructeurs::DossiersController, type: :controller do
it 'it is possible to go back to en_instruction as instructeur' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure))
expect(flash.notice).to eq("Le dossier #{dossier.id} a été repassé en instruction.")
expect(response).to have_http_status(:ok)
end
end
@ -314,7 +313,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.justificatif_motivation).to be_attached
end
it { expect(subject.body).to include('.header-actions') }
it { expect(subject.body).to include('.sub-header') }
end
context 'with dossier in batch_operation' do
@ -354,7 +353,7 @@ describe Instructeurs::DossiersController, type: :controller do
subject
end
it { expect(subject.body).to include('.header-actions') }
it { expect(subject.body).to include('.sub-header') }
end
context 'with attachment' do
@ -368,7 +367,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.justificatif_motivation).to be_attached
end
it { expect(subject.body).to include('.header-actions') }
it { expect(subject.body).to include('.sub-header') }
end
end
@ -410,14 +409,14 @@ describe Instructeurs::DossiersController, type: :controller do
end
it 'The instructeur is sent back to the dossier page' do
expect(subject.body).to include('.header-actions')
expect(subject.body).to include('.sub-header')
end
context 'and the dossier has already an attestation' do
it 'should not crash' do
dossier.attestation = Attestation.new
dossier.save
expect(subject.body).to include('.header-actions')
expect(subject.body).to include('.sub-header')
end
end
end
@ -456,7 +455,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.justificatif_motivation).to be_attached
end
it { expect(subject.body).to include('.header-actions') }
it { expect(subject.body).to include('.sub-header') }
end
end

View file

@ -39,7 +39,9 @@ describe 'Instructing a dossier:', js: true do
click_on 'Passer en instruction'
expect(page).to have_text('en instruction')
expect(page).to have_text('Dossier passé en instruction.')
expect(page).to have_text('Instruire le dossier')
expect(page).to have_selector('.label.en-instruction')
dossier.reload
expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction))