Skip to content

Commit

Permalink
refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand committed Dec 19, 2023
1 parent 1541da9 commit e6a4459
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
30 changes: 7 additions & 23 deletions app/controllers/instructeurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def show
@not_archived_notifications_dossier_ids = notifications[:en_cours] + notifications[:termines]

@has_export_notification = notify_exports?
@has_last_export = last_export_for(@statut)
@last_export = last_export_for(statut)

@filtered_sorted_ids = procedure_presentation.filtered_sorted_ids(dossiers, statut, count: dossiers_count)

Expand Down Expand Up @@ -182,7 +182,7 @@ def download_export
@statut = export_options[:statut]
@dossiers_count = export.count

@has_last_export = last_export_for(@statut)
@last_export = last_export_for(@statut)

if export.available?
respond_to do |format|
Expand All @@ -209,28 +209,12 @@ def download_export
end

def polling_last_export
@has_last_export = last_export_for(params[:statut])
if @has_last_export.available?
respond_to do |format|
format.turbo_stream do
flash.notice = t('instructeurs.procedures.export_available_html', file_format: @has_last_export.format, file_url: @has_last_export.file.url)
end

format.html do
redirect_to url_from(@has_last_export.file.url)
end
end
@statut = statut
@last_export = last_export_for(@statut)
if @last_export.available?
flash.notice = t('instructeurs.procedures.export_available_html', file_format: @last_export.format, file_url: @last_export.file.url)
else
respond_to do |format|
format.turbo_stream do
if !params[:no_progress_notification]
flash.notice = t('instructeurs.procedures.export_pending_html', url: exports_instructeur_procedure_path(procedure))
end
end
format.html do
redirect_to exports_instructeur_procedure_path(procedure), notice: t('instructeurs.procedures.export_pending_html', url: exports_instructeur_procedure_path(procedure))
end
end
flash.notice = t('instructeurs.procedures.export_pending_html', url: exports_instructeur_procedure_path(procedure))
end
end

Expand Down
3 changes: 1 addition & 2 deletions app/views/instructeurs/procedures/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@
- if @has_export_notification
%span.notifications{ 'aria-label': t('instructeurs.dossiers.header.banner.exports_notification_label') }


#last-export-alert
= render partial: "last_export_alert"
= render partial: "last_export_alert", locals: { export: @last_export, statut: @statut }
14 changes: 7 additions & 7 deletions app/views/instructeurs/procedures/_last_export_alert.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
- if @has_last_export.present?
%div{ data: @has_last_export.pending? ? { controller: "turbo-poll", turbo_poll_url_value: polling_last_export_instructeur_procedure_path(export_format: @has_last_export.format, statut: @statut), turbo_poll_interval_value: 5_000, turbo_poll_max_checks_value: 6 } : {} }
- if export.present?
%div{ data: export.pending? ? { controller: "turbo-poll", turbo_poll_url_value: polling_last_export_instructeur_procedure_path(export_format: export.format, statut: statut), turbo_poll_interval_value: 5_000, turbo_poll_max_checks_value: 6 } : {} }
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: 'fr-my-2w') do |c|
- c.body do
%p
- if @has_last_export.pending?
- if export.pending?
= t('instructeurs.procedures.last_export_pending')
- if @has_last_export.generated?
= t('instructeurs.procedures.last_export_available_html', file_format: @has_last_export.format, file_url: @has_last_export.file.url)
- if @has_last_export.failed?
= t('instructeurs.procedures.last_export_failed', file_format: @has_last_export.format)
- if export.generated?
= t('instructeurs.procedures.last_export_available_html', file_format: export.format, file_url: export.file.url)
- if export.failed?
= t('instructeurs.procedures.last_export_failed', file_format: export.format)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
= render Dossiers::ExportDropdownComponent.new(procedure: @procedure, statut: @statut, count: @dossiers_count, export_url: method(:download_export_instructeur_procedure_path))

= turbo_stream.update "last-export-alert" do
= render partial: "last_export_alert"
= render partial: "last_export_alert", locals: { export: @last_export, statut: @statut }
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
= turbo_stream.update "last-export-alert" do
= render partial: "last_export_alert"
= render partial: "last_export_alert", locals: { export: @last_export, statut: @statut }
10 changes: 5 additions & 5 deletions spec/controllers/instructeurs/procedures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
subject
end

it { expect(assigns(:has_last_export)).to eq(export) }
it { expect(assigns(:last_export)).to eq(export) }
it { expect(response.body).to include("Votre dernier export est en cours de création") }
end

Expand All @@ -530,7 +530,7 @@
subject
end

it { expect(assigns(:has_last_export)).to eq(export) }
it { expect(assigns(:last_export)).to eq(export) }
it { expect(response.body).to include("Votre dernier export au format csv est prêt") }
end

Expand All @@ -542,7 +542,7 @@
subject
end

it { expect(assigns(:has_last_export)).to eq(export) }
it { expect(assigns(:last_export)).to eq(export) }
it { expect(response.body).to include("Votre dernier export au format csv n'a pas fonctionné") }
end

Expand All @@ -553,7 +553,7 @@
subject
end

it { expect(assigns(:has_last_export)).to eq(nil) }
it { expect(assigns(:last_export)).to eq(nil) }
end

context 'logged in with another instructeur' do
Expand All @@ -567,7 +567,7 @@
subject
end

it { expect(assigns(:has_last_export)).to eq(nil) }
it { expect(assigns(:last_export)).to eq(nil) }
end
end
end
Expand Down

0 comments on commit e6a4459

Please sign in to comment.