old_sql 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +66 -2
- data/app/controllers/old_sql/report_controller.rb +4 -18
- data/app/views/old_sql/report/datagrid.html.erb +1 -1
- data/app/views/old_sql/report/index.html.erb +1 -13
- data/lib/generators/old_sql/copy_assets_generator.rb +1 -0
- data/lib/generators/old_sql/install_generator.rb +5 -0
- data/lib/generators/old_sql/templates/old_sql.rb +3 -0
- data/lib/generators/old_sql/templates/reports.yml.example +16 -5
- data/lib/old_sql.rb +4 -0
- data/public/javascripts/old_sql/old_sql.js +31 -41
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -2,7 +2,36 @@
|
|
2
2
|
|
3
3
|
Old SQL is a Rails Engine database reporting gem that uses plain old SQL.
|
4
4
|
|
5
|
-
|
5
|
+
Some features of Old SQL are:
|
6
|
+
|
7
|
+
* Reports can be created using little or no Ruby code.
|
8
|
+
- This allows the SQL for the report to be designed by a DBA, or other database developer independent of Ruby.
|
9
|
+
- Reports can be designed using a design file that mocks the reports. This file can contain data from the SQL, as well as String literals, and formulas (that can also use numeric literals).
|
10
|
+
- The design documents, which are nothing more than csv files, can also serve as documentation, and describe the layout of the report in an intuitive way.
|
11
|
+
- If you want more fine grained control and report processor can parse the SQL.
|
12
|
+
- This also makes it simple to convert legacy reports into Old SQL reports.
|
13
|
+
* Multiple report views (jqGrid, HTML table) that can be configured using the old_sql initializer.
|
14
|
+
* Old SQL uses Devise for authentication, and will install it for you. It can
|
15
|
+
even add Devise support to an existing model (by default users).
|
16
|
+
* In the report design all data is rounded to a precision that can be set in the old_sql initializer. This feature can also be disabled in the initializer.
|
17
|
+
* Old SQL has rake tasks for running the reports and outputting the result as CSV. This can simplify testing. It also allows reports to be run as a cron task.
|
18
|
+
* The look of Old SQL can be customized.
|
19
|
+
* Support for printing and exporting to csv.
|
20
|
+
|
21
|
+
== Quick Setup and Demo
|
22
|
+
|
23
|
+
1. Add gem 'old_sql', and gem 'devise' to your Gemfile.
|
24
|
+
2. bundle instal
|
25
|
+
3. rails g old_sql:install, or rails g old_sql:install <model>
|
26
|
+
4. rake db:migrate
|
27
|
+
5. Ensure you have at least one user record, and that old_sql_admin=true.
|
28
|
+
6. if you didn't previously have Devise installed open rails console, and select your old_sql_admin user, and set password and password_confirmation. Save, and exit.
|
29
|
+
7. Type rails s to start your rails server.
|
30
|
+
8. Navigate to http://localhost:3000/sql/reports
|
31
|
+
9. Authenticate using your old_sql_admin user.
|
32
|
+
10. Select user from the Reports drop down list. Click run.
|
33
|
+
|
34
|
+
== Installation
|
6
35
|
|
7
36
|
To install Old SQL type:
|
8
37
|
|
@@ -13,8 +42,43 @@ This will create the following directories:
|
|
13
42
|
* config/old_sql
|
14
43
|
* lib/old_sql
|
15
44
|
|
16
|
-
|
45
|
+
This generator will also create a migration that will add a old_sql_admin column to the model used for authentication (by default users).
|
46
|
+
|
47
|
+
If not already installed Devise is setup.
|
48
|
+
|
49
|
+
== Setup
|
50
|
+
|
51
|
+
Configure your reports config/old_sql/report.yml. An example configuration is created when you run the old_sql:install generator.
|
52
|
+
|
53
|
+
# Old SQL Reports YAML
|
54
|
+
# This is an example report. Replace it with your actual reports.
|
55
|
+
#
|
56
|
+
# 'description' is the value displayed in the 'SELECT A REPORT' drop down list.
|
57
|
+
#
|
58
|
+
# The 'report_sql' file should be located under config/old_sql/report_sql.
|
59
|
+
# See config/old_sql/report_sql/user_old_sql_demo.sql for an example.
|
60
|
+
#
|
61
|
+
# The 'processor' parameter is optional, and should point to a class in lib/old_sql.
|
62
|
+
# See lib/old_sql/user_old_sql_demo_processor.rb for an example.
|
63
|
+
#
|
64
|
+
# 'report_processor' names should be capitalized and separated with underscores. The file
|
65
|
+
# itself should follow normal ruby class naming conventions.
|
66
|
+
#
|
67
|
+
# 'report_design' is also optional, and should point to a file in config/old_sql/report_design.
|
68
|
+
# See config/old_sql/report_design/user_old_sql_demo.csv for an example.
|
69
|
+
#
|
70
|
+
# The 'fields' are the headers for the report.
|
71
|
+
|
72
|
+
user:
|
73
|
+
description: User
|
74
|
+
report_sql: user_old_sql_demo
|
75
|
+
report_design: user_old_sql_demo
|
76
|
+
#report_processor: User_Old_Sql_Demo_Processor
|
77
|
+
fields:
|
78
|
+
- 'id'
|
79
|
+
- 'name'
|
17
80
|
|
81
|
+
== Customize
|
18
82
|
|
19
83
|
== Contributing to old_sql
|
20
84
|
|
@@ -2,7 +2,7 @@ require 'csv'
|
|
2
2
|
|
3
3
|
module OldSql
|
4
4
|
class ReportController < ApplicationController
|
5
|
-
before_filter :
|
5
|
+
before_filter :"authenticate_#{OldSql.devise_model}!"
|
6
6
|
before_filter :ensure_old_sql_admin!
|
7
7
|
before_filter :_init
|
8
8
|
before_filter :_reports
|
@@ -22,7 +22,6 @@ module OldSql
|
|
22
22
|
def jqgrid
|
23
23
|
@start_date = params[:start_date]
|
24
24
|
@end_date = params[:end_date]
|
25
|
-
@generation = params[:generation]
|
26
25
|
@report_name = params[:report]
|
27
26
|
@report_sql = params[:report_sql]
|
28
27
|
|
@@ -37,7 +36,6 @@ module OldSql
|
|
37
36
|
def table
|
38
37
|
@start_date = params[:start_date]
|
39
38
|
@end_date = params[:end_date]
|
40
|
-
@generation = params[:generation]
|
41
39
|
@report_name = params[:report]
|
42
40
|
@report_sql = params[:report_sql].downcase
|
43
41
|
@report_sql_orig = params[:report_sql].downcase
|
@@ -45,10 +43,6 @@ module OldSql
|
|
45
43
|
@width = OldSql.report_width
|
46
44
|
@height = OldSql.report_height
|
47
45
|
|
48
|
-
if !@generation.nil? && @generation.to_i >= 0
|
49
|
-
@report_sql << "_gen_#{@generation}"
|
50
|
-
end
|
51
|
-
|
52
46
|
processor = load_base_processor
|
53
47
|
@report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'],
|
54
48
|
@reports[@report_name]['report_processor'])
|
@@ -59,15 +53,10 @@ module OldSql
|
|
59
53
|
def query
|
60
54
|
@start_date = params[:start_date]
|
61
55
|
@end_date = params[:end_date]
|
62
|
-
@generation = params[:generation]
|
63
56
|
@report_name = params[:report]
|
64
57
|
@report_sql = params[:report_sql].downcase
|
65
58
|
@report_sql_orig = params[:report_sql].downcase
|
66
59
|
|
67
|
-
if !@generation.nil? && @generation.to_i >= 0
|
68
|
-
@report_sql << "_gen_#{@generation}"
|
69
|
-
end
|
70
|
-
|
71
60
|
processor = load_base_processor
|
72
61
|
@report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'],
|
73
62
|
@reports[@report_name]['report_processor'])
|
@@ -101,16 +90,11 @@ module OldSql
|
|
101
90
|
def print
|
102
91
|
@start_date = params[:start_date]
|
103
92
|
@end_date = params[:end_date]
|
104
|
-
@generation = params[:generation]
|
105
93
|
@report_name = params[:report]
|
106
94
|
@desc = params[:desc]
|
107
95
|
@report_sql = params[:report_sql].downcase
|
108
96
|
@report_sql_orig = params[:report_sql].downcase
|
109
97
|
|
110
|
-
if !@generation.nil? && @generation.to_i >= 0
|
111
|
-
@report_sql << "_gen_#{@generation}"
|
112
|
-
end
|
113
|
-
|
114
98
|
processor = load_base_processor
|
115
99
|
@report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'],
|
116
100
|
@reports[@report_name]['report_processor'])
|
@@ -121,7 +105,7 @@ module OldSql
|
|
121
105
|
|
122
106
|
private
|
123
107
|
def ensure_old_sql_admin!
|
124
|
-
render_error(Exception.new "Old SQL Access Denied.") unless current_user.old_sql_admin?
|
108
|
+
render_error(Exception.new "Old SQL Access Denied.") unless eval("current_user.old_sql_admin?")
|
125
109
|
end
|
126
110
|
|
127
111
|
def _init
|
@@ -166,6 +150,8 @@ module OldSql
|
|
166
150
|
end
|
167
151
|
|
168
152
|
def jqgrid_col_names
|
153
|
+
logger.info @reports
|
154
|
+
logger.info "REPORT NAME #{@report_name}"
|
169
155
|
json = @reports[@report_name]['fields'].to_json
|
170
156
|
json.html_safe
|
171
157
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<script>
|
7
7
|
jQuery(document).ready(function(){
|
8
8
|
jQuery("#rowed1").jqGrid({
|
9
|
-
url:"http://<%=@host%>:<%=@port%>/sql/reports/query.json/?report=<%=@report_name%>&report_sql=<%=@report_sql%>&
|
9
|
+
url:"http://<%=@host%>:<%=@port%>/sql/reports/query.json/?report=<%=@report_name%>&report_sql=<%=@report_sql%>&start_date=<%=@start_date%>&end_date=<%=@end_date%>",
|
10
10
|
datatype: "json",
|
11
11
|
pager: false,
|
12
12
|
colNames: <%=jqgrid_col_names%>,
|
@@ -17,24 +17,12 @@ var report_view = "<%=@report_view%>";
|
|
17
17
|
onchange="report_selected()">
|
18
18
|
<option></option>
|
19
19
|
<% @reports.each do |report, data| %>
|
20
|
-
<option value="<%= data['name'] %>"
|
20
|
+
<option value="<%= data['name'] %>" report_sql="<%= data['report_sql'] %>" desc="<%= data['description'] %>" name="<%=report%>"><%= data['description'] %></option>
|
21
21
|
<% end %>
|
22
22
|
</select>
|
23
23
|
</div>
|
24
24
|
</div>
|
25
25
|
|
26
|
-
<div class="report-form-row">
|
27
|
-
<div class="report-form-label">GENERATION:</div>
|
28
|
-
<div class="report-form-input">
|
29
|
-
<select name="generation" id="select-generation">
|
30
|
-
<option value="-1"></option>
|
31
|
-
<option value="0">0</option>
|
32
|
-
<option value="1">1</option>
|
33
|
-
<option value="2">2</option>
|
34
|
-
</select>
|
35
|
-
</div>
|
36
|
-
</div>
|
37
|
-
|
38
26
|
<div class="report-form-row">
|
39
27
|
<div class="report-form-label">START DATE:</div>
|
40
28
|
<div class="report-form-input">
|
@@ -15,6 +15,7 @@ module OldSql
|
|
15
15
|
|
16
16
|
def copy_old_sql_files
|
17
17
|
copy_file "#{gem_path}/public/stylesheets/old_sql/old_sql.css", "#{app_path}/public/stylesheets/old_sql/old_sql.css"
|
18
|
+
copy_file "#{gem_path}/public/stylesheets/old_sql/old_sql.css", "#{app_path}/public/stylesheets/old_sql/table.css"
|
18
19
|
copy_file "#{gem_path}/app/views/layouts/old_sql/report.html.erb", "#{app_path}/app/views/layouts/old_sql/report.html.erb"
|
19
20
|
end
|
20
21
|
|
@@ -61,6 +61,11 @@ module OldSql
|
|
61
61
|
copy_file "user_design_template.csv", "#{app_path}/config/old_sql/report_design/user_old_sql_demo.csv"
|
62
62
|
end
|
63
63
|
|
64
|
+
def configure_initializer
|
65
|
+
initializer_path = "#{app_path}/config/initializers/old_sql.rb"
|
66
|
+
gsub_file initializer_path, /DeviseModel/, "#{model_name.downcase}"
|
67
|
+
end
|
68
|
+
|
64
69
|
################ PRIVATE ################
|
65
70
|
|
66
71
|
private
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# Use this hook to configure the default report view, etc.
|
2
2
|
OldSql.setup do |config|
|
3
|
+
# The model used by devise. Ensure that the devise columns are installed in the model.
|
4
|
+
config.devise_model = 'DeviseModel'
|
5
|
+
|
3
6
|
# ==> Default Report View Configuration
|
4
7
|
# The title of the Report Selection View.
|
5
8
|
config.report_select_page_title = 'Old SQL Reports'
|
@@ -1,14 +1,25 @@
|
|
1
1
|
# Old SQL Reports YAML
|
2
2
|
# This is an example report. Replace it with your actual reports.
|
3
3
|
#
|
4
|
-
# '
|
5
|
-
#
|
4
|
+
# 'description' is the value displayed in the 'SELECT A REPORT' drop down list.
|
5
|
+
#
|
6
|
+
# The 'report_sql' file should be located under config/old_sql/report_sql.
|
7
|
+
# See config/old_sql/report_sql/user_old_sql_demo.sql for an example.
|
8
|
+
#
|
9
|
+
# The 'processor' parameter is optional, and should point to a class in lib/old_sql.
|
10
|
+
# See lib/old_sql/user_old_sql_demo_processor.rb for an example.
|
11
|
+
#
|
12
|
+
# 'report_processor' names should be capitalized and separated with underscores. The file
|
13
|
+
# itself should follow normal ruby class naming conventions.
|
14
|
+
#
|
15
|
+
# 'report_design' is also optional, and should point to a file in config/old_sql/report_design.
|
16
|
+
# See config/old_sql/report_design/user_old_sql_demo.csv for an example.
|
17
|
+
#
|
18
|
+
# The 'fields' are the headers for the report.
|
6
19
|
|
7
20
|
user:
|
8
|
-
|
9
|
-
value: User
|
21
|
+
description: User
|
10
22
|
report_sql: user_old_sql_demo
|
11
|
-
virality: false
|
12
23
|
report_design: user_old_sql_demo
|
13
24
|
#report_processor: User_Old_Sql_Demo_Processor
|
14
25
|
fields:
|
data/lib/old_sql.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module OldSql
|
2
2
|
require 'old_sql/engine' if defined?(Rails)
|
3
3
|
|
4
|
+
# The model used by devise. Ensure that the devise columns are installed in the model.
|
5
|
+
mattr_accessor :devise_model
|
6
|
+
@@devise_model = 'user'
|
7
|
+
|
4
8
|
# The title of the Report Selection View.
|
5
9
|
mattr_accessor :report_select_page_title
|
6
10
|
@@report_select_page_title = 'Old SQL Reports'
|
@@ -1,28 +1,13 @@
|
|
1
|
-
var _report_sql = '';
|
2
|
-
var _report_loaded = false;
|
3
|
-
|
4
|
-
function report_selected()
|
5
|
-
{
|
6
|
-
var virality = jQuery("#report option:selected").attr('virality');
|
7
|
-
_report_sql = jQuery("#report option:selected").attr('report_sql');
|
8
|
-
|
9
|
-
if (virality == 'true')
|
10
|
-
{
|
11
|
-
jQuery("#select-generation").removeAttr('disabled');
|
12
|
-
}
|
13
|
-
else
|
14
|
-
{
|
15
|
-
jQuery("#select-generation").attr('disabled', 'disabled');
|
16
|
-
jQuery("#select-generation option:first").attr('selected','selected');
|
17
|
-
}
|
18
|
-
}
|
19
|
-
|
20
1
|
function load_report()
|
21
2
|
{
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
3
|
+
report_name = jQuery("#report option:selected").attr('name');
|
4
|
+
report_sql = jQuery("#report option:selected").attr('report_sql');
|
5
|
+
|
6
|
+
if (!reported_selected(report_name)) return;
|
7
|
+
|
8
|
+
var src = "http://"+host+":"+port+"/sql/reports/"+report_view+"/?report="+report_name+
|
9
|
+
"&start_date="+jQuery("#datepicker-start").val()+"&end_date="+jQuery("#datepicker-end").val()+"&report_sql="+
|
10
|
+
report_sql;
|
26
11
|
|
27
12
|
jQuery('iframe').attr('src', src);
|
28
13
|
|
@@ -31,40 +16,45 @@ function load_report()
|
|
31
16
|
|
32
17
|
function print_report()
|
33
18
|
{
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
}
|
19
|
+
report_name = jQuery("#report option:selected").attr('name');
|
20
|
+
report_sql = jQuery("#report option:selected").attr('report_sql');
|
21
|
+
|
22
|
+
if (!reported_selected(report_name)) return;
|
39
23
|
|
40
|
-
var src = "http://"+host+":"+port+"/sql/reports/print/?report="+
|
41
|
-
"&start_date="+jQuery("#datepicker-start").val()+"&end_date="+jQuery("#datepicker-end").val()+
|
42
|
-
|
24
|
+
var src = "http://"+host+":"+port+"/sql/reports/print/?report="+report_name+
|
25
|
+
"&start_date="+jQuery("#datepicker-start").val()+"&end_date="+jQuery("#datepicker-end").val()+
|
26
|
+
"&report_sql="+report_sql+"&desc="+jQuery("#report option:selected").attr('desc');
|
43
27
|
window.open(src,'Old SQL Report')
|
44
28
|
}
|
45
29
|
|
46
30
|
function export_report_to_excel()
|
47
31
|
{
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
32
|
+
report_name = jQuery("#report option:selected").attr('name');
|
33
|
+
report_sql = jQuery("#report option:selected").attr('report_sql');
|
34
|
+
|
35
|
+
if (!reported_selected(report_name)) return;
|
53
36
|
|
54
|
-
var src = "http://"+host+":"+port+"/sql/reports/query.csv/?report="+
|
37
|
+
var src = "http://"+host+":"+port+"/sql/reports/query.csv/?report="+report_name+
|
55
38
|
"&start_date="+jQuery("#datepicker-start").val()+"&end_date="+jQuery("#datepicker-end").val()+
|
56
|
-
"&
|
57
|
-
_report_sql+"&desc="+jQuery("#report option:selected").attr('desc');
|
39
|
+
"&report_sql="+ report_sql+"&desc="+jQuery("#report option:selected").attr('desc');
|
58
40
|
window.open(src,'DB Report')
|
59
41
|
}
|
60
42
|
|
43
|
+
function reported_selected(report_name)
|
44
|
+
{
|
45
|
+
if (!report_name) {
|
46
|
+
alert("You must select a report, and run it before continuing.");
|
47
|
+
return false;
|
48
|
+
} else {
|
49
|
+
return true;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
61
53
|
jQuery(document).ready(function($){
|
62
54
|
jQuery("#datepicker-start").datetimepicker();
|
63
55
|
jQuery("#datepicker-start").datetimepicker( "option", "dateFormat", "yy/mm/dd" );
|
64
56
|
jQuery("#datepicker-end").datetimepicker();
|
65
57
|
jQuery("#datepicker-end").datetimepicker( "option", "dateFormat", "yy/mm/dd" );
|
66
|
-
|
67
|
-
jQuery("#select-generation").attr('disabled', 'disabled');
|
68
58
|
|
69
59
|
var now = new Date();
|
70
60
|
var tomorrow = new Date();
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: old_sql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.
|
5
|
+
version: 1.11.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Eddie Gonzales
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
requirements:
|
186
186
|
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
hash:
|
188
|
+
hash: 780971945359697670
|
189
189
|
segments:
|
190
190
|
- 0
|
191
191
|
version: "0"
|