old_sql 1.17.0 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,15 +13,17 @@ Some features of Old SQL are:
13
13
  and describe the layout of the report in an intuitive way.
14
14
  - If you want more fine grained control, a custom report processor can parse the SQL.
15
15
  - Simple to convert legacy reports into Old SQL reports.
16
- * Multiple report views (jqGrid, HTML table, and chart) that can be configured using the old_sql initializer.
17
- * Old SQL uses Devise for authentication, and will install it for you. It can
18
- even add Devise support to an existing model (by default users).
16
+ * Multiple report views (jqGrid, HTML table, and chart).
17
+ * Bar and Pie charts using Google Charts.
19
18
  * In the report design all data is rounded to a precision that can be set in the old_sql initializer.
20
19
  This feature can also be disabled in the initializer.
21
20
  * Old SQL has rake tasks for running the reports and outputting the result as CSV. This can simplify testing.
22
21
  It also allows reports to be run as a cron task.
23
22
  * The look of Old SQL can be customized.
24
23
  * Support for printing and exporting to CSV.
24
+ * Old SQL uses Devise for authentication, and will install it for you. It can
25
+ even add Devise support to an existing model (by default users).
26
+ * Support for multiple database connections.
25
27
 
26
28
  Quick Setup and Demo
27
29
  --------------------
@@ -40,9 +42,16 @@ Quick Setup and Demo
40
42
 
41
43
  Screenshots
42
44
  -----------
45
+ #### jqGrid
43
46
 
44
47
  ![jqGrid view](https://github.com/egonz/old_sql/raw/master/screenshots/jqgrid.png "jqGrid view")
48
+
49
+ #### HTML Table
50
+
45
51
  ![table view](https://github.com/egonz/old_sql/raw/master/screenshots/table.png "Table view")
52
+
53
+ #### Google Charts
54
+
46
55
  ![table view](https://github.com/egonz/old_sql/raw/master/screenshots/chart.png "Chart view")
47
56
 
48
57
  Installation
@@ -86,6 +95,9 @@ Configure your reports config/old_sql/report.yml. An example configuration is cr
86
95
  # 'report_view' is optional. It overrides the default_report_view defined in the initializer. It
87
96
  # can be set to jqgrid, table, or chart.
88
97
  #
98
+ # Optionally use 'report_db' to specify a class that extends ActiveRecord::Base. Use the require
99
+ # path for your class. E.g. foo/my_alternative_db.
100
+ #
89
101
  # The 'fields' are the headers for the report.
90
102
 
91
103
  user_jqgrid:
@@ -46,8 +46,7 @@ module OldSql
46
46
  @height = OldSql.report_height
47
47
 
48
48
  processor = load_base_processor
49
- @report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'],
50
- @reports[@report_name]['report_processor'])
49
+ @report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
51
50
 
52
51
  render :template => "old_sql/report/table.html.erb"
53
52
  end
@@ -63,8 +62,7 @@ module OldSql
63
62
  @height = 500
64
63
 
65
64
  processor = load_base_processor
66
- @report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'],
67
- @reports[@report_name]['report_processor'])
65
+ @report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
68
66
 
69
67
  render :layout => 'old_sql/chart.html.erb', :template => "old_sql/report/chart.html.erb"
70
68
  end
@@ -77,8 +75,7 @@ module OldSql
77
75
  @report_sql_orig = params[:report_sql].downcase
78
76
 
79
77
  processor = load_base_processor
80
- @report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'],
81
- @reports[@report_name]['report_processor'])
78
+ @report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
82
79
 
83
80
  respond_to do |format|
84
81
  format.json { render :json => @report.to_json}
@@ -115,8 +112,7 @@ module OldSql
115
112
  @report_sql_orig = params[:report_sql].downcase
116
113
 
117
114
  processor = load_base_processor
118
- @report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'],
119
- @reports[@report_name]['report_processor'])
115
+ @report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
120
116
 
121
117
  render :template => "old_sql/report/print.html.erb"
122
118
  end
@@ -194,11 +190,13 @@ module OldSql
194
190
  end
