mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Provide download link for generated reports
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
module Admin
|
||||
class ReportsController < Spree::Admin::BaseController
|
||||
include ActiveStorage::SetCurrent
|
||||
include ReportsActions
|
||||
helper ReportsHelper
|
||||
|
||||
@@ -59,16 +60,16 @@ module Admin
|
||||
if OpenFoodNetwork::FeatureToggle.enabled?(:background_reports, spree_current_user)
|
||||
filename = report_filename
|
||||
filename = "#{filename}html" if report_format.blank?
|
||||
blob = ReportBlob.create_for_upload_later!(filename)
|
||||
@blob = ReportBlob.create_for_upload_later!(filename)
|
||||
ReportJob.perform_later(
|
||||
report_class, spree_current_user, params, format, blob
|
||||
report_class, spree_current_user, params, format, @blob
|
||||
)
|
||||
Timeout.timeout(max_wait_time) do
|
||||
sleep 1 until blob.content_stored?
|
||||
sleep 1 until @blob.content_stored?
|
||||
end
|
||||
|
||||
# This result has been rendered by Rails in safe mode already.
|
||||
blob.result.html_safe # rubocop:disable Rails/OutputSafety
|
||||
@blob.result.html_safe # rubocop:disable Rails/OutputSafety
|
||||
else
|
||||
@report.render_as(format)
|
||||
end
|
||||
@@ -76,7 +77,13 @@ module Admin
|
||||
|
||||
def render_timeout_error
|
||||
assign_view_data
|
||||
@error = ".report_taking_longer"
|
||||
if @blob
|
||||
@error = ".report_taking_longer_html"
|
||||
@error_url = @blob.url
|
||||
else
|
||||
@error = ".report_taking_longer"
|
||||
@error_url = ""
|
||||
end
|
||||
render "show"
|
||||
end
|
||||
|
||||
|
||||
@@ -21,5 +21,5 @@
|
||||
- if request.post? && !@error
|
||||
%button.btn-print.icon-print{ onclick: "window.print()"}= t(:report_print)
|
||||
|
||||
= t(@error) if @error
|
||||
= t(@error, link: link_to(t(".report_link_label"), @error_url)) if @error
|
||||
= @table
|
||||
|
||||
@@ -1445,6 +1445,11 @@ en:
|
||||
Sorry, this report took too long to process.
|
||||
It may contain a lot of data or we are busy with other reports.
|
||||
You can try again later.
|
||||
report_taking_longer_html: >
|
||||
This report is taking longer to process.
|
||||
It may contain a lot of data or we are busy with other reports.
|
||||
Once it's finished, you can download it: %{link}
|
||||
report_link_label: Download report (when available)
|
||||
revenues_by_hub:
|
||||
name: Revenues By Hub
|
||||
description: Revenues by hub
|
||||
|
||||
@@ -45,7 +45,7 @@ describe '
|
||||
expect(page).to have_content "EMAIL FIRST NAME"
|
||||
end
|
||||
|
||||
it "displays a friendly timeout message" do
|
||||
it "displays a friendly timeout message and offers download" do
|
||||
ActiveJob::Base.queue_adapter.perform_enqueued_jobs = false
|
||||
login_as_admin_and_visit admin_report_path(
|
||||
report_type: :customers, report_subtype: :mailing_list
|
||||
@@ -55,7 +55,16 @@ describe '
|
||||
|
||||
click_button "Go"
|
||||
|
||||
expect(page).to have_content "this report took too long"
|
||||
expect(page).to have_content "report is taking longer"
|
||||
|
||||
perform_enqueued_jobs(only: ReportJob)
|
||||
|
||||
click_link "Download report"
|
||||
|
||||
expect(downloaded_filename).to match /customers_[0-9]+\.html/
|
||||
|
||||
content = File.read(downloaded_filename)
|
||||
expect(content).to match "<th>\nFirst Name\n</th>"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user