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,7 +134,15 @@ module Instructeurs
end end
@dossier = dossier @dossier = dossier
redirect_back(fallback_location: instructeur_procedure_path(procedure)) 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 end
def repasser_en_construction def repasser_en_construction
@ -146,7 +154,15 @@ module Instructeurs
end end
@dossier = dossier @dossier = dossier
redirect_back(fallback_location: instructeur_procedure_path(procedure)) 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 end
def repasser_en_instruction def repasser_en_instruction
@ -158,7 +174,15 @@ module Instructeurs
end end
@dossier = dossier @dossier = dossier
redirect_back(fallback_location: instructeur_procedure_path(procedure)) 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 end
def terminer def terminer

View file

@ -6,7 +6,8 @@
archived: dossier.archived, archived: dossier.archived,
dossier_is_followed: current_instructeur&.follow?(dossier), dossier_is_followed: current_instructeur&.follow?(dossier),
close_to_expiration: dossier.close_to_expiration?, 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 %li.instruction-button
= render partial: "instruction_button", locals: { dossier: dossier } = 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 = 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') = t('views.instructeurs.dossiers.restore')
- elsif close_to_expiration || Dossier::TERMINE.include?(state) - elsif close_to_expiration || Dossier::TERMINE.include?(state)
%li %li{ 'data-turbo': 'true' }
- if close_to_expiration - if close_to_expiration
= link_to(repousser_expiration_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: "fr-btn") do = 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') = 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')) = 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 - 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 Repasser en instruction
= link_to( archive_instructeur_dossier_path(procedure_id, dossier_id), method: :patch, class: 'fr-btn fr-icon-folder-2-line') do = 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) - elsif Dossier::EN_CONSTRUCTION_OU_INSTRUCTION.include?(state)
- if Dossier.states[:en_construction] == state - if Dossier.states[:en_construction] == state
%li %li{ 'data-turbo': 'true' }
= 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 = 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 Passer en instruction
- elsif Dossier.states[:en_instruction] == state - elsif Dossier.states[:en_instruction] == state
%li %li{ 'data-turbo': 'true' }
= 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 = 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 Repasser en construction

View file

@ -180,7 +180,8 @@
archived: p.archived, archived: p.archived,
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: @statut == 'expirant', close_to_expiration: @statut == 'expirant',
hidden_by_administration: @statut == 'supprimes_recemment' } hidden_by_administration: @statut == 'supprimes_recemment',
post_method: { method: :post } }
%tfoot %tfoot
%tr %tr
%td.force-table-100{ colspan: @procedure_presentation.displayed_fields_for_headers.size + 2 }= paginate @filtered_sorted_paginated_ids %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, archived: p.archived,
dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id),
close_to_expiration: nil, close_to_expiration: nil,
hidden_by_administration: nil } hidden_by_administration: nil,
post_method: { method: :post } }
- else - else
%td %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(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
it { expect(instructeur.follow?(dossier)).to be true } it { expect(instructeur.follow?(dossier)).to be true }
it { expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) } it { expect(response).to have_http_status(:ok) }
it { expect(flash.notice).to eq("Dossier passé en instruction.") } it { expect(response.body).to include('.sub-header') }
context 'when the dossier has already been put en_instruction' do context 'when the dossier has already been put en_instruction' do
let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) } let(:dossier) { create(:dossier, :en_instruction, procedure: procedure) }
it 'warns about the error' do it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) expect(response).to have_http_status(:ok)
expect(flash.alert).to eq("Le dossier est déjà en instruction.") expect(response.body).to include('Le dossier est déjà en instruction.')
end end
end end
@ -174,8 +174,8 @@ describe Instructeurs::DossiersController, type: :controller do
end end
it 'warns about the error' do it 'warns about the error' do
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) expect(response).to have_http_status(:ok)
expect(flash.alert).to eq("Le dossier est en ce moment accepté : il nest pas possible de le passer en instruction.") expect(response.body).to include('Le dossier est en ce moment accepté : il nest pas possible de le passer en instruction.')
end end
end end
@ -199,16 +199,16 @@ describe Instructeurs::DossiersController, type: :controller do
end end
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) } 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(response).to have_http_status(:ok) }
it { expect(flash.notice).to eq("Dossier repassé en construction.") } it { expect(response.body).to include('.sub-header') }
context 'when the dossier has already been put en_construction' do context 'when the dossier has already been put en_construction' do
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) } let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
it 'warns about the error' do it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) expect(response).to have_http_status(:ok)
expect(flash.alert).to eq("Le dossier est déjà en construction.") expect(response.body).to include('Le dossier est déjà en construction.')
end end
end end
@ -235,8 +235,8 @@ describe Instructeurs::DossiersController, type: :controller do
context 'when the dossier is refuse' do context 'when the dossier is refuse' do
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) } 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(response).to have_http_status(:ok) }
it { expect(flash.notice).to eq("Le dossier #{dossier.id} a été repassé en instruction.") } it { expect(response.body).to include('.sub-header') }
end end
context 'when the dossier has already been put en_instruction' do 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 it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) expect(response).to have_http_status(:ok)
expect(flash.alert).to eq("Le dossier est déjà en instruction.") expect(response.body).to include('Le dossier est déjà en instruction.')
end end
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 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(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to redirect_to(instructeur_procedure_path(dossier.procedure)) expect(response).to have_http_status(:ok)
expect(flash.notice).to eq("Le dossier #{dossier.id} a été repassé en instruction.")
end end
end end
@ -314,7 +313,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.justificatif_motivation).to be_attached expect(dossier.justificatif_motivation).to be_attached
end end
it { expect(subject.body).to include('.header-actions') } it { expect(subject.body).to include('.sub-header') }
end end
context 'with dossier in batch_operation' do context 'with dossier in batch_operation' do
@ -354,7 +353,7 @@ describe Instructeurs::DossiersController, type: :controller do
subject subject
end end
it { expect(subject.body).to include('.header-actions') } it { expect(subject.body).to include('.sub-header') }
end end
context 'with attachment' do context 'with attachment' do
@ -368,7 +367,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.justificatif_motivation).to be_attached expect(dossier.justificatif_motivation).to be_attached
end end
it { expect(subject.body).to include('.header-actions') } it { expect(subject.body).to include('.sub-header') }
end end
end end
@ -410,14 +409,14 @@ describe Instructeurs::DossiersController, type: :controller do
end end
it 'The instructeur is sent back to the dossier page' do 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 end
context 'and the dossier has already an attestation' do context 'and the dossier has already an attestation' do
it 'should not crash' do it 'should not crash' do
dossier.attestation = Attestation.new dossier.attestation = Attestation.new
dossier.save dossier.save
expect(subject.body).to include('.header-actions') expect(subject.body).to include('.sub-header')
end end
end end
end end
@ -456,7 +455,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.justificatif_motivation).to be_attached expect(dossier.justificatif_motivation).to be_attached
end end
it { expect(subject.body).to include('.header-actions') } it { expect(subject.body).to include('.sub-header') }
end end
end end

View file

@ -39,7 +39,9 @@ describe 'Instructing a dossier:', js: true do
click_on 'Passer en instruction' 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 dossier.reload
expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction)) expect(dossier.state).to eq(Dossier.states.fetch(:en_instruction))