diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index 2dc18e4092..10eeed407b 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -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 diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 4c93fc9977..0493dfd640 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index eb520908a0..df589a0d28 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 33a9cae152..a1e620ae07 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -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