Sha256: 3fc558560bbec23e17aab06a763acd072551f0a8a3c1108adc63c5d7ca0cafe9
Contents?: true
Size: 1.54 KB
Versions: 5
Compression:
Stored size: 1.54 KB
Contents
require 'fileutils' require 'csv' module RailsDbAdmin class ReportSupport < QuerySupport def initialize() @connection = RailsDbAdmin::ConnectionHandler.create_connection_class(Rails.env).connection end def render_report(iid, format=:html) report = Report.find_by_internal_identifier(iid.to_s) if report.nil? or report.query.nil? "Invalid Report, make sure report exists and query is valid" else data = get_report_data(iid) case format when :html ActionView::Base.new().render(:inline => report.template, :locals => {:unique_name => iid, :title => report.name, :columns => data[:columns], :rows => data[:rows]} ) when :pdf html = ActionView::Base.new().render(:inline => report.template, :locals => {:unique_name => iid, :title => report.name, :columns => data[:columns], :rows => data[:rows]} ) kit = PDFKit.new(html, :page_size => 'Letter') kit.to_pdf when :csv CSV.generate do |csv| csv << data[:columns] data[:rows].each do |row| csv << row.values end end end end end def get_report_data(iid) report = Report.find_by_internal_identifier(iid.to_s) columns, values = self.execute_sql(report.query) return {:columns => columns, :rows => values} end end #ReportSupport end #RailsDbAdmin
Version data entries
5 entries across 5 versions & 1 rubygems