Class: RailsDbAdmin::ReportSupport
- Inherits:
-
QuerySupport
- Object
- QuerySupport
- RailsDbAdmin::ReportSupport
- Defined in:
- lib/rails_db_admin/report_support.rb
Instance Method Summary collapse
- #get_report_data(iid) ⇒ Object
-
#initialize ⇒ ReportSupport
constructor
A new instance of ReportSupport.
- #render_report(iid, format = :html) ⇒ Object
Methods inherited from QuerySupport
#delete_query, #execute_sql, #get_query, #get_saved_query_names, #save_query, #select_top_fifty
Constructor Details
#initialize ⇒ ReportSupport
Returns a new instance of ReportSupport.
7 8 9 |
# File 'lib/rails_db_admin/report_support.rb', line 7 def initialize() @connection = RailsDbAdmin::ConnectionHandler.create_connection_class(Rails.env).connection end |
Instance Method Details
#get_report_data(iid) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/rails_db_admin/report_support.rb', line 43 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 |
#render_report(iid, format = :html) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails_db_admin/report_support.rb', line 11 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 |