diff --git a/app/controllers/instructeurs/dossiers_controller.rb b/app/controllers/instructeurs/dossiers_controller.rb index 05b13ee05..f013c537a 100644 --- a/app/controllers/instructeurs/dossiers_controller.rb +++ b/app/controllers/instructeurs/dossiers_controller.rb @@ -134,7 +134,15 @@ module Instructeurs end @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 def repasser_en_construction @@ -146,7 +154,15 @@ module Instructeurs end @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 def repasser_en_instruction @@ -158,7 +174,15 @@ module Instructeurs end @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 def terminer diff --git a/app/views/instructeurs/dossiers/_header_actions.html.haml b/app/views/instructeurs/dossiers/_header_actions.html.haml index 0bbaec513..8ee89c31e 100644 --- a/app/views/instructeurs/dossiers/_header_actions.html.haml +++ b/app/views/instructeurs/dossiers/_header_actions.html.haml @@ -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 } diff --git a/app/views/instructeurs/dossiers/change_state.turbo_stream.haml b/app/views/instructeurs/dossiers/change_state.turbo_stream.haml index 94ce488db..4f0f74067 100644 --- a/app/views/instructeurs/dossiers/change_state.turbo_stream.haml +++ b/app/views/instructeurs/dossiers/change_state.turbo_stream.haml @@ -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 } diff --git a/app/views/instructeurs/procedures/_dossier_actions.html.haml b/app/views/instructeurs/procedures/_dossier_actions.html.haml index 314da655c..b4a954d3f 100644 --- a/app/views/instructeurs/procedures/_dossier_actions.html.haml +++ b/app/views/instructeurs/procedures/_dossier_actions.html.haml @@ -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 diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index 81a748055..4bb34f922 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -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 diff --git a/app/views/recherche/index.html.haml b/app/views/recherche/index.html.haml index 46aa5b6ed..a5aaac223 100644 --- a/app/views/recherche/index.html.haml +++ b/app/views/recherche/index.html.haml @@ -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 diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index 9f85aff93..f46dd041c 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -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 n’est 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 n’est 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 diff --git a/spec/system/instructeurs/instruction_spec.rb b/spec/system/instructeurs/instruction_spec.rb index 6057189cb..43025324a 100644 --- a/spec/system/instructeurs/instruction_spec.rb +++ b/spec/system/instructeurs/instruction_spec.rb @@ -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))