diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb index af09cfc77c..176b5c02cb 100644 --- a/app/controllers/admin/reports_controller.rb +++ b/app/controllers/admin/reports_controller.rb @@ -49,6 +49,7 @@ module Admin I18n.t(:name, scope: [:admin, :reports, @report_type]) end @rendering_options = rendering_options + @table = @report.to_html if request.post? @data = Reporting::FrontendData.new(spree_current_user) end end diff --git a/app/views/admin/reports/_table.html.haml b/app/views/admin/reports/_table.html.haml index 091d70e632..fce89c0ebd 100644 --- a/app/views/admin/reports/_table.html.haml +++ b/app/views/admin/reports/_table.html.haml @@ -1,5 +1,3 @@ -- report ||= @report - .report__table-container %table.report__table %thead diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 92de53506a..3447401a19 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -19,7 +19,4 @@ - if request.post? %button.btn-print.icon-print{ onclick: "window.print()"}= t(:report_print) -/ We don't want to render data unless search params are supplied. -/ Compiling data can take a long time. -- if request.post? - = render "table" += @table diff --git a/lib/reporting/report_renderer.rb b/lib/reporting/report_renderer.rb index 29afa5dd39..c58917a5ae 100644 --- a/lib/reporting/report_renderer.rb +++ b/lib/reporting/report_renderer.rb @@ -46,6 +46,14 @@ module Reporting public_send("to_#{target_format}") end + def to_html(layout: nil) + ApplicationController.render( + template: "admin/reports/_table", + layout: layout, + locals: { report: @report } + ) + end + def to_csv SpreadsheetArchitect.to_csv(headers: table_headers, data: table_rows) end @@ -55,11 +63,7 @@ module Reporting end def to_pdf - html = ApplicationController.render( - template: "admin/reports/_table", - layout: "pdf", - locals: { report: @report } - ) + html = to_html(layout: "pdf") WickedPdf.new.pdf_from_string(html) end diff --git a/lib/reporting/report_template.rb b/lib/reporting/report_template.rb index 9c2cc3fe00..bbac0727e8 100644 --- a/lib/reporting/report_template.rb +++ b/lib/reporting/report_template.rb @@ -5,7 +5,7 @@ module Reporting include ReportsHelper attr_accessor :user, :params, :ransack_params - delegate :render_as, :as_json, :to_csv, :to_xlsx, :to_pdf, :to_json, to: :renderer + delegate :render_as, :as_json, :to_html, :to_csv, :to_xlsx, :to_pdf, :to_json, to: :renderer delegate :raw_render?, :html_render?, :display_header_row?, :display_summary_row?, to: :renderer delegate :rows, :table_rows, :grouped_data, to: :rows_builder