Merge pull request #10237 from mkllnk/report-rendering

Remove report dependency on report controller
This commit is contained in:
Filipe
2023-01-09 18:49:19 +00:00
committed by GitHub
2 changed files with 11 additions and 12 deletions

View File

@@ -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

View File

@@ -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