mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Remove report dependency on report controller
The ReportsController was referencing the report and the report was referencing the controller. It's unlikely that this circular dependency created a memory leak but it's generally a bad design. And we need to make the reporting independent of the controller to isolate it in a background job.
This commit is contained in:
@@ -31,7 +31,7 @@ module Admin
|
||||
private
|
||||
|
||||
def export_report
|
||||
send_data @report.render_as(report_format, controller: self), filename: report_filename
|
||||
send_data @report.render_as(report_format), filename: report_filename
|
||||
end
|
||||
|
||||
def render_report
|
||||
|
||||
@@ -38,30 +38,29 @@ module Reporting
|
||||
@report.rows.map(&:to_h).as_json
|
||||
end
|
||||
|
||||
def render_as(target_format, controller: nil)
|
||||
def render_as(target_format)
|
||||
unless target_format.to_sym.in?(REPORT_FORMATS)
|
||||
raise ActionController::BadRequest, "report_format should be in #{REPORT_FORMATS}"
|
||||
end
|
||||
|
||||
public_send("to_#{target_format}", controller)
|
||||
public_send("to_#{target_format}")
|
||||
end
|
||||
|
||||
def to_csv(_context_controller = nil)
|
||||
def to_csv
|
||||
SpreadsheetArchitect.to_csv(headers: table_headers, data: table_rows)
|
||||
end
|
||||
|
||||
def to_xlsx(_context_controller = nil)
|
||||
def to_xlsx
|
||||
SpreadsheetArchitect.to_xlsx(spreadsheets_options)
|
||||
end
|
||||
|
||||
def to_pdf(context_controller)
|
||||
WickedPdf.new.pdf_from_string(
|
||||
context_controller.render_to_string(
|
||||
template: 'admin/reports/_table',
|
||||
layout: 'pdf',
|
||||
locals: { report: @report }
|
||||
)
|
||||
def to_pdf
|
||||
html = ApplicationController.render(
|
||||
template: "admin/reports/_table",
|
||||
layout: "pdf",
|
||||
locals: { report: @report }
|
||||
)
|
||||
WickedPdf.new.pdf_from_string(html)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user