old_sql 1.26.0 → 1.27.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -21
- data/app/controllers/old_sql/report_controller.rb +141 -120
- data/app/views/old_sql/report/_query.html.erb +49 -0
- data/app/views/old_sql/report/_reports.html.erb +40 -0
- data/app/views/old_sql/report/index.html.erb +20 -46
- data/app/views/old_sql/report/{datagrid.html.erb → jqgrid.html.erb} +11 -4
- data/config/routes.rb +1 -1
- data/lib/old_sql/report_processor/base.rb +60 -28
- data/public/javascripts/old_sql/chart.js +1 -0
- data/public/javascripts/old_sql/jquery-ui-1.8.13.custom.min.js +65 -0
- data/public/javascripts/old_sql/old_sql.js +130 -32
- data/public/stylesheets/old_sql/old_sql.css +29 -32
- data/public/stylesheets/old_sql/table.css +29 -29
- data/public/stylesheets/old_sql/ui-lightness/jquery-ui-1.8.13.custom.css +60 -0
- metadata +6 -4
data/README.md
CHANGED
@@ -1,28 +1,22 @@
|
|
1
|
-
# Old SQL
|
1
|
+
# Old SQL [pronounced /skuːl/]
|
2
2
|
|
3
3
|
Old SQL is a Rails Engine database reporting gem that uses plain old SQL.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
* Reports can be
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
- If you want more fine grained control, a custom report processor can parse the SQL.
|
14
|
-
- Simple to convert legacy reports into Old SQL reports.
|
15
|
-
* Multiple report views (jqGrid, HTML table, and chart).
|
16
|
-
* Bar and Pie charts using Google Charts.
|
17
|
-
* In the report design all data is rounded to a precision that can be set in the old_sql initializer.
|
18
|
-
This feature can also be disabled in the initializer.
|
19
|
-
* Old SQL has rake tasks for running the reports and outputting the result as CSV. This can simplify testing.
|
20
|
-
It also allows reports to be run as a cron task.
|
21
|
-
* The look of Old SQL can be customized.
|
22
|
-
* Support for printing and exporting to CSV.
|
23
|
-
* Old SQL uses Devise for authentication, and will install it for you. It can
|
24
|
-
even add Devise support to an existing model (by default users).
|
5
|
+
* Write reports in plain old SQL with little or no coding.
|
6
|
+
* Layout reports using CSV and YAML.
|
7
|
+
* Reports can be displayed using jqGrid, plain HTML, or as a chart (using the Google Charts API).
|
8
|
+
* Automatic rounding of all values. Can be controlled via an initializer.
|
9
|
+
* Rake tasks for running reports from the command line.
|
10
|
+
* Devise for authentication. Which is installed and configured for you using the old_sql
|
11
|
+
generator._
|
12
|
+
* Printing and exporting to CSV.
|
25
13
|
* Support for multiple database connections.
|
14
|
+
* Interface for running Ad hoc queries.
|
15
|
+
|
16
|
+
## Coming Soon
|
17
|
+
|
18
|
+
* Schema browser
|
19
|
+
* Google docs integration
|
26
20
|
|
27
21
|
## Quick Setup and Demo
|
28
22
|
|
@@ -12,83 +12,105 @@ module OldSql
|
|
12
12
|
helper_method :strip_html
|
13
13
|
helper_method :chart_type
|
14
14
|
helper_method :chart_data
|
15
|
+
helper_method :db_list
|
15
16
|
|
16
17
|
layout "old_sql/report.html.erb"
|
17
|
-
|
18
|
+
|
18
19
|
BASE_PROCESSOR = "base"
|
19
20
|
|
20
21
|
def index
|
21
22
|
@report_view = OldSql.default_report_view
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
def jqgrid
|
25
26
|
@start_date = params[:start_date]
|
26
27
|
@end_date = params[:end_date]
|
27
28
|
@report_name = params[:report]
|
28
29
|
@report_sql = params[:report_sql]
|
30
|
+
@query = params[:query]
|
31
|
+
@db = params[:db]
|
32
|
+
@caption = params[:caption]
|
33
|
+
w = params[:w]
|
29
34
|
|
30
35
|
#todo allow these to be overridden in the report config
|
31
36
|
@row_num = OldSql.jqgrid_row_num
|
32
|
-
@width = OldSql.report_width
|
37
|
+
@width = w.nil? ? OldSql.report_width : w
|
33
38
|
@height = OldSql.report_height
|
34
|
-
|
35
|
-
render :template => "old_sql/report/
|
39
|
+
|
40
|
+
render :template => "old_sql/report/jqgrid.html.erb"
|
36
41
|
end
|
37
|
-
|
42
|
+
|
38
43
|
def table
|
39
44
|
@start_date = params[:start_date]
|
40
45
|
@end_date = params[:end_date]
|
41
46
|
@report_name = params[:report]
|
42
47
|
@report_sql = params[:report_sql].downcase
|
43
48
|
@report_sql_orig = params[:report_sql].downcase
|
44
|
-
|
49
|
+
|
45
50
|
@width = OldSql.report_width
|
46
51
|
@height = OldSql.report_height
|
47
|
-
|
52
|
+
|
48
53
|
processor = load_base_processor
|
49
54
|
@report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
|
50
|
-
|
55
|
+
|
51
56
|
render :template => "old_sql/report/table.html.erb"
|
52
57
|
end
|
53
|
-
|
58
|
+
|
54
59
|
def chart
|
55
60
|
@start_date = params[:start_date]
|
56
61
|
@end_date = params[:end_date]
|
57
62
|
@report_name = params[:report]
|
58
63
|
@report_sql = params[:report_sql].downcase
|
59
64
|
@report_sql_orig = params[:report_sql].downcase
|
60
|
-
|
65
|
+
|
61
66
|
@width = 800
|
62
67
|
@height = 500
|
63
68
|
@google_chart_colors = google_chart_colors
|
64
|
-
|
69
|
+
|
65
70
|
processor = load_base_processor
|
66
71
|
@report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
|
67
|
-
|
72
|
+
|
68
73
|
render :layout => 'old_sql/chart.html.erb', :template => "old_sql/report/chart.html.erb"
|
69
74
|
end
|
70
|
-
|
71
|
-
def
|
75
|
+
|
76
|
+
def print
|
72
77
|
@start_date = params[:start_date]
|
73
78
|
@end_date = params[:end_date]
|
74
79
|
@report_name = params[:report]
|
80
|
+
@desc = params[:desc]
|
75
81
|
@report_sql = params[:report_sql].downcase
|
76
82
|
@report_sql_orig = params[:report_sql].downcase
|
77
|
-
|
83
|
+
|
78
84
|
processor = load_base_processor
|
79
85
|
@report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
|
80
|
-
|
86
|
+
|
87
|
+
render :template => "old_sql/report/print.html.erb"
|
88
|
+
end
|
89
|
+
|
90
|
+
#ajax call
|
91
|
+
def query
|
92
|
+
start_date = params[:start_date]
|
93
|
+
end_date = params[:end_date]
|
94
|
+
report_name = params[:report]
|
95
|
+
report_sql = params[:report_sql].downcase
|
96
|
+
report_sql_orig = params[:report_sql].downcase
|
97
|
+
query = params[:query]
|
98
|
+
db = params[:db]
|
99
|
+
|
100
|
+
@processor = load_base_processor
|
101
|
+
report = @processor.execute_query(@reports[report_name],start_date,end_date,query_vars(report_name),query,db)
|
102
|
+
|
81
103
|
respond_to do |format|
|
82
|
-
format.json { render :json =>
|
83
|
-
format.xml { render :xml =>
|
104
|
+
format.json { render :json => report.to_json}
|
105
|
+
format.xml { render :xml => report.to_xml }
|
84
106
|
format.csv {
|
85
107
|
csv_string = CSV.generate do |csv|
|
86
108
|
# header row
|
87
|
-
csv << ['Start Date',
|
88
|
-
csv << @reports[
|
109
|
+
csv << ['Start Date', start_date,'End Date', end_date]
|
110
|
+
csv << @reports[report_name]['fields']
|
89
111
|
|
90
112
|
# data rows
|
91
|
-
|
113
|
+
report[:rows].each do |row|
|
92
114
|
rec = []
|
93
115
|
row[:cell].each do |cell|
|
94
116
|
rec << strip_html(cell.to_s).gsub("\n","")
|
@@ -98,113 +120,112 @@ module OldSql
|
|
98
120
|
end
|
99
121
|
|
100
122
|
send_data csv_string,
|
101
|
-
|
102
|
-
|
123
|
+
:type => 'text/csv; charset=iso-8859-1; header=present',
|
124
|
+
:disposition => "attachment; filename=#{report_sql}_#{start_date.gsub(' ','_')}_#{end_date.gsub(' ','_')}.csv"
|
103
125
|
}
|
104
126
|
end
|
105
127
|
end
|
106
|
-
|
107
|
-
def print
|
108
|
-
@start_date = params[:start_date]
|
109
|
-
@end_date = params[:end_date]
|
110
|
-
@report_name = params[:report]
|
111
|
-
@desc = params[:desc]
|
112
|
-
@report_sql = params[:report_sql].downcase
|
113
|
-
@report_sql_orig = params[:report_sql].downcase
|
114
|
-
|
115
|
-
processor = load_base_processor
|
116
|
-
@report = processor.execute_query(@reports[@report_name],@start_date,@end_date,query_vars(@report_name))
|
117
|
-
|
118
|
-
render :template => "old_sql/report/print.html.erb"
|
119
|
-
end
|
120
|
-
|
128
|
+
|
121
129
|
|
122
130
|
private
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
field_num+=1
|
163
|
-
end
|
164
|
-
|
165
|
-
@fields.to_json.html_safe
|
166
|
-
end
|
167
|
-
|
168
|
-
def jqgrid_col_names
|
169
|
-
logger.info @reports
|
170
|
-
logger.info "REPORT NAME #{@report_name}"
|
171
|
-
json = @reports[@report_name]['fields'].to_json
|
172
|
-
json.html_safe
|
173
|
-
end
|
174
|
-
|
175
|
-
def query_vars report
|
176
|
-
query_vars = @reports[report]['query_vars']
|
177
|
-
if !query_vars.nil? && query_vars.size > 0
|
178
|
-
return query_vars[0]
|
131
|
+
def ensure_old_sql_admin!
|
132
|
+
render_error(Exception.new "Old SQL Access Denied.") unless eval("current_user.old_sql_admin?")
|
133
|
+
end
|
134
|
+
|
135
|
+
def _init
|
136
|
+
@host = self.request.host
|
137
|
+
@port = self.request.port
|
138
|
+
end
|
139
|
+
|
140
|
+
def _reports
|
141
|
+
template = File.read("#{Rails.root}/config/old_sql/reports.yml")
|
142
|
+
@reports = YAML.load(Erubis::Eruby.new(template).result)
|
143
|
+
end
|
144
|
+
|
145
|
+
def load_base_processor
|
146
|
+
require "old_sql/report_processor/base"
|
147
|
+
OldSql::ReportProcessor::Base.new
|
148
|
+
end
|
149
|
+
|
150
|
+
def jqgrid_col_model
|
151
|
+
@fields = []
|
152
|
+
field_num = 1
|
153
|
+
|
154
|
+
# [
|
155
|
+
# {name:'id',index:'id', width:55},
|
156
|
+
# {name:'invdate',index:'invdate', width:90, editable:true},
|
157
|
+
# {name:'name',index:'name', width:100,editable:true},
|
158
|
+
# {name:'amount',index:'amount', width:80, align:"right",editable:true},
|
159
|
+
# {name:'tax',index:'tax', width:80, align:"right",editable:true},
|
160
|
+
# {name:'total',index:'total', width:80,align:"right",editable:true},
|
161
|
+
# {name:'note',index:'note', width:150, sortable:false,editable:true}
|
162
|
+
# ]
|
163
|
+
|
164
|
+
qf = query_fields
|
165
|
+
return if qf.nil?
|
166
|
+
|
167
|
+
qf.each do |field|
|
168
|
+
if field_num == 1
|
169
|
+
@fields << { :name=>field }
|
179
170
|
else
|
180
|
-
|
171
|
+
@fields << { :name=>field, :align=>"center" }
|
181
172
|
end
|
173
|
+
field_num+=1
|
182
174
|
end
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
json = OldSql.google_chart_colors.to_json
|
206
|
-
json.html_safe
|
175
|
+
|
176
|
+
@fields.to_json.html_safe
|
177
|
+
end
|
178
|
+
|
179
|
+
def jqgrid_col_names
|
180
|
+
json = query_fields.to_json
|
181
|
+
json.html_safe
|
182
|
+
end
|
183
|
+
|
184
|
+
def query_fields
|
185
|
+
fields = load_base_processor.fields(@reports[@report_name],@start_date,@end_date,query_vars(@report_name),@query,@db)
|
186
|
+
logger.info "FIELDS #{fields}"
|
187
|
+
fields
|
188
|
+
end
|
189
|
+
|
190
|
+
def query_vars report
|
191
|
+
return nil if report.nil? || report.length<=0
|
192
|
+
query_vars = @reports[report]['query_vars']
|
193
|
+
if !query_vars.nil? && query_vars.size > 0
|
194
|
+
return query_vars[0]
|
195
|
+
else
|
196
|
+
return nil
|
207
197
|
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def render_error(exception)
|
201
|
+
logger.error(exception)
|
202
|
+
render :template => "old_sql/errors/401.html.erb", :status => 401
|
203
|
+
end
|
204
|
+
|
205
|
+
def strip_html html
|
206
|
+
OldSql.strip_html html
|
207
|
+
end
|
208
|
+
|
209
|
+
def chart_data
|
210
|
+
return nil if @report.nil?
|
211
|
+
json = @report.values.first.to_json
|
212
|
+
json.html_safe
|
213
|
+
end
|
214
|
+
|
215
|
+
def chart_type
|
216
|
+
return nil if @report.nil?
|
217
|
+
@report.keys.first
|
218
|
+
end
|
219
|
+
|
220
|
+
def google_chart_colors
|
221
|
+
json = OldSql.google_chart_colors.to_json
|
222
|
+
json.html_safe
|
223
|
+
end
|
224
|
+
|
225
|
+
def db_list
|
226
|
+
db = []
|
227
|
+
db << {name: Rails.env.capitalize, db_class: "active_record/base"}
|
228
|
+
end
|
208
229
|
end
|
209
230
|
end
|
210
231
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
<script>
|
2
|
+
jQuery(document).ready(function($){
|
3
|
+
$('#query-button').bind('click', function() {
|
4
|
+
query();
|
5
|
+
});
|
6
|
+
|
7
|
+
$('#delete-saved-queries').bind('click', function() {
|
8
|
+
deleted_saved_queries();
|
9
|
+
});
|
10
|
+
|
11
|
+
$('#saved-queries-list').bind('click', function() {
|
12
|
+
$('#query-text').val($("#saved-queries-list option:selected").val());
|
13
|
+
});
|
14
|
+
});
|
15
|
+
</script>
|
16
|
+
|
17
|
+
<div class="query">
|
18
|
+
<div>
|
19
|
+
DATABASE:
|
20
|
+
<select name="query-db" id="query-db" onchange="db_selected()">
|
21
|
+
<% db_list.each do |db| %>
|
22
|
+
<option value="<%=db[:name]%>" class_name="<%=db[:class_name]%>"><%=db[:name]%></option>
|
23
|
+
<% end %>
|
24
|
+
</select>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div>
|
28
|
+
<textarea id="query-text" rows="12" cols="120"></textarea>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div>
|
32
|
+
<input id="query-button" type="button" value="Run" onclick="return true;" /> or press ctrl-enter
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div id="saved_queries">
|
37
|
+
<div>
|
38
|
+
SAVED QUERIES:
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div>
|
42
|
+
<select id="saved-queries-list" size="14">
|
43
|
+
</select>
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div>
|
47
|
+
<input id="delete-saved-queries" type="button" value="Clear" onclick="return true;" />
|
48
|
+
</div>
|
49
|
+
</div>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<form id="report-form" name="report-form" action="/oldsql/reports/query" method="POST">
|
2
|
+
<div class="report-form-row">
|
3
|
+
<div class="report-form-label">SELECT A REPORT:</div>
|
4
|
+
<div class="report-form-input">
|
5
|
+
<select name="report" id="report"
|
6
|
+
onchange="report_selected()">
|
7
|
+
<option></option>
|
8
|
+
<% @reports.each do |report, data| %>
|
9
|
+
<option value="<%= data['name'] %>" report_sql="<%= data['report_sql'] %>"
|
10
|
+
desc="<%= data['description'] %>" name="<%=report%>"
|
11
|
+
report_view="<%=data['report_view']%>"><%= data['description'] %></option>
|
12
|
+
<% end %>
|
13
|
+
</select>
|
14
|
+
</div>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="report-form-row">
|
18
|
+
<div class="report-form-label">START DATE:</div>
|
19
|
+
<div class="report-form-input">
|
20
|
+
<input type="text" id="datepicker-start" name="start_date" value="">
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="report-form-row">
|
25
|
+
<div class="report-form-label">END DATE:</div>
|
26
|
+
<div class="report-form-input">
|
27
|
+
<input type="text" id="datepicker-end" name="end_date" value="">
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
<div class="report-form-row">
|
32
|
+
<div class="report-form-label"></div>
|
33
|
+
<input type="button" value="Run" onclick="load_report();"/>
|
34
|
+
</div>
|
35
|
+
</form>
|
36
|
+
|
37
|
+
<div id="links">
|
38
|
+
<div><%= link_to_function("Print Report", "javascript:print_report()") %></div>
|
39
|
+
<div><%= link_to_function("Export To Excel", "javascript:export_report_to_excel()") %></div>
|
40
|
+
</div>
|