refactor(dossier): export to use turbo-poll

This commit is contained in:
Paul Chavard 2022-05-11 16:11:34 +02:00
parent e9b02642c5
commit e33022ffc7
5 changed files with 9 additions and 29 deletions

View file

@ -156,7 +156,7 @@ module Instructeurs
if export.ready? if export.ready?
respond_to do |format| respond_to do |format|
format.js do format.turbo_stream do
@procedure = procedure @procedure = procedure
@statut = export_options[:statut] @statut = export_options[:statut]
@dossiers_count = export.count @dossiers_count = export.count
@ -172,7 +172,7 @@ module Instructeurs
respond_to do |format| respond_to do |format|
notice_message = "Nous générons cet export. Veuillez revenir dans quelques minutes pour le télécharger." notice_message = "Nous générons cet export. Veuillez revenir dans quelques minutes pour le télécharger."
format.js do format.turbo_stream do
@procedure = procedure @procedure = procedure
@statut = export_options[:statut] @statut = export_options[:statut]
@dossiers_count = export.count @dossiers_count = export.count

View file

@ -1,24 +0,0 @@
<% if @can_download_dossiers %>
<% if @statut.present? %>
<%= render_to_element('.dossiers-export', partial: "dossiers_export", locals: { procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count }) %>
<% else %>
<%= render_to_element('.procedure-actions', partial: "download_dossiers", locals: { procedure: @procedure, exports: @exports }) %>
<% end %>
<% end %>
<% @exports.values.each do |exports| %>
<% if @statut.present? %>
<% export = exports[:statut][@statut] %>
<% if export && !export.ready? %>
<%= fire_event('export:update', { url: download_export_instructeur_procedure_path(@procedure, export_format: export.format, statut: export.statut, no_progress_notification: true) }.to_json) %>
<% end %>
<% else %>
<% exports[:time_span_type].values.each do |export| %>
<% if !export.ready? %>
<%= fire_event('export:update', { url: download_export_instructeur_procedure_path(@procedure, export_format: export.format, time_span_type: export.time_span_type, no_progress_notification: true) }.to_json) %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= render_flash %>

View file

@ -0,0 +1,3 @@
- if @can_download_dossiers
= turbo_stream.update_all '.dossiers-export' do
= render Dossiers::ExportComponent.new(procedure: @procedure, exports: @exports, statut: @statut, count: @dossiers_count)

View file

@ -355,6 +355,7 @@ Rails.application.routes.draw do
post 'add_filter' post 'add_filter'
get 'remove_filter' => 'procedures#remove_filter', as: 'remove_filter' get 'remove_filter' => 'procedures#remove_filter', as: 'remove_filter'
get 'download_export' get 'download_export'
post 'download_export'
get 'stats' get 'stats'
get 'email_notifications' get 'email_notifications'
patch 'update_email_notifications' patch 'update_email_notifications'

View file

@ -523,15 +523,15 @@ describe Instructeurs::ProceduresController, type: :controller do
end end
end end
context 'when the js format is used' do context 'when the turbo_stream format is used' do
before do before do
post :download_export, post :download_export,
params: { export_format: :csv, procedure_id: procedure.id }, params: { export_format: :csv, procedure_id: procedure.id },
format: :js format: :turbo_stream
end end
it 'responds in the correct format' do it 'responds in the correct format' do
expect(response.media_type).to eq('text/javascript') expect(response.media_type).to eq('text/vnd.turbo-stream.html')
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
end end
end end