mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Display a friendly message when a report times out
Once we get a download link for a report, we can display this message sooner. But for now we just use the existing request timeout.
This commit is contained in:
@@ -26,6 +26,8 @@ module Admin
|
||||
else
|
||||
show_report
|
||||
end
|
||||
rescue Rack::Timeout::RequestTimeoutException
|
||||
render_timeout_error
|
||||
end
|
||||
|
||||
private
|
||||
@@ -36,6 +38,7 @@ module Admin
|
||||
|
||||
def show_report
|
||||
assign_view_data
|
||||
@table = render_report_as(:html) if render_data?
|
||||
render "show"
|
||||
end
|
||||
|
||||
@@ -45,7 +48,6 @@ module Admin
|
||||
@report_subtype = report_subtype
|
||||
@report_title = report_title
|
||||
@rendering_options = rendering_options
|
||||
@table = render_report_as(:html) if render_data?
|
||||
@data = Reporting::FrontendData.new(spree_current_user)
|
||||
end
|
||||
|
||||
@@ -66,5 +68,11 @@ module Admin
|
||||
@report.render_as(format)
|
||||
end
|
||||
end
|
||||
|
||||
def render_timeout_error
|
||||
assign_view_data
|
||||
@error = ".report_taking_longer"
|
||||
render "show"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
.report__header.print-hidden
|
||||
- if @report.message.present?
|
||||
%p.report__message= @report.message
|
||||
- if request.post?
|
||||
- if request.post? && !@error
|
||||
%button.btn-print.icon-print{ onclick: "window.print()"}= t(:report_print)
|
||||
|
||||
= t(@error) if @error
|
||||
= @table
|
||||
|
||||
@@ -1438,6 +1438,11 @@ en:
|
||||
pack_by_customer: Pack By Customer
|
||||
pack_by_supplier: Pack By Supplier
|
||||
pack_by_product: Pack By Product
|
||||
show:
|
||||
report_taking_longer: >
|
||||
This report is taking longer to process.
|
||||
It may contain a lot of data or we are busy with other reports.
|
||||
You can try again later.
|
||||
revenues_by_hub:
|
||||
name: Revenues By Hub
|
||||
description: Revenues by hub
|
||||
|
||||
@@ -44,6 +44,19 @@ describe '
|
||||
click_button "Go"
|
||||
expect(page).to have_content "EMAIL FIRST NAME"
|
||||
end
|
||||
|
||||
it "displays a friendly timeout message" do
|
||||
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = false
|
||||
login_as_admin_and_visit admin_report_path(
|
||||
report_type: :customers, report_subtype: :mailing_list
|
||||
)
|
||||
expect_any_instance_of(Admin::ReportsController).to receive(:sleep).
|
||||
and_raise(Rack::Timeout::RequestTimeoutException.new(nil))
|
||||
|
||||
click_button "Go"
|
||||
|
||||
expect(page).to have_content "This report is taking longer to process."
|
||||
end
|
||||
end
|
||||
|
||||
describe "Can access Customers reports and generate customers report" do
|
||||
|
||||
Reference in New Issue
Block a user