old_sql 0.42.0 → 0.43.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/app/controllers/old_sql/report_controller.rb +1 -1
- data/lib/generators/old_sql/install_generator.rb +42 -40
- data/lib/generators/old_sql/templates/old_sql.rb +7 -0
- data/lib/generators/old_sql/templates/user_design_template.csv +6 -0
- data/lib/old_sql.rb +10 -0
- data/lib/old_sql/report_design/cell.rb +27 -0
- data/lib/old_sql/report_design/cell_data.rb +30 -0
- data/lib/old_sql/report_design/model.rb +21 -0
- data/lib/old_sql/report_design/parser.rb +28 -0
- data/lib/old_sql/report_design/row.rb +20 -0
- data/lib/old_sql/report_processor/base.rb +39 -7
- metadata +9 -2
|
@@ -46,7 +46,7 @@ module OldSql
|
|
|
46
46
|
logger.info "GENERATION: #{@generation}"
|
|
47
47
|
|
|
48
48
|
processor = load_processor(@report_name)
|
|
49
|
-
@report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name))
|
|
49
|
+
@report = processor.execute_query(@report_sql,@start_date,@end_date,query_vars(@report_name),@reports[@report_name]['report_design'])
|
|
50
50
|
|
|
51
51
|
respond_to do |format|
|
|
52
52
|
format.json { render :json => @report.to_json}
|
|
@@ -6,8 +6,7 @@ module OldSql
|
|
|
6
6
|
desc "Old SQL Install"
|
|
7
7
|
|
|
8
8
|
def check_for_devise
|
|
9
|
-
puts "Old SQL works with devise, cancan and sanitize. Checking for a current installation of devise
|
|
10
|
-
"
|
|
9
|
+
puts "Old SQL works with devise, cancan and sanitize. Checking for a current installation of devise!\n"
|
|
11
10
|
|
|
12
11
|
if defined?(Devise)
|
|
13
12
|
check_for_devise_models
|
|
@@ -16,16 +15,52 @@ module OldSql
|
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
puts "Please put gem 'cancan' into your Gemfile" unless defined?(Cancan)
|
|
19
|
-
|
|
20
18
|
puts "Please put gem 'sanitize' into your Gemfile" unless defined?(Sanitize)
|
|
21
|
-
|
|
22
|
-
copy_locales_files
|
|
23
|
-
create_old_sql_dirs
|
|
24
|
-
copy_old_sql_files
|
|
25
19
|
|
|
26
20
|
puts "Also you need a new migration. We'll generate it for you now."
|
|
27
21
|
invoke 'old_sql:install_migrations'
|
|
28
22
|
end
|
|
23
|
+
|
|
24
|
+
def copy_initializer
|
|
25
|
+
template "old_sql.rb", "config/initializers/old_sql.rb"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def copy_locales_files
|
|
29
|
+
print "Now copying locales files! "
|
|
30
|
+
###
|
|
31
|
+
locales_path = "#{gem_path}/config/locales/*.yml"
|
|
32
|
+
|
|
33
|
+
locales_app_path = "#{app_path}/config/locales"
|
|
34
|
+
|
|
35
|
+
unless File.directory?(locales_app_path)
|
|
36
|
+
FileUtils.mkdir locales_app_path
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Dir.glob(locales_path).each do |file|
|
|
40
|
+
file_path = file.split("/")
|
|
41
|
+
file_path = file_path[-1]
|
|
42
|
+
FileUtils.copy_file(file, "#{locales_app_path}/#{file_path}")
|
|
43
|
+
print "."
|
|
44
|
+
end
|
|
45
|
+
print "\n"
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def create_old_sql_dirs
|
|
50
|
+
empty_directory "#{app_path}/config/old_sql/"
|
|
51
|
+
empty_directory "#{app_path}/config/old_sql/report_sql"
|
|
52
|
+
empty_directory "#{app_path}/config/old_sql/report_design"
|
|
53
|
+
empty_directory "#{app_path}/lib/old_sql/report_processor"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def copy_old_sql_files
|
|
57
|
+
copy_file "#{gem_path}/config/old_sql/reports.yml.example", "#{app_path}/config/old_sql/reports.yml"
|
|
58
|
+
copy_file "#{gem_path}/config/old_sql/report_sql/user.erb.example", "#{app_path}/config/old_sql/report_sql/user.erb"
|
|
59
|
+
copy_file "#{gem_path}/lib/old_sql/report_processor/user_processor.rb.example", "#{app_path}/lib/old_sql/report_processor/user_processor.rb"
|
|
60
|
+
copy_file "user_design_template.csv", "#{app_path}/config/old_sql/report_design/user.csv"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
################ PRIVATE ################
|
|
29
64
|
|
|
30
65
|
private
|
|
31
66
|
|
|
@@ -137,39 +172,6 @@ module OldSql
|
|
|
137
172
|
======================================================"
|
|
138
173
|
invoke 'devise', [model_name]
|
|
139
174
|
end
|
|
140
|
-
|
|
141
|
-
def copy_locales_files
|
|
142
|
-
print "Now copying locales files! "
|
|
143
|
-
###
|
|
144
|
-
locales_path = "#{gem_path}/config/locales/*.yml"
|
|
145
|
-
|
|
146
|
-
locales_app_path = "#{app_path}/config/locales"
|
|
147
|
-
|
|
148
|
-
unless File.directory?(locales_app_path)
|
|
149
|
-
FileUtils.mkdir locales_app_path
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
Dir.glob(locales_path).each do |file|
|
|
153
|
-
file_path = file.split("/")
|
|
154
|
-
file_path = file_path[-1]
|
|
155
|
-
FileUtils.copy_file(file, "#{locales_app_path}/#{file_path}")
|
|
156
|
-
print "."
|
|
157
|
-
end
|
|
158
|
-
print "\n"
|
|
159
|
-
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
def create_old_sql_dirs
|
|
163
|
-
empty_directory "#{app_path}/config/old_sql/"
|
|
164
|
-
empty_directory "#{app_path}/config/old_sql/report_sql"
|
|
165
|
-
empty_directory "#{app_path}/lib/old_sql/report_processor"
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def copy_old_sql_files
|
|
169
|
-
copy_file "#{gem_path}/config/old_sql/reports.yml.example", "#{app_path}/config/old_sql/reports.yml"
|
|
170
|
-
copy_file "#{gem_path}/config/old_sql/report_sql/user.erb.example", "#{app_path}/config/old_sql/report_sql/user.erb"
|
|
171
|
-
copy_file "#{gem_path}/lib/old_sql/report_processor/user_processor.rb.example", "#{app_path}/lib/old_sql/report_processor/user_processor.rb"
|
|
172
|
-
end
|
|
173
175
|
|
|
174
176
|
def app_path
|
|
175
177
|
app_path = Rails.public_path.split("/")
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Use this hook to configure the default report view, etc.
|
|
2
|
+
OldSql.setup do |config|
|
|
3
|
+
# ==> Default Report View Configuration
|
|
4
|
+
# Configure the default report view. This setting will be used unless overridden
|
|
5
|
+
# in config/old_sql/reports.yml.
|
|
6
|
+
config.default_report_view = "jqgrid"
|
|
7
|
+
end
|
data/lib/old_sql.rb
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
module OldSql
|
|
2
2
|
require 'old_sql/engine' if defined?(Rails)
|
|
3
|
+
|
|
4
|
+
# The default report view. This setting will be used unless overridden in
|
|
5
|
+
# config/old_sql/reports.yml.
|
|
6
|
+
@@default_report_view = 'jqgrid'
|
|
7
|
+
|
|
8
|
+
# Default way to setup Old SQL. Run rails generate old_sql:install to create
|
|
9
|
+
# a fresh initializer with all configuration values.
|
|
10
|
+
def self.setup
|
|
11
|
+
yield self
|
|
12
|
+
end
|
|
3
13
|
end
|
|
4
14
|
|
|
5
15
|
require 'extensions/action_controller/base'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module OldSql
|
|
2
|
+
module ReportDesign
|
|
3
|
+
class Cell
|
|
4
|
+
attr_accessor :cell_data, :cell
|
|
5
|
+
|
|
6
|
+
def initialize(value)
|
|
7
|
+
@cell = value
|
|
8
|
+
@cell_data = []
|
|
9
|
+
|
|
10
|
+
# Check if cell is a label
|
|
11
|
+
if @cell[0] =~ /['"]/
|
|
12
|
+
@cell_data << CellData.new(@cell)
|
|
13
|
+
else
|
|
14
|
+
value.split(" ").each {|cell_data| @cell_data << CellData.new(cell_data)}
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def expression?
|
|
19
|
+
if @cell_data.count>1
|
|
20
|
+
return true
|
|
21
|
+
else
|
|
22
|
+
return false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module OldSql
|
|
2
|
+
module ReportDesign
|
|
3
|
+
class CellData
|
|
4
|
+
attr_accessor :data, :type
|
|
5
|
+
|
|
6
|
+
COLUMN = 1
|
|
7
|
+
LABEL = 2
|
|
8
|
+
OPERATOR = 3
|
|
9
|
+
|
|
10
|
+
def initialize(value)
|
|
11
|
+
@data = value
|
|
12
|
+
set_type
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def set_type
|
|
18
|
+
first_char = @data[0]
|
|
19
|
+
@type = case first_char
|
|
20
|
+
when /['"]/
|
|
21
|
+
LABEL
|
|
22
|
+
when /[\/*+]/
|
|
23
|
+
OPERATOR
|
|
24
|
+
else
|
|
25
|
+
COLUMN
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module OldSql
|
|
2
|
+
module ReportDesign
|
|
3
|
+
class Model
|
|
4
|
+
attr_accessor :rows
|
|
5
|
+
|
|
6
|
+
@rows = nil
|
|
7
|
+
|
|
8
|
+
def initialize(value = [])
|
|
9
|
+
@rows = value
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add(row)
|
|
13
|
+
@rows << Row.new(row) unless row[0] == "#"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def row(index)
|
|
17
|
+
@rows[index]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module OldSql
|
|
2
|
+
module ReportDesign
|
|
3
|
+
class Parser
|
|
4
|
+
def self.read_file file_to_read
|
|
5
|
+
raise ArgumentError, 'Argument file is null.' unless !file_to_read.nil?
|
|
6
|
+
full_path = "#{report_design_path}/#{file_to_read}"
|
|
7
|
+
raise ArgumentError, "File #{full_path} not found." unless File.exists?(full_path)
|
|
8
|
+
|
|
9
|
+
@model = Model.new
|
|
10
|
+
|
|
11
|
+
file = File.new(full_path, "r")
|
|
12
|
+
while (line = file.gets)
|
|
13
|
+
@model.add line
|
|
14
|
+
end
|
|
15
|
+
file.close
|
|
16
|
+
|
|
17
|
+
@model
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.report_design_path
|
|
21
|
+
app_path = Rails.public_path.split("/")
|
|
22
|
+
app_path.delete_at(-1)
|
|
23
|
+
app_path = app_path.join("/")
|
|
24
|
+
app_path << "/config/old_sql/report_design"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module OldSql
|
|
2
|
+
module ReportDesign
|
|
3
|
+
class Row
|
|
4
|
+
attr_accessor :data, :cells
|
|
5
|
+
|
|
6
|
+
def initialize(value)
|
|
7
|
+
@data = value
|
|
8
|
+
@cells = []
|
|
9
|
+
|
|
10
|
+
@data.split(",").each do |cell|
|
|
11
|
+
@cells << Cell.new(cell)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def cell(index)
|
|
16
|
+
@cells[index]
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -3,12 +3,8 @@ module OldSql
|
|
|
3
3
|
class Base
|
|
4
4
|
|
|
5
5
|
ROUND_PRECISION = 2
|
|
6
|
-
|
|
7
|
-
def hello_world
|
|
8
|
-
puts "Hello World"
|
|
9
|
-
end
|
|
10
6
|
|
|
11
|
-
def execute_query(report_sql,start_date,end_date,query_vars)
|
|
7
|
+
def execute_query(report_sql,start_date,end_date,query_vars,design=nil)
|
|
12
8
|
vars = {:start_date => start_date, :end_date => end_date}
|
|
13
9
|
|
|
14
10
|
if !query_vars.nil?
|
|
@@ -34,8 +30,12 @@ module OldSql
|
|
|
34
30
|
rescue
|
|
35
31
|
#todo log error
|
|
36
32
|
end
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
|
|
34
|
+
if design
|
|
35
|
+
parse_design(design, @resultset)
|
|
36
|
+
else
|
|
37
|
+
parse(@resultset)
|
|
38
|
+
end
|
|
39
39
|
|
|
40
40
|
@data
|
|
41
41
|
end
|
|
@@ -58,6 +58,38 @@ module OldSql
|
|
|
58
58
|
|
|
59
59
|
@data
|
|
60
60
|
end
|
|
61
|
+
|
|
62
|
+
def parse_design(design, resultset)
|
|
63
|
+
Rails.logger.info "PARSING DESIGN DOCUMENT #{design}.csv"
|
|
64
|
+
model = OldSql::ReportDesign::Parser.read_file("#{design}.csv")
|
|
65
|
+
|
|
66
|
+
init(resultset)
|
|
67
|
+
|
|
68
|
+
model.rows.each do |row|
|
|
69
|
+
report_row = []
|
|
70
|
+
row.cells.each do |cell|
|
|
71
|
+
expression = ""
|
|
72
|
+
cell.cell_data.each do |cd|
|
|
73
|
+
if cell.expression?
|
|
74
|
+
if cd.type == OldSql::ReportDesign::CellData::COLUMN
|
|
75
|
+
expression << @rec[cd.data].to_s
|
|
76
|
+
elsif cd.type == OldSql::ReportDesign::CellData::OPERATOR
|
|
77
|
+
expression << cd.data
|
|
78
|
+
end
|
|
79
|
+
else
|
|
80
|
+
if cd.type == OldSql::ReportDesign::CellData::COLUMN
|
|
81
|
+
report_row << @rec[cd.data]
|
|
82
|
+
elsif cd.type == OldSql::ReportDesign::CellData::LABEL
|
|
83
|
+
report_row << cd.data
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
report_row << eval(expression) unless expression.length==0
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
new_row(nil, report_row)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
61
93
|
|
|
62
94
|
def new_data(page=1, total=1, records=1)
|
|
63
95
|
@id = 0
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: old_sql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.
|
|
5
|
+
version: 0.43.0
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Eddie Gonzales
|
|
@@ -88,8 +88,15 @@ files:
|
|
|
88
88
|
- lib/generators/old_sql/templates/add_old_sql_admin_to_users_migration.rb
|
|
89
89
|
- lib/generators/old_sql/templates/devise/add_devise_to_users_migration.rb
|
|
90
90
|
- lib/generators/old_sql/templates/devise/devise_model.rb.template
|
|
91
|
+
- lib/generators/old_sql/templates/old_sql.rb
|
|
92
|
+
- lib/generators/old_sql/templates/user_design_template.csv
|
|
91
93
|
- lib/old_sql.rb
|
|
92
94
|
- lib/old_sql/engine.rb
|
|
95
|
+
- lib/old_sql/report_design/cell.rb
|
|
96
|
+
- lib/old_sql/report_design/cell_data.rb
|
|
97
|
+
- lib/old_sql/report_design/model.rb
|
|
98
|
+
- lib/old_sql/report_design/parser.rb
|
|
99
|
+
- lib/old_sql/report_design/row.rb
|
|
93
100
|
- lib/old_sql/report_processor/base.rb
|
|
94
101
|
- lib/old_sql/report_processor/user_processor.rb.example
|
|
95
102
|
- public/javascripts/old_sql/date_format.js
|
|
@@ -192,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
192
199
|
requirements:
|
|
193
200
|
- - ">="
|
|
194
201
|
- !ruby/object:Gem::Version
|
|
195
|
-
hash: -
|
|
202
|
+
hash: -3181007581839946414
|
|
196
203
|
segments:
|
|
197
204
|
- 0
|
|
198
205
|
version: "0"
|