clark_kent 0.9.2 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/clark_kent/report.rb +8 -8
- data/app/models/clark_kent/report_config.rb +8 -12
- data/app/models/clark_kent/report_email.rb +1 -1
- data/app/models/clark_kent/reportable.rb +152 -160
- data/app/views/clark_kent/reports/_edit.html.erb +0 -2
- data/lib/clark_kent.rb +1 -1
- data/lib/clark_kent/version.rb +1 -1
- data/test/dummy/app/models/order.rb +1 -1
- data/test/dummy/app/models/reporting/order.rb +39 -38
- data/test/dummy/config/initializers/zz_clark_kent.rb +0 -1
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +6856 -0
- data/test/models/clark_kent/reportable_test.rb +32 -25
- metadata +381 -367
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cff67d05d931728a4d59a4a6fda5228dbd06eeff
|
4
|
+
data.tar.gz: b9d6e364e1cdd574c34f995b1a9434847886a476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f50b2f886b9d98d75cf32a5d854d3e2460173655834233764c80252504d8d217280fe8139cce95eb2b49bac5fd5893cc9759aa2da0f3461220db67a88bf9fc9e
|
7
|
+
data.tar.gz: 00600cad919cf0694d33cbd53e8ac4922078176c55279f3dd494c9edbb2a99b58cfc3a1a73a0f34d4dd28f383555f15e69b56f2d6f408c859cacc1a3e65281c2
|
@@ -177,11 +177,11 @@ require 'aws-sdk-v1'
|
|
177
177
|
end
|
178
178
|
|
179
179
|
def filter_options_for(filter_name)
|
180
|
-
self.resource_class
|
180
|
+
self.resource_class.report_filter_options.detect{|filter| filter.param == filter_name}
|
181
181
|
end
|
182
182
|
|
183
183
|
def column_options
|
184
|
-
@column_options ||= self.resource_class
|
184
|
+
@column_options ||= self.resource_class.report_column_options
|
185
185
|
end
|
186
186
|
|
187
187
|
def column_options_for(column_name)
|
@@ -200,7 +200,7 @@ require 'aws-sdk-v1'
|
|
200
200
|
end
|
201
201
|
|
202
202
|
def date_filter_names
|
203
|
-
self.resource_class
|
203
|
+
self.resource_class.report_filter_options.select{|filter| 'date_filter' == filter.kind}.map{|filter| filter.param}
|
204
204
|
end
|
205
205
|
|
206
206
|
## These are the filters available for defining a report for this resource. They do not include date
|
@@ -210,23 +210,23 @@ require 'aws-sdk-v1'
|
|
210
210
|
end
|
211
211
|
|
212
212
|
def available_filter_options
|
213
|
-
self.available_filters.map{|
|
213
|
+
self.available_filters.map{|filter_name| [self.filter_options_for(filter_name).label,filter_name]}
|
214
214
|
end
|
215
215
|
|
216
216
|
## This is the full set of filter options for defining a report, including the date filters for
|
217
217
|
## an automatic, timed, emailed report.
|
218
218
|
def available_email_filters
|
219
|
-
self.resource_class
|
219
|
+
self.resource_class.report_definition_options.reject{|name| (viable_report_filters.map(&:filter_name)).include? name}
|
220
220
|
end
|
221
221
|
|
222
222
|
def collection_for(filter_name)
|
223
|
-
self.
|
223
|
+
self.filter_options_for(filter_name).collection
|
224
224
|
end
|
225
225
|
|
226
226
|
## These are the filters available at runtime, ie. not including the ones set to define this report.
|
227
227
|
## If updating the report, this is the set available to add as new report definition filters.
|
228
228
|
def custom_filters
|
229
|
-
self.resource_class
|
229
|
+
self.resource_class.report_filter_options.select{|filter| viable_report_filters.map(&:filter_name).exclude? filter.param}
|
230
230
|
end
|
231
231
|
|
232
232
|
## This is the set of columns not chosed to use in the report. These are the ones available to add
|
@@ -253,7 +253,7 @@ require 'aws-sdk-v1'
|
|
253
253
|
end
|
254
254
|
|
255
255
|
def get_filter_class(params)
|
256
|
-
filter_option = self.resource_class
|
256
|
+
filter_option = self.resource_class.report_filter_options.detect{|filter| filter.param == params[:filter_name]}
|
257
257
|
"ClarkKent::Report#{filter_option.kind.camelcase}".constantize
|
258
258
|
end
|
259
259
|
|
@@ -1,19 +1,15 @@
|
|
1
1
|
module ClarkKent
|
2
2
|
module ReportConfig
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def column_config(params)
|
10
|
-
ClarkKent::ReportColumnConfig.new(params)
|
11
|
-
end
|
3
|
+
include ClarkKent::Reportable
|
4
|
+
def filter_config(params)
|
5
|
+
filter_option_class = ('ClarkKent::' + ((params[:kind] + '_option').camelcase)).constantize
|
6
|
+
filter_option_class.new(params)
|
12
7
|
end
|
13
|
-
|
14
|
-
def
|
15
|
-
|
8
|
+
|
9
|
+
def column_config(params)
|
10
|
+
ClarkKent::ReportColumnConfig.new(params)
|
16
11
|
end
|
12
|
+
|
17
13
|
end
|
18
14
|
class ReportColumnConfig
|
19
15
|
attr_accessor :name, :order_sql, :custom_select, :link, :time_zone_column, :time_format, :summarizable, :includes, :joins, :extra_scopes, :where, :group
|
@@ -86,7 +86,7 @@ module ClarkKent
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def available_email_filters
|
89
|
-
self.resource_class
|
89
|
+
self.resource_class.report_definition_options.reject{|name, label| (self.viable_report_filters.pluck(:filter_name) + self.report.viable_report_filters.pluck(:filter_name)).include? name}
|
90
90
|
end
|
91
91
|
|
92
92
|
def available_filters
|
@@ -1,182 +1,174 @@
|
|
1
1
|
module ClarkKent
|
2
2
|
module Reportable
|
3
|
-
def
|
4
|
-
|
3
|
+
def chain_up(query, params)
|
4
|
+
params.each do |key,val|
|
5
|
+
arel_method_name = self.arel_method_for(key)
|
6
|
+
if arel_method_name.present? and self.respond_to? arel_method_name and val.present?
|
7
|
+
query = self.send(arel_method_name, query, key, val)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
query = query.distinct if params[:distinct]
|
11
|
+
query
|
5
12
|
end
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
params.each do |key,val|
|
11
|
-
arel_method_name = self.arel_method_for(key)
|
12
|
-
if arel_method_name.present? and self.respond_to? arel_method_name and val.present?
|
13
|
-
query = self.send(arel_method_name, query, key, val)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
query = query.distinct if params[:distinct]
|
17
|
-
query
|
18
|
-
end
|
14
|
+
def required_date_params
|
15
|
+
self.report_filter_options.select{|rfo| rfo.in_required_date_group}.map{|rfo| rfo.filter_params}.flatten.map(&:to_sym)
|
16
|
+
end
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
def validate_params(params,report)
|
19
|
+
if required_date_params.any?
|
20
|
+
missing_params = required_date_params - params.select{|k,v| v.present? }.symbolize_keys.keys
|
21
|
+
# a bit clunky, it only requires any 2 date filters. It would be better to require at least one pair of before/after filters
|
22
|
+
if missing_params.length > (required_date_params.length - 2)
|
23
|
+
raise ClarkKent::ReportFilterError.new("At least one date range is required.")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
def report(params,report,count = false)
|
29
|
+
@selects = []
|
30
|
+
@includes = []
|
31
|
+
@joins = []
|
32
|
+
@extra_scopes = []
|
33
|
+
@extra_filters = []
|
34
|
+
@groups = []
|
35
|
+
if 'ClarkKent::ReportEmail' == report.class.name
|
36
|
+
@report_email = report
|
37
|
+
report = @report_email.report
|
38
|
+
end
|
39
|
+
if count == false
|
40
|
+
report.select_clauses.each do |select_clause|
|
41
|
+
@selects.push select_clause
|
31
42
|
end
|
43
|
+
end
|
44
|
+
report.arel_includes.each do |arel_include|
|
45
|
+
@includes.push arel_include
|
32
46
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
params = @report_email.report_filter_params.symbolize_keys!.merge(params.symbolize_keys)
|
68
|
-
else
|
69
|
-
params = report.report_filter_params.symbolize_keys!.merge(params.symbolize_keys)
|
70
|
-
end
|
71
|
-
validate_params(params, report)
|
72
|
-
params.each do |param_type,param_value|
|
73
|
-
if param_value.present?
|
74
|
-
arel_method_name = self.arel_method_for(param_type)
|
75
|
-
if arel_method_name.present?
|
76
|
-
query = self.send(arel_method_name, query, param_type, param_value)
|
77
|
-
if report_column_options = column_options_for(param_type)
|
78
|
-
if(report_column_options.joins.present?) && (@joins.exclude? report_column_options.joins)
|
79
|
-
@joins.push report_column_options.joins
|
80
|
-
end
|
81
|
-
if(report_column_options.includes.present?) && (@includes.exclude? report_column_options.includes)
|
82
|
-
@includes.push report_column_options.includes
|
83
|
-
end
|
84
|
-
if (count == false) && (report_column_options.custom_select.present?) && (@selects.exclude? report_column_options.custom_select)
|
85
|
-
@selects.push report_column_options.custom_select
|
86
|
-
end
|
87
|
-
end
|
47
|
+
report.arel_joins.each do |arel_join|
|
48
|
+
@joins.push arel_join
|
49
|
+
end
|
50
|
+
report.extra_scopes.each do |extra_scope|
|
51
|
+
@extra_scopes.push extra_scope
|
52
|
+
end
|
53
|
+
report.extra_filters.each do |extra_filter|
|
54
|
+
@extra_filters.push extra_filter
|
55
|
+
end
|
56
|
+
report.groups.each do |grouper|
|
57
|
+
@groups.push grouper
|
58
|
+
end
|
59
|
+
query = self.all
|
60
|
+
if @report_email and @report_email.is_a? ClarkKent::ReportEmail
|
61
|
+
params = @report_email.report_filter_params.symbolize_keys!.merge(params.symbolize_keys)
|
62
|
+
else
|
63
|
+
params = report.report_filter_params.symbolize_keys!.merge(params.symbolize_keys)
|
64
|
+
end
|
65
|
+
validate_params(params, report)
|
66
|
+
params.each do |param_type,param_value|
|
67
|
+
if param_value.present?
|
68
|
+
arel_method_name = self.arel_method_for(param_type)
|
69
|
+
if arel_method_name.present?
|
70
|
+
query = self.send(arel_method_name, query, param_type, param_value)
|
71
|
+
if report_column_options = column_options_for(param_type)
|
72
|
+
if(report_column_options.joins.present?) && (@joins.exclude? report_column_options.joins)
|
73
|
+
@joins.push report_column_options.joins
|
74
|
+
end
|
75
|
+
if(report_column_options.includes.present?) && (@includes.exclude? report_column_options.includes)
|
76
|
+
@includes.push report_column_options.includes
|
77
|
+
end
|
78
|
+
if (count == false) && (report_column_options.custom_select.present?) && (@selects.exclude? report_column_options.custom_select)
|
79
|
+
@selects.push report_column_options.custom_select
|
80
|
+
end
|
88
81
|
end
|
89
|
-
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
if @selects.any?
|
86
|
+
query = query.select("DISTINCT " + self.column_names.map{|cn| self.table_name + '.' + cn}.join(', '))
|
87
|
+
@selects.uniq.each do |selectable|
|
88
|
+
query = query.select(selectable)
|
90
89
|
end
|
91
|
-
if @selects.any?
|
92
|
-
query = query.select("DISTINCT " + self.column_names.map{|cn| self.table_name + '.' + cn}.join(', '))
|
93
|
-
@selects.uniq.each do |selectable|
|
94
|
-
query = query.select(selectable)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
if self.respond_to? :clark_kent_required_filters
|
98
|
-
query = self.send(:clark_kent_required_filters, query)
|
99
|
-
end
|
100
|
-
@includes.uniq.each do |includeable|
|
101
|
-
query = query.includes(includeable)
|
102
|
-
end if @includes.any?
|
103
|
-
@extra_scopes.uniq.each do |extra_scope|
|
104
|
-
query = query.send(extra_scope)
|
105
|
-
end if @extra_scopes.any?
|
106
|
-
@extra_filters.uniq.each do |extra_filter|
|
107
|
-
query = query.where(extra_filter)
|
108
|
-
end if @extra_filters.any?
|
109
|
-
@joins.uniq.each do |joinable|
|
110
|
-
query = query.joins(joinable).uniq
|
111
|
-
end if @joins.any?
|
112
|
-
@groups.uniq.each do |grouper|
|
113
|
-
query = query.group(grouper)
|
114
|
-
end if @groups.any?
|
115
|
-
if count == true
|
116
|
-
return query.count
|
117
|
-
else
|
118
|
-
return query
|
119
|
-
end
|
120
|
-
|
121
90
|
end
|
122
|
-
|
123
|
-
|
124
|
-
self::REPORT_COLUMN_OPTIONS.detect{|co| column_name == co.name}
|
91
|
+
if self.respond_to? :clark_kent_required_filters
|
92
|
+
query = self.send(:clark_kent_required_filters, query)
|
125
93
|
end
|
94
|
+
@includes.uniq.each do |includeable|
|
95
|
+
query = query.includes(includeable)
|
96
|
+
end if @includes.any?
|
97
|
+
@extra_scopes.uniq.each do |extra_scope|
|
98
|
+
query = query.send(extra_scope)
|
99
|
+
end if @extra_scopes.any?
|
100
|
+
@extra_filters.uniq.each do |extra_filter|
|
101
|
+
query = query.where(extra_filter)
|
102
|
+
end if @extra_filters.any?
|
103
|
+
@joins.uniq.each do |joinable|
|
104
|
+
query = query.joins(joinable).uniq
|
105
|
+
end if @joins.any?
|
106
|
+
@groups.uniq.each do |grouper|
|
107
|
+
query = query.group(grouper)
|
108
|
+
end if @groups.any?
|
109
|
+
if count == true
|
110
|
+
return query.count
|
111
|
+
else
|
112
|
+
return query
|
113
|
+
end
|
126
114
|
|
127
|
-
|
128
|
-
method_name = self::AREL_METHODS[param_type.to_s]
|
129
|
-
method_name ||= "#{param_type}_arel" if self.respond_to? "#{param_type}_arel"
|
130
|
-
method_name
|
131
|
-
end
|
115
|
+
end
|
132
116
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
end
|
117
|
+
def column_options_for(column_name)
|
118
|
+
self.report_column_options.detect{|co| column_name == co.name}
|
119
|
+
end
|
137
120
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
121
|
+
def arel_method_for(param_type)
|
122
|
+
method_name = self.arel_methods[param_type.to_s]
|
123
|
+
method_name ||= "#{param_type}_arel" if self.respond_to? "#{param_type}_arel"
|
124
|
+
method_name
|
125
|
+
end
|
142
126
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
127
|
+
def simple_equality_arel(query, field_name, match_value)
|
128
|
+
query.
|
129
|
+
where(field_name.to_sym => match_value)
|
130
|
+
end
|
147
131
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
132
|
+
def before_date_arel(query, field_name, match_value)
|
133
|
+
query.
|
134
|
+
where("#{self.table_name}.#{field_name.to_s.sub(/_until/,'')} <= :date_limit", date_limit: match_value)
|
135
|
+
end
|
152
136
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
137
|
+
def after_date_arel(query, field_name, match_value)
|
138
|
+
query.
|
139
|
+
where("#{self.table_name}.#{field_name.to_s.sub(/_from/,'')} >= :date_limit", date_limit: match_value)
|
140
|
+
end
|
157
141
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
order_sql = column_info.order_sql
|
168
|
-
order_sql = "#{order_sql} #{order_direction}"
|
169
|
-
query = query.order(order_sql)
|
170
|
-
if column_info.respond_to? :includes
|
171
|
-
order_includes = column_info.includes
|
172
|
-
query = query.includes(order_includes).references(order_includes)
|
173
|
-
end
|
174
|
-
query
|
175
|
-
else
|
176
|
-
query
|
177
|
-
end
|
178
|
-
end
|
142
|
+
def above_number_arel(query, field_name, match_value)
|
143
|
+
query.
|
144
|
+
where("#{self.table_name}.#{field_name.to_s.sub(/_above/,'')} >= :lower_limit", lower_limit: match_value)
|
145
|
+
end
|
146
|
+
|
147
|
+
def below_number_arel(query, field_name, match_value)
|
148
|
+
query.
|
149
|
+
where("#{self.table_name}.#{field_name.to_s.sub(/_below/,'')} <= :upper_limit", upper_limit: match_value)
|
150
|
+
end
|
179
151
|
|
180
|
-
|
152
|
+
def order_arel(query, field_name, match_value)
|
153
|
+
if match_value.is_a? ClarkKent::ReportSort
|
154
|
+
order_column = match_value.order_column
|
155
|
+
order_direction = match_value.order_direction
|
156
|
+
else
|
157
|
+
order_column, order_direction = match_value.split('-')
|
158
|
+
end
|
159
|
+
column_info = column_options_for(order_column.to_sym)
|
160
|
+
if column_info.respond_to?(:order_sql) && column_info.order_sql.present?
|
161
|
+
order_sql = column_info.order_sql
|
162
|
+
order_sql = "#{order_sql} #{order_direction}"
|
163
|
+
query = query.order(order_sql)
|
164
|
+
if column_info.respond_to? :includes
|
165
|
+
order_includes = column_info.includes
|
166
|
+
query = query.includes(order_includes).references(order_includes)
|
167
|
+
end
|
168
|
+
query
|
169
|
+
else
|
170
|
+
query
|
171
|
+
end
|
172
|
+
end
|
181
173
|
end
|
182
174
|
end
|
@@ -18,8 +18,6 @@
|
|
18
18
|
label: false, include_blank: false %>
|
19
19
|
</div>
|
20
20
|
<div class="ih-row" <%= revealer_target_attrs("sharing_options") %>>
|
21
|
-
<%= ClarkKent.user_class_name %>
|
22
|
-
|
23
21
|
<%= f.input :sharing_scope_id, as: :hidden, input_html: {value: current_user.id, data: {foo: ClarkKent.user_class_name}}, wrapper_html: revealer_option("sharing_options", trigger: ClarkKent.user_class_name).merge(id: "sharing_options_#{ClarkKent.user_class_name}") %>
|
24
22
|
<% ClarkKent::SharingScopeKind.custom_for_user(current_user).each do |sharing_scope_kind| %>
|
25
23
|
<% if sharing_scope_kind.associated_containers_for(current_user).respond_to? :each %>
|