195
191
 
196
192
  def chart_data
193
+ return nil if @report.nil?
197
194
  json = @report.values.first.to_json
198
195
  json.html_safe
199
196
  end
200
197
 
201
198
  def chart_type
199
+ return nil if @report.nil?
202
200
  @report.keys.first
203
201
  end
204
202
  end
@@ -1,6 +1,7 @@
1
1
  <html>
2
2
  <head>
3
3
  <title><%=OldSql.report_select_page_title%></title>
4
+ <%= stylesheet_link_tag "old_sql/old_sql.css" %>
4
5
  <!--Load the AJAX API-->
5
6
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
6
7
  <%= javascript_include_tag "old_sql/chart.js" %>
@@ -1,3 +1,6 @@
1
+ <% if @report.nil? %>
2
+ The report has no data for this date range.
3
+ <% else %>
1
4
  <script type="text/javascript">
2
5
  var chart_title = "<%=@reports[@report_name]['description']%> Report";
3
6
  var chart_type = "<%=chart_type%>";
@@ -7,4 +10,5 @@
7
10
  var height = <%=@height%>;
8
11
  </script>
9
12
 
10
- <div id="chart_div"></div>
13
+ <div id="chart_div"></div>
14
+ <% end %>
@@ -1,3 +1,6 @@
1
+ <% if @report.nil? %>
2
+ The report has no data for this date range.
3
+ <% else %>
1
4
  <script>
2
5
  print();
3
6
  </script>
