Class: OldSql::ReportController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/old_sql/report_controller.rb

Constant Summary collapse

BASE_PROCESSOR =
"base"

Instance Method Summary collapse

Instance Method Details

#chartObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/old_sql/report_controller.rb', line 59

def chart
  @start_date = params[:start_date]
  @end_date = params[:end_date]
  @report_name = params[:report]
  @report_sql = params[:report_sql].downcase
  @report_sql_orig = params[:report_sql].downcase

  @width = 800
  @height = 500
  @google_chart_colors = google_chart_colors

  processor = load_base_processor
  @report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))

  render :layout => 'old_sql/chart.html.erb', :template => "old_sql/report/chart.html.erb"
end

#indexObject



21
22
23
# File 'app/controllers/old_sql/report_controller.rb', line 21

def index
  @report_view = OldSql.default_report_view
end

#jqgridObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/old_sql/report_controller.rb', line 25

def jqgrid
  @start_date = params[:start_date]
  @end_date = params[:end_date]
  @report_name = params[:report]
  @report_sql = params[:report_sql]
  @query = params[:query]
  @db = params[:db]
  @caption = params[:caption] 
  w = params[:w]
  
  #todo allow these to be overridden in the report config
  @row_num = OldSql.jqgrid_row_num
  @width =  w.nil? ? OldSql.report_width : w
  @height = OldSql.report_height

  render :template => "old_sql/report/jqgrid.html.erb"
end


76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/old_sql/report_controller.rb', line 76

def print
  @start_date = params[:start_date]
  @end_date = params[:end_date]
  @report_name = params[:report]
  @desc = params[:desc]
  @report_sql = params[:report_sql].downcase
  @report_sql_orig = params[:report_sql].downcase

  processor = load_base_processor
  @report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))

  render :template => "old_sql/report/print.html.erb"
end

#queryObject

ajax call



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/controllers/old_sql/report_controller.rb', line 91

def query
  start_date = params[:start_date]
  end_date = params[:end_date]
  report_name = params[:report]
  report_sql = params[:report_sql].downcase
  report_sql_orig = params[:report_sql].downcase
  query = params[:query]
  db = params[:db]

  @processor = load_base_processor
  report = @processor.execute_query(@reports[report_name],start_date,end_date,query_vars(report_name),query,db)

  respond_to do |format|
    format.json { render :json => report.to_json}
    format.xml { render :xml => report.to_xml }
    format.csv {
      csv_string = CSV.generate do |csv|
        # header row
        csv << ['Start Date', start_date,'End Date', end_date]
        csv << @reports[report_name]['fields']

        # data rows
        report[:rows].each do |row|
          rec = []
          row[:cell].each do |cell|
            rec << strip_html(cell.to_s).gsub("\n","")
          end
          csv << rec
        end
      end

      send_data csv_string,
      :type => 'text/csv; charset=iso-8859-1; header=present',
      :disposition => "attachment; filename=#{report_sql}_#{start_date.gsub(' ','_')}_#{end_date.gsub(' ','_')}.csv"
    }
  end
end

#tableObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/old_sql/report_controller.rb', line 43

def table
  @start_date = params[:start_date]
  @end_date = params[:end_date]
  @report_name = params[:report]
  @report_sql = params[:report_sql].downcase
  @report_sql_orig = params[:report_sql].downcase

  @width = OldSql.report_width
  @height = OldSql.report_height

  processor = load_base_processor
  @report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))

  render :template => "old_sql/report/table.html.erb"
end