Module: QueryReport::Helper
- Defined in:
- lib/query_report/helper.rb
Instance Method Summary collapse
- #generate_csv_for_report(records) ⇒ Object
- #pdf_for_report(options) ⇒ Object
- #query_report_pdf_template_class(options) ⇒ Object
- #render_report(options) ⇒ Object
-
#reporter(query, options = {}, &block) ⇒ Object
Generates the reports.
- #send_pdf_email(email, subject, message, file_name, attachment) ⇒ Object
Instance Method Details
#generate_csv_for_report(records) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/query_report/helper.rb', line 64 def generate_csv_for_report(records) if records.size > 0 columns = records.first.keys CSV.generate do |csv| csv << columns records.each do |record| csv << record.values.collect { |val| val.kind_of?(String) ? view_context.strip_links(val) : val } end end else nil end end |
#pdf_for_report(options) ⇒ Object
51 52 53 |
# File 'lib/query_report/helper.rb', line 51 def pdf_for_report() query_report_pdf_template_class().new(@report).to_pdf.render end |
#query_report_pdf_template_class(options) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/query_report/helper.rb', line 55 def query_report_pdf_template_class() = QueryReport.config..merge() if [:template_class] @template_class ||= [:template_class].to_s.constantize return @template_class end QueryReport::ReportPdf end |
#render_report(options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/query_report/helper.rb', line 26 def render_report() if (params[:send_as_email].to_i > 0) send_pdf_email(params[:email_to], params[:subject], params[:message], action_name, pdf_for_report()) end @remote = false respond_to do |format| if [:custom_view] format.js do @remote = true end format.html else format.js do @remote = true render 'query_report/list' end format.html { render('query_report/list') } end format.json { render json: @report.all_records } format.csv { send_data generate_csv_for_report(@report.all_records), :disposition => "attachment;" } format.pdf { send_data pdf_for_report(), :type => 'application/pdf', :disposition => 'inline' } end end |
#reporter(query, options = {}, &block) ⇒ Object
Generates the reports
18 19 20 21 22 23 24 |
# File 'lib/query_report/helper.rb', line 18 def reporter(query, ={}, &block) @report ||= QueryReport::Report.new(params, view_context, ) @report.query = query @report.instance_eval &block render_report() unless [:skip_rendering] @report end |
#send_pdf_email(email, subject, message, file_name, attachment) ⇒ Object
78 79 80 81 82 |
# File 'lib/query_report/helper.rb', line 78 def send_pdf_email(email, subject, , file_name, ) @user = current_user if defined? current_user to = email.split(',') ReportMailer.send_report(@user, to, subject, , file_name, ).deliver end |