@@ -63,4 +66,5 @@ th {
63
66
  </tr>
64
67
  <% end %>
65
68
  </table>
66
- </div>
69
+ </div>
70
+ <% end %>
@@ -1,3 +1,6 @@
1
+ <% if @report.nil? %>
2
+ The report has no data for this date range.
3
+ <% else %>
1
4
  <%= stylesheet_link_tag "old_sql/table.css" %>
2
5
  <%= javascript_include_tag "old_sql/table.js" %>
3
6
 
@@ -17,4 +20,5 @@
17
20
  <% end %>
18
21
  </tr>
19
22
  <% end %>
20
- </table>
23
+ </table>
24
+ <% end %>
@@ -17,6 +17,7 @@ module OldSql
17
17
  copy_file "#{gem_path}/public/stylesheets/old_sql/old_sql.css", "#{app_path}/public/stylesheets/old_sql/old_sql.css"
18
18
  copy_file "#{gem_path}/public/stylesheets/old_sql/old_sql.css", "#{app_path}/public/stylesheets/old_sql/table.css"
19
19
  copy_file "#{gem_path}/app/views/layouts/old_sql/report.html.erb", "#{app_path}/app/views/layouts/old_sql/report.html.erb"
20
+ copy_file "#{gem_path}/app/views/layouts/old_sql/report.html.erb", "#{app_path}/app/views/layouts/old_sql/chart.html.erb"
20
21
  end
21
22
 
22
23
  private
@@ -18,6 +18,9 @@
18
18
  # 'report_view' is optional. It overrides the default_report_view defined in the initializer. It
19
19
  # can be set to jqgrid, table, or chart.
20
20
  #
21
+ # Optionally use 'report_db' to specify a class that extends ActiveRecord::Base. Use the require
22
+ # path for your class. E.g. foo/my_alternative_db.
23
+ #
21
24
  # The 'fields' are the headers for the report.
22
25
 
23
26
  user_jqgrid:
@@ -5,8 +5,6 @@ module OldSql
5
5
  class UserOldSqlDemoProcessor < OldSql::ReportProcessor::Base
6
6
 
7
7
  def parse(resultset)
8
- init(resultset)
9
-
10
8
  Rails.logger.debug "REC: #{@rec}"
11
9
 
12
10
  add_row([@rec['id'], @rec['name']])
@@ -3,7 +3,6 @@ require 'old_sql/report_design/model'
3
3
  require 'old_sql/report_design/row'
4
4
  require 'old_sql/report_design/cell'
5
5
  require 'old_sql/report_design/cell_data'
6
-
7
6
  require 'old_sql/report_design/chart_parser'
8
7
  require 'old_sql/report_design/chart'
9
8
  require 'old_sql/report_design/chart_item'
@@ -15,7 +14,50 @@ module OldSql
15
14
 
16
15
  ROUND_PRECISION = OldSql.rounding_precision
17
16
 
18
- def execute_query(report_sql,start_date,end_date,query_vars,design=nil,sub_processor=nil)
17
+ def execute_query(report_config, start_date, end_date, query_vars = nil)
18
+ sql = load_sql(report_config['report_sql'], start_date, end_date, query_vars)
19
+ query(sql, report_config)
20
+
21
+ return nil if @resultset.nil?
22
+
23
+ init
24
+
25
+ report_design = report_config['report_design']
26
+
27
+ if report_design
28
+ parse_design(report_design, @resultset) if report_design =~ /csv/
29
+ parse_chart_design(report_design, @resultset) if report_design =~ /yml/
30
+ else
31
+ loaded_sub_processor = load_sub_processor(report_config['report_processor'])
32
+
33
+ if loaded_sub_processor.nil?
34
+ parse(@resultset)
35
+ else
36
+ @data = loaded_sub_processor.parse(@resultset)
37
+ end
38
+ end
39
+
40
+ @data
41
+ end
42
+
43
+ protected
44
+
45
+ def add_row(cell_data = [], id = @id+1)
46
+ @data[:rows] << {id: id, cell: cell_data}
47
+ end
48
+
49
+ def round(value, precision = ROUND_PRECISION)
50
+ factor = 10.0**precision
51
+ (value*factor).round / factor
52
+ end
53
+
54
+ def isNumeric(s)
55
+ Float(s) != nil rescue false
56
+ end
57
+
58
+ private
59
+
60
+ def load_sql(report_sql, start_date, end_date, query_vars)
19
61
  vars = {:start_date => start_date, :end_date => end_date}
20
62
 
21
63
  if !query_vars.nil?
@@ -24,10 +66,14 @@ module OldSql
24
66
 
25
67
  template = File.read("#{Rails.root}/config/old_sql/report_sql/#{report_sql}.erb")
26
68
  sql = Erubis::Eruby.new(template).result(vars)
69
+ end
27
70
 
71
+ def query sql, report_config
28
72
  begin
29
73
  #todo change to a reporting db
30
- db = ActiveRecord::Base.connection();
74
+ db = db_connection(report_config['report_db'])
75
+
76
+ raise Exception("Unable to Establish a Database Connection") unless db.active?
31
77
 
32
78
  @resultset = []
33
79
  rec = db.select_all(sql)
@@ -35,34 +81,67 @@ module OldSql
35
81
  @resultset << row
36
82
  end
37
83
  rescue Exception=>e
38
- #todo log error
39
84
  Rails.logger.error e
40
85
  end
41
86
 
42
- if design
43
- parse_design(design, @resultset) if design =~ /csv/
44
- parse_chart_design(design, @resultset) if design =~ /yml/
87
+ @resultset
88
+ end
89
+
90
+ def db_connection report_db
91
+ db = nil
92
+ if report_db.nil?
93
+ db = ActiveRecord::Base.connection();
45
94
  else
46
- loaded_sub_processor = load_sub_processor(sub_processor)
47
-
48
- if loaded_sub_processor.nil?
49
- parse(@resultset)
50
- else
51
- @data = loaded_sub_processor.parse(@resultset)
95
+ require report_db
96
+
97
+ db_class_name = ""
98
+ first = true
99
+
100
+ report_db.split("/").each do |path|
101
+ db_class_name << "::" unless first
102
+ path.split("_").each {|c| db_class_name << c.capitalize }
103
+ first = false
52
104
  end
105
+
106
+ db=eval(db_class_name).connection
53
107
  end
54
108
 
55
- @data
109
+ db
56
110
  end
57
-
58
- def init(resultset)
59
- @rec = resultset[0]
60
- self.new_data
111
+
112
+ def load_sub_processor sub_processor
113
+ return if sub_processor.nil?
114
+
115
+ loaded_sub_processor = nil
116
+ begin
117
+ require "old_sql/report_processor/#{sub_processor.downcase}"
118
+ loaded_sub_processor=eval("OldSql::ReportProcessor::#{sub_processor.gsub("_","")}").new
119
+ rescue Exception=>e
120
+ Rails.logger.error e.message
121
+ end
122
+
123
+ loaded_sub_processor
124
+ end
125
+
126
+ def init
127
+ @rec = @resultset[0]
128
+ @id = 0
129
+ @data = {}
130
+ @data[:rows] = []
131
+
132
+ init_jqgrid_data
61
133
  end
134
+
135
+ def init_jqgrid_data(page=1, total=1, records=1)
136
+ @data[:page]=page
137
+ @data[:total]=total
138
+ @data[:records]=records
139
+ end
140
+
62
141
 
63
142
  def parse(resultset)
64
- init(resultset)
65
-
143
+ init_jqgrid_data
144
+
66
145
  resultset.each do |r|
67
146
  cell = []
68
147
  r.each do |key, value|
@@ -75,14 +154,8 @@ module OldSql
75
154
  end
76
155
 
77
156
  def parse_design(design, resultset)
78
- init(resultset)
79
-
80
- return nil if @rec.nil?
81
-
82
157
  model = OldSql::ReportDesign::Parser.read_file("#{design}")
83
158
 
84
- init(resultset)
85
-
86
159
  model.rows.each do |row|
87
160
  report_row = []
88
161
  row.cells.each do |cell|
@@ -116,13 +189,13 @@ module OldSql
116
189
 
117
190
  def parse_chart_design(design, resultset)
118
191
  report_row = []
119
- @rec = resultset[0]
120
-
192
+
121
193
  chart = OldSql::ReportDesign::ChartParser.read_file("#{design}")
122
194
 
123
195
  chart.items.each do |item|
124
196
  key = item.key
125
197
  expression = ""
198
+
126
199
  item.chart_data.each do |data|
127
200
  if item.expression?
128
201
  if data.type == OldSql::ReportDesign::ChartData::COLUMN
@@ -167,51 +240,6 @@ module OldSql
167
240
 
168
241
  result
169
242
  end
170
-
171
- def round(value, precision = ROUND_PRECISION)
172
- factor = 10.0**precision
173
- (value*factor).round / factor
174
- end
175
-
176
- def new_data(page=1, total=1, records=1)
177
- @id = 0
178
- @data = {}
179
- @data[:page]=page
180
- @data[:total]=total
181
- @data[:records]=records
182
- @data[:rows] = []
183
- end
184
-
185
- def add_row(cell_data = [], id = @id+1)
186
- @data[:rows] << {id: id, cell: cell_data}
187
- end
188
-
189
- def ifnull(o)
190
- if !o.nil? && o != 0
191
- return o
192
- else
193
- return 1
194
- end
195
- end
196
-
197
- def isNumeric(s)
198
- Float(s) != nil rescue false
199
- end
200
-
201
- def load_sub_processor sub_processor
202
- return if sub_processor.nil?
203
-
204
- loaded_sub_processor = nil
205
- begin
206
- Rails.logger.info "Loading Processor old_sql/report_processor/#{sub_processor.downcase}"
207
- require "old_sql/report_processor/#{sub_processor.downcase}"
208
- loaded_sub_processor=eval("OldSql::ReportProcessor::#{sub_processor.gsub("_","")}").new
209
- rescue Exception=>e
210
- Rails.logger.error e.message
211
- end
212
-
213
- loaded_sub_processor
214
- end
215
243
  end
216
244
  end
217
245
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: old_sql
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.17.0
5
+ version: 1.18.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Eddie Gonzales
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-15 00:00:00 Z
13
+ date: 2011-06-16 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: devise
@@ -193,7 +193,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
193
  requirements:
194
194
  - - ">="
195
195
  - !ruby/object:Gem::Version
196
- hash: 1474127642564641117
196
+ hash: 1596520403789192732
197
197
  segments:
198
198
  - 0
199
199
  version: "0"