clark_kent 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/app/controllers/clark_kent/report_filters_controller.rb +1 -1
- data/app/helpers/clark_kent/application_helper.rb +10 -2
- data/app/models/clark_kent/report.rb +18 -16
- data/app/models/clark_kent/report_column.rb +8 -1
- data/app/models/clark_kent/report_config.rb +5 -1
- data/app/models/clark_kent/reportable.rb +16 -11
- data/app/models/clark_kent/sharing_scope_kind.rb +0 -4
- data/app/views/clark_kent/report_filters/_object_filter_edit.html.erb +1 -1
- data/app/views/clark_kent/reports/show.html.erb +2 -2
- data/lib/clark_kent/version.rb +1 -1
- data/test/controllers/clark_kent/reports_controller_test.rb +1 -0
- data/test/dummy/app/controllers/orders_controller.rb +5 -0
- data/test/dummy/app/models/reporting/order.rb +6 -6
- data/test/dummy/app/views/orders/show.html.erb +14 -0
- data/test/dummy/config/routes.rb +2 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +2952 -0
- data/test/dummy/log/test.log +3051 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/0ec37c0a58c1be93659732a3efc73581 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/0fd54fd98cd2fa0085b77e6743046927 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8aa37926d964a9eb59cf9b940e4fe2f4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/0ec37c0a58c1be93659732a3efc73581 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/0fd54fd98cd2fa0085b77e6743046927 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/8aa37926d964a9eb59cf9b940e4fe2f4 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a5cb2db96ead480ab3da69947c4adb9d3d224d6
|
4
|
+
data.tar.gz: 1ea114b60fb78c8b7e8aed2484fc908345df6ee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c46a94dfc0fead2b2c8ca15ae1e8b4db836a870749812ad43033f722e0dfbd812e1d3c4e6796735b12ad944e7349efedd9ea8e5c11241b895cfcc1720b1c0a8
|
7
|
+
data.tar.gz: c2008aeaca8c54ce0d9c644c7acd9ddaa5050c44320e05da0f5a5bd20d86256fb9340d004b5f93a6fe66a3512f8925f72112bc015428b1834cfcc6e3eb983412
|
@@ -50,7 +50,7 @@ class ClarkKent::ReportFiltersController < ClarkKent::ApplicationController
|
|
50
50
|
|
51
51
|
def report_filter_params
|
52
52
|
if @report_filter
|
53
|
-
these_params = params[@report_filter.class.name.underscore]
|
53
|
+
these_params = params[@report_filter.class.name.underscore.gsub(/.*\//,'')]
|
54
54
|
else
|
55
55
|
these_params = params[:report_filter]
|
56
56
|
end
|
@@ -33,9 +33,9 @@ module ClarkKent
|
|
33
33
|
(value =~ /\d/) && (value =~ /\./) && !(value =~ /[a-zA-Z]/)
|
34
34
|
end
|
35
35
|
|
36
|
-
def display_for_value(value,
|
36
|
+
def display_for_value(value, column=nil)
|
37
37
|
##TODO, genericize this link display. link info must come from model config.
|
38
|
-
return link_to(value, main_app.
|
38
|
+
return link_to(value, main_app.send(column.link, id: value)) if column.try(:link) && value.present?
|
39
39
|
return value.join(', ') if value.is_a? Array
|
40
40
|
return value.to_formatted_s(:datepicker) if value.is_a? Date
|
41
41
|
return number_to_currency(value) if value.is_a? Float or value.is_a? BigDecimal or is_decimal?(value)
|
@@ -67,5 +67,13 @@ module ClarkKent
|
|
67
67
|
onclick: raw(onclick_str)
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
def collection_for(report_filter,name)
|
72
|
+
if report_filter.filterable.collection_for(name).is_a? Symbol
|
73
|
+
@filter_collections.send(report_filter.filterable.collection_for(name))
|
74
|
+
else
|
75
|
+
report_filter.filterable.collection_for(name)
|
76
|
+
end
|
77
|
+
end
|
70
78
|
end
|
71
79
|
end
|
@@ -20,7 +20,6 @@ module ClarkKent
|
|
20
20
|
validates :sharing_scope_id, presence: true, if: ->(r) { r.sharing_scope_type.present? }
|
21
21
|
|
22
22
|
def self.send_report_to_s3(report_id, params)
|
23
|
-
params = params
|
24
23
|
report_class = params['report_class'].constantize if params['report_class']
|
25
24
|
report_class ||= ::ClarkKent::Report
|
26
25
|
reportable = report_class.find(report_id)
|
@@ -114,35 +113,35 @@ module ClarkKent
|
|
114
113
|
def arel_includes
|
115
114
|
self.report_columns.map{|column|
|
116
115
|
column_info = self.column_options_for(column.column_name)
|
117
|
-
column_info.includes
|
116
|
+
column_info.includes
|
118
117
|
}.compact
|
119
118
|
end
|
120
119
|
|
121
120
|
def arel_joins
|
122
121
|
self.report_columns.map{|column|
|
123
122
|
column_info = self.column_options_for(column.column_name)
|
124
|
-
column_info.joins
|
123
|
+
column_info.joins
|
125
124
|
}.compact
|
126
125
|
end
|
127
126
|
|
128
127
|
def extra_scopes
|
129
128
|
self.report_columns.map{|column|
|
130
129
|
column_info = self.column_options_for(column.column_name)
|
131
|
-
column_info.extra_scopes
|
130
|
+
column_info.extra_scopes
|
132
131
|
}.flatten.compact
|
133
132
|
end
|
134
133
|
|
135
134
|
def extra_filters
|
136
135
|
self.report_columns.map{|column|
|
137
136
|
column_info = self.column_options_for(column.column_name)
|
138
|
-
column_info.where
|
137
|
+
column_info.where
|
139
138
|
}.flatten.compact
|
140
139
|
end
|
141
140
|
|
142
141
|
def groups
|
143
142
|
self.report_columns.map{|column|
|
144
143
|
column_info = self.column_options_for(column.column_name)
|
145
|
-
column_info.group
|
144
|
+
column_info.group
|
146
145
|
}.flatten.compact
|
147
146
|
end
|
148
147
|
|
@@ -158,27 +157,30 @@ module ClarkKent
|
|
158
157
|
@selects = []
|
159
158
|
self.report_columns.each do |report_column|
|
160
159
|
column_option = self.column_options_for(report_column.column_name)
|
161
|
-
@selects.push column_option.custom_select
|
160
|
+
@selects.push column_option.custom_select
|
162
161
|
end
|
163
162
|
self.report_filters.each do |report_filter|
|
164
|
-
column_option = self.column_options_for(report_filter.filter_name)
|
165
|
-
@selects.push column_option.custom_select if column_option.
|
163
|
+
column_option = self.column_options_for(report_filter.filter_name.to_sym)
|
164
|
+
@selects.push column_option.custom_select if column_option.present?
|
166
165
|
end
|
167
166
|
@selects
|
168
167
|
end
|
169
168
|
|
170
|
-
|
171
169
|
def filter_options_for(filter_name)
|
172
170
|
self.resource_class::REPORT_FILTER_OPTIONS.detect{|filter| filter.param == filter_name}
|
173
171
|
end
|
174
172
|
|
173
|
+
def column_options
|
174
|
+
@column_options ||= self.resource_class::REPORT_COLUMN_OPTIONS
|
175
|
+
end
|
176
|
+
|
175
177
|
def column_options_for(column_name)
|
176
|
-
if
|
177
|
-
|
178
|
+
if column_options.any?{|co| co.name == column_name.to_sym}
|
179
|
+
column_options.detect{|co| co.name == column_name.to_sym}
|
178
180
|
else
|
179
181
|
column_name = column_name.to_s.split('_')[0..-2].join('_')
|
180
|
-
if
|
181
|
-
|
182
|
+
if column_options.any?{|co| co.name == column_name.to_sym}
|
183
|
+
column_options.detect{|co| co.name == column_name.to_sym}
|
182
184
|
end
|
183
185
|
end
|
184
186
|
end
|
@@ -220,11 +222,11 @@ module ClarkKent
|
|
220
222
|
## This is the set of columns not chosed to use in the report. These are the ones available to add
|
221
223
|
## when updating a report.
|
222
224
|
def available_columns
|
223
|
-
|
225
|
+
column_options.reject{|column| self.report_columns.pluck(:column_name).include? column.name.to_s}
|
224
226
|
end
|
225
227
|
|
226
228
|
def sortable?(column)
|
227
|
-
|
229
|
+
self.column_options_for(column.column_name).order_sql.present?
|
228
230
|
end
|
229
231
|
|
230
232
|
def sharing_scope_pretty
|
@@ -18,13 +18,20 @@ module ClarkKent
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def summarizable?
|
21
|
-
report.column_options_for(self.column_name).summarizable
|
21
|
+
report.column_options_for(self.column_name.to_sym).summarizable
|
22
22
|
end
|
23
23
|
|
24
24
|
def calculator
|
25
25
|
('ClarkKent::' + summary_method.camelcase + 'Calculator').constantize
|
26
26
|
end
|
27
27
|
|
28
|
+
def name
|
29
|
+
column_name
|
30
|
+
end
|
31
|
+
|
32
|
+
def link
|
33
|
+
report.column_options_for(self.name.to_sym).link
|
34
|
+
end
|
28
35
|
end
|
29
36
|
|
30
37
|
class AbstractCalculator
|
@@ -16,9 +16,13 @@ module ClarkKent
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
class ReportColumnConfig
|
19
|
-
attr_accessor :
|
19
|
+
attr_accessor :name, :order_sql, :custom_select, :link, :summarizable, :includes, :joins, :extra_scopes, :where, :group
|
20
20
|
def initialize params = {}
|
21
21
|
params.each { |key, value| send "#{key}=", value }
|
22
22
|
end
|
23
|
+
|
24
|
+
def id
|
25
|
+
name
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
@@ -72,16 +72,17 @@ module ClarkKent
|
|
72
72
|
arel_method_name = self.arel_method_for(param_type)
|
73
73
|
if arel_method_name.present?
|
74
74
|
query = self.send(arel_method_name, query, param_type, param_value)
|
75
|
-
report_column_options =
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
75
|
+
if report_column_options = column_options_for(param_type)
|
76
|
+
if(report_column_options.joins.present?) && (@joins.exclude? report_column_options.joins)
|
77
|
+
@joins.push report_column_options.joins
|
78
|
+
end
|
79
|
+
if(report_column_options.includes.present?) && (@includes.exclude? report_column_options.includes)
|
80
|
+
@includes.push report_column_options.includes
|
81
|
+
end
|
82
|
+
if (count == false) && (report_column_options.custom_select.present?) && (@selects.exclude? report_column_options.custom_select)
|
83
|
+
@selects.push report_column_options.custom_select
|
84
|
+
end
|
85
|
+
end
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
@@ -115,6 +116,10 @@ module ClarkKent
|
|
115
116
|
|
116
117
|
end
|
117
118
|
|
119
|
+
def column_options_for(column_name)
|
120
|
+
self::REPORT_COLUMN_OPTIONS.detect{|co| column_name == co.name}
|
121
|
+
end
|
122
|
+
|
118
123
|
def arel_method_for(param_type)
|
119
124
|
method_name = self::AREL_METHODS[param_type.to_s]
|
120
125
|
method_name ||= "#{param_type}_arel" if self.respond_to? "#{param_type}_arel"
|
@@ -153,7 +158,7 @@ module ClarkKent
|
|
153
158
|
else
|
154
159
|
order_column, order_direction = match_value.split('-')
|
155
160
|
end
|
156
|
-
column_info =
|
161
|
+
column_info = column_options_for(order_column.to_sym)
|
157
162
|
if column_info.respond_to? :order_sql
|
158
163
|
order_sql = column_info.order_sql
|
159
164
|
order_sql = "#{order_sql} #{order_direction}"
|
@@ -49,10 +49,7 @@ module ClarkKent
|
|
49
49
|
def self.select_options_for_user(user)
|
50
50
|
sharing_scope_options = {}
|
51
51
|
self.all.each do |sharing_scope_kind|
|
52
|
-
puts sharing_scope_kind.to_yaml
|
53
52
|
if custom.exclude?(sharing_scope_kind) || has_some(sharing_scope_kind.associated_containers_for(user))
|
54
|
-
puts sharing_scope_kind.class_name
|
55
|
-
puts sharing_scope_kind.human_name
|
56
53
|
sharing_scope_options[sharing_scope_kind.human_name] = sharing_scope_kind.class_name
|
57
54
|
end
|
58
55
|
end
|
@@ -76,7 +73,6 @@ module ClarkKent
|
|
76
73
|
else
|
77
74
|
@human_name = @class_name.humanize
|
78
75
|
end
|
79
|
-
puts @human_name
|
80
76
|
@human_name
|
81
77
|
end
|
82
78
|
|
@@ -1 +1 @@
|
|
1
|
-
<%= f.input :filter_value, collection:
|
1
|
+
<%= f.input :filter_value, collection: collection_for(report_filter, name) %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<h1><%= @report.name %></h1>
|
2
2
|
<%= link_to "← back to report index".html_safe, reports_url, id: 'report_index' %>
|
3
|
-
|
3
|
+
<%= controller_name %>
|
4
4
|
<% if @errors %>
|
5
5
|
<div class="error">
|
6
6
|
<%= @errors %>
|
@@ -33,7 +33,7 @@
|
|
33
33
|
<% @rows.each do |row| %>
|
34
34
|
<tr>
|
35
35
|
<% @report.report_columns.each do |column| %>
|
36
|
-
<td><%= display_for_value(row[column.column_name], column
|
36
|
+
<td><%= display_for_value(row[column.column_name], column) %></td>
|
37
37
|
<% end %>
|
38
38
|
</tr>
|
39
39
|
<% end if @rows.present? %>
|
data/lib/clark_kent/version.rb
CHANGED
@@ -39,6 +39,7 @@ module ClarkKent
|
|
39
39
|
test "should show report results" do
|
40
40
|
get :show, id: @report, current_user_id: @current_user.id, run_report: true, created_at_until: Date.today, created_at_from: Date.yesterday
|
41
41
|
assert_response :success
|
42
|
+
assert_not_nil assigns(:rows)
|
42
43
|
@response.body.must_match 'Guitar strings'
|
43
44
|
end
|
44
45
|
|
@@ -23,17 +23,17 @@ module Reporting
|
|
23
23
|
]
|
24
24
|
|
25
25
|
# These are the available column options for building reports from this resource
|
26
|
-
REPORT_COLUMN_OPTIONS ||=
|
27
|
-
|
26
|
+
REPORT_COLUMN_OPTIONS ||= [
|
27
|
+
column_config(name: :user_name,
|
28
28
|
custom_select: "
|
29
29
|
(SELECT u.name
|
30
30
|
FROM users u
|
31
31
|
WHERE u.id = orders.user_id)
|
32
32
|
as user_name"),
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
column_config(name: :id, order_sql: 'orders.id', link: :order_path),
|
34
|
+
column_config(name: :amount, order_sql: 'orders.amount', summarizable: true),
|
35
|
+
column_config(name: :description, order_sql: 'orders.description')
|
36
|
+
]
|
37
37
|
|
38
38
|
def self.included(base)
|
39
39
|
base.extend ClassMethods
|
data/test/dummy/config/routes.rb
CHANGED
Binary file
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|