wice_grid 3.5.0 → 3.6.0.pre1
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/.inch.yml +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +181 -0
- data/.travis.yml +22 -0
- data/{CHANGELOG → CHANGELOG.md} +95 -31
- data/Gemfile +4 -1
- data/README.md +1517 -0
- data/Rakefile +51 -7
- data/{SAVED_QUERIES_HOWTO.rdoc → SAVED_QUERIES_HOWTO.md} +34 -31
- data/TODO.md +16 -0
- data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +4 -6
- data/lib/generators/wice_grid/install_generator.rb +2 -5
- data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +1 -0
- data/lib/generators/wice_grid/templates/wice_grid_config.rb +29 -34
- data/lib/wice/active_record_column_wrapper.rb +36 -17
- data/lib/wice/columns.rb +53 -52
- data/lib/wice/columns/column_action.rb +11 -13
- data/lib/wice/columns/column_boolean.rb +9 -11
- data/lib/wice/columns/column_bootstrap_datepicker.rb +48 -0
- data/lib/wice/columns/column_custom_dropdown.rb +22 -23
- data/lib/wice/columns/column_float.rb +2 -6
- data/lib/wice/columns/column_html5_datepicker.rb +31 -0
- data/lib/wice/columns/column_integer.rb +9 -13
- data/lib/wice/columns/column_jquery_datepicker.rb +49 -0
- data/lib/wice/columns/column_processor_index.rb +18 -13
- data/lib/wice/columns/column_rails_date_helper.rb +41 -0
- data/lib/wice/columns/column_rails_datetime_helper.rb +40 -0
- data/lib/wice/columns/column_range.rb +7 -11
- data/lib/wice/columns/column_string.rb +24 -20
- data/lib/wice/columns/common_date_datetime_mixin.rb +20 -0
- data/lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb +39 -0
- data/lib/wice/columns/common_js_date_datetime_mixin.rb +15 -0
- data/lib/wice/columns/{column_date.rb → common_rails_date_datetime_conditions_generator_mixin.rb} +4 -22
- data/lib/wice/columns/common_standard_helper_date_datetime_mixin.rb +22 -0
- data/lib/wice/grid_output_buffer.rb +19 -10
- data/lib/wice/grid_renderer.rb +146 -85
- data/lib/wice/helpers/bs_calendar_helpers.rb +6 -7
- data/lib/wice/helpers/js_calendar_helpers.rb +19 -17
- data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +18 -18
- data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +44 -49
- data/lib/wice/helpers/wice_grid_view_helpers.rb +131 -134
- data/lib/wice/kaminari_monkey_patching.rb +3 -1
- data/lib/wice/table_column_matrix.rb +23 -8
- data/lib/wice/wice_grid_controller.rb +12 -16
- data/lib/wice/wice_grid_core_ext.rb +12 -20
- data/lib/wice/wice_grid_misc.rb +131 -53
- data/lib/wice/wice_grid_serialized_queries_controller.rb +10 -11
- data/lib/wice/wice_grid_serialized_query.rb +4 -3
- data/lib/wice/wice_grid_spreadsheet.rb +19 -18
- data/lib/wice_grid.rb +144 -135
- data/spec/schema.rb +9 -0
- data/spec/spec_helper.rb +75 -0
- data/spec/support/active_record.rb +11 -0
- data/spec/support/wice_grid_test_config.rb +172 -0
- data/spec/wice/grid_output_buffer_spec.rb +41 -0
- data/spec/wice/table_column_matrix_spec.rb +38 -0
- data/spec/wice/wice_grid_misc_spec.rb +159 -0
- data/spec/wice/wice_grid_spreadsheet_spec.rb +14 -0
- data/test/readme.txt +1 -1
- data/vendor/assets/javascripts/wice_grid_init.js.coffee +14 -8
- data/vendor/assets/stylesheets/wice_grid.scss +84 -0
- data/wice_grid.gemspec +32 -16
- metadata +217 -25
- data/README.rdoc +0 -1325
- data/lib/generators/wice_grid/templates/wice_grid.scss +0 -140
- data/lib/wice/columns/column_datetime.rb +0 -171
- data/vendor/assets/images/icons/grid/arrow_down.gif +0 -0
- data/vendor/assets/images/icons/grid/arrow_up.gif +0 -0
- data/vendor/assets/images/icons/grid/calendar_view_month.png +0 -0
- data/vendor/assets/images/icons/grid/collapse.gif +0 -0
- data/vendor/assets/images/icons/grid/delete.png +0 -0
- data/vendor/assets/images/icons/grid/expand.gif +0 -0
- data/vendor/assets/images/icons/grid/page_white_excel.png +0 -0
- data/vendor/assets/images/icons/grid/page_white_find.png +0 -0
- data/vendor/assets/images/icons/grid/table.png +0 -0
- data/vendor/assets/images/icons/grid/table_refresh.png +0 -0
- data/vendor/assets/images/icons/grid/tick_all.png +0 -0
- data/vendor/assets/images/icons/grid/untick_all.png +0 -0
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module Wice
|
2
3
|
class <<self
|
3
4
|
# Used in routes.rb to define routes to the query processing controller.
|
@@ -10,18 +11,16 @@ module Wice
|
|
10
11
|
controller = controller.to_s
|
11
12
|
|
12
13
|
map.post '/wice_grid_serialized_queries/:grid_name',
|
13
|
-
|
14
|
-
|
14
|
+
to: "#{controller}#create_saved_query",
|
15
|
+
as: 'create_serialized_query'
|
15
16
|
|
16
17
|
map.post '/wice_grid_serialized_queries/:grid_name/:id',
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
to: "#{controller}#delete_saved_query",
|
19
|
+
as: 'delete_serialized_query'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
module SerializedQueriesControllerMixin #:nodoc:
|
24
|
-
|
25
24
|
def delete_saved_query #:nodoc:
|
26
25
|
init
|
27
26
|
if sq = @query_store_model.find_by_id_and_grid_name(params[:id], @grid_name)
|
@@ -59,19 +58,19 @@ module Wice
|
|
59
58
|
@grid_title_id = "#{@grid_name}_title"
|
60
59
|
@notification_messages = NlMessage['query_saved_message']
|
61
60
|
else
|
62
|
-
@error_messages = @saved_query.errors.map{ |_, msg| msg }.join(' ')
|
61
|
+
@error_messages = @saved_query.errors.map { |_, msg| msg }.join(' ')
|
63
62
|
end
|
64
63
|
|
65
64
|
render_asyns_result
|
66
65
|
end
|
67
66
|
|
68
|
-
def extra
|
67
|
+
def extra #:nodoc:
|
69
68
|
params[:extra]
|
70
69
|
end
|
71
70
|
|
72
71
|
protected
|
73
72
|
|
74
|
-
def render_asyns_result
|
73
|
+
def render_asyns_result #:nodoc:
|
75
74
|
render json: {
|
76
75
|
'error_messages' => @error_messages,
|
77
76
|
'notification_messages' => @notification_messages,
|
@@ -80,9 +79,9 @@ module Wice
|
|
80
79
|
end
|
81
80
|
|
82
81
|
def init #:nodoc:
|
83
|
-
@query_store_model = ::Wice
|
82
|
+
@query_store_model = ::Wice.get_query_store_model
|
84
83
|
@confirm = params[:confirm] == '1' || params[:confirm] == 'true'
|
85
84
|
@grid_name = params[:grid_name]
|
86
85
|
end
|
87
86
|
end
|
88
|
-
end
|
87
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
class WiceGridSerializedQuery < ActiveRecord::Base #:nodoc:
|
2
3
|
serialize :query
|
3
4
|
|
@@ -5,9 +6,9 @@ class WiceGridSerializedQuery < ActiveRecord::Base #:nodoc:
|
|
5
6
|
|
6
7
|
validates_presence_of :name, message: 'Please submit the name of the custom query'
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
# returns a list of all serialized queries
|
10
|
+
def self.list(name, _controller)
|
11
|
+
conditions = { grid_name: name }
|
10
12
|
self.where(conditions).to_a
|
11
13
|
end
|
12
|
-
|
13
14
|
end
|
@@ -1,18 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Wice
|
5
|
+
class Spreadsheet #:nodoc:
|
6
|
+
|
7
|
+
#:nodoc:
|
8
|
+
attr_reader :tempfile
|
9
|
+
|
10
|
+
def initialize(name, field_separator) #:nodoc:
|
11
|
+
@tempfile = Tempfile.new(name)
|
12
|
+
@csv = CSV.new(@tempfile, col_sep: field_separator)
|
13
|
+
end
|
14
|
+
|
15
|
+
def << (row) #:nodoc:
|
16
|
+
@csv << row
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/wice_grid.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'wice/wice_grid_misc.rb'
|
2
3
|
require 'wice/wice_grid_core_ext.rb'
|
3
4
|
require 'wice/grid_renderer.rb'
|
@@ -15,50 +16,56 @@ require 'wice/wice_grid_spreadsheet.rb'
|
|
15
16
|
require 'wice/wice_grid_serialized_queries_controller.rb'
|
16
17
|
require 'wice/columns/column_processor_index.rb'
|
17
18
|
require 'wice/columns.rb'
|
19
|
+
require 'wice/columns/common_date_datetime_mixin.rb'
|
20
|
+
require 'wice/columns/common_standard_helper_date_datetime_mixin.rb'
|
21
|
+
require 'wice/columns/common_js_date_datetime_mixin.rb'
|
22
|
+
require 'wice/columns/common_js_date_datetime_conditions_generator_mixin.rb'
|
23
|
+
require 'wice/columns/common_rails_date_datetime_conditions_generator_mixin.rb'
|
18
24
|
require 'kaminari.rb'
|
19
25
|
|
20
|
-
|
21
26
|
ActionController::Base.send(:helper_method, :wice_grid_custom_filter_params)
|
22
27
|
|
23
28
|
module Wice
|
24
29
|
|
25
|
-
|
30
|
+
def self.on_action_view_load #:nodoc:
|
31
|
+
::ActionView::Base.class_eval { include Wice::GridViewHelper }
|
32
|
+
[ActionView::Helpers::AssetTagHelper,
|
33
|
+
ActionView::Helpers::TagHelper,
|
34
|
+
ActionView::Helpers::JavaScriptHelper,
|
35
|
+
ActionView::Helpers::FormTagHelper].each do |m|
|
36
|
+
JsCalendarHelpers.send(:include, m)
|
37
|
+
end
|
26
38
|
|
27
|
-
|
39
|
+
Columns.load_column_processors
|
40
|
+
require 'wice/wice_grid_serialized_query.rb'
|
28
41
|
|
42
|
+
# It is here only because of this: https://github.com/amatsuda/kaminari/pull/267
|
43
|
+
require 'wice/kaminari_monkey_patching.rb'
|
44
|
+
end
|
45
|
+
|
46
|
+
class WiceGridEngine < ::Rails::Engine #:nodoc:
|
47
|
+
initializer 'wice_grid_railtie.configure_rails_initialization' do |_app|
|
29
48
|
ActiveSupport.on_load :action_controller do
|
30
49
|
ActionController::Base.send(:include, Wice::Controller)
|
31
50
|
end
|
32
51
|
|
33
52
|
ActiveSupport.on_load :active_record do
|
34
53
|
ActiveRecord::ConnectionAdapters::Column.send(:include, ::Wice::WiceGridExtentionToActiveRecordColumn)
|
35
|
-
ActiveRecord::Base.send(:include, ::Wice::MergeConditions)
|
36
54
|
end
|
37
55
|
|
38
56
|
ActiveSupport.on_load :action_view do
|
39
|
-
::
|
40
|
-
[ActionView::Helpers::AssetTagHelper,
|
41
|
-
ActionView::Helpers::TagHelper,
|
42
|
-
ActionView::Helpers::JavaScriptHelper,
|
43
|
-
ActionView::Helpers::FormTagHelper].each do |m|
|
44
|
-
JsCalendarHelpers.send(:include, m)
|
45
|
-
end
|
46
|
-
|
47
|
-
Columns.load_column_processors
|
48
|
-
require 'wice/wice_grid_serialized_query.rb'
|
49
|
-
|
50
|
-
# It is here only until this pull request is pulled: https://github.com/amatsuda/kaminari/pull/267
|
51
|
-
require 'wice/kaminari_monkey_patching.rb'
|
57
|
+
::Wice.on_action_view_load
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
55
|
-
initializer
|
61
|
+
initializer 'wice_grid_railtie.configure_rails_assets_precompilation' do |app|
|
56
62
|
app.config.assets.precompile << 'icons/grid/*'
|
57
63
|
end
|
58
64
|
end
|
59
65
|
|
60
|
-
class WiceGrid
|
61
66
|
|
67
|
+
# Main class responsible for keeping the state of the grid, building an ActiveRelation, and running queries
|
68
|
+
class WiceGrid
|
62
69
|
attr_reader :klass, :name, :resultset, :custom_order, :query_store_model #:nodoc:
|
63
70
|
attr_reader :ar_options, :status, :export_to_csv_enabled, :csv_file_name, :csv_field_separator, :saved_query #:nodoc:
|
64
71
|
attr_writer :renderer #:nodoc:
|
@@ -70,29 +77,29 @@ module Wice
|
|
70
77
|
@controller = controller
|
71
78
|
|
72
79
|
@relation = klass_or_relation
|
73
|
-
@klass = @relation.
|
74
|
-
klass_or_relation
|
80
|
+
@klass = if @relation.is_a?(Class) && @relation.ancestors.index(ActiveRecord::Base)
|
81
|
+
klass_or_relation
|
82
|
+
else
|
75
83
|
klass_or_relation.klass
|
84
|
+
end
|
76
85
|
|
77
|
-
unless @klass.
|
78
|
-
|
86
|
+
unless @klass.is_a?(Class) && @klass.ancestors.index(ActiveRecord::Base)
|
87
|
+
fail WiceGridArgumentError.new('ActiveRecord model class (second argument) must be a Class derived from ActiveRecord::Base')
|
79
88
|
end
|
80
89
|
|
81
90
|
# validate :with_resultset & :with_paginated_resultset
|
82
91
|
[:with_resultset, :with_paginated_resultset].each do |callback_symbol|
|
83
92
|
unless [NilClass, Symbol, Proc].index(opts[callback_symbol].class)
|
84
|
-
|
93
|
+
fail WiceGridArgumentError.new(":#{callback_symbol} must be either a Proc or Symbol object")
|
85
94
|
end
|
86
95
|
end
|
87
96
|
|
88
|
-
opts[:order_direction].downcase! if opts[:order_direction].
|
97
|
+
opts[:order_direction].downcase! if opts[:order_direction].is_a?(String)
|
89
98
|
|
90
99
|
# validate :order_direction
|
91
|
-
if opts[:order_direction] && ! (opts[:order_direction] == 'asc'
|
92
|
-
opts[:order_direction] == :asc ||
|
93
|
-
opts[:order_direction] == 'desc' ||
|
100
|
+
if opts[:order_direction] && ! (opts[:order_direction] == 'asc' || opts[:order_direction] == :asc || opts[:order_direction] == 'desc' ||
|
94
101
|
opts[:order_direction] == :desc)
|
95
|
-
|
102
|
+
fail WiceGridArgumentError.new(":order_direction must be either 'asc' or 'desc'.")
|
96
103
|
end
|
97
104
|
|
98
105
|
begin
|
@@ -100,26 +107,27 @@ module Wice
|
|
100
107
|
@options = {
|
101
108
|
conditions: nil,
|
102
109
|
csv_file_name: nil,
|
103
|
-
csv_field_separator:
|
110
|
+
csv_field_separator: ConfigurationProvider.value_for(:CSV_FIELD_SEPARATOR),
|
104
111
|
custom_order: {},
|
105
|
-
enable_export_to_csv:
|
112
|
+
enable_export_to_csv: ConfigurationProvider.value_for(:ENABLE_EXPORT_TO_CSV),
|
106
113
|
group: nil,
|
107
114
|
include: nil,
|
108
115
|
joins: nil,
|
109
|
-
name:
|
116
|
+
name: ConfigurationProvider.value_for(:GRID_NAME),
|
110
117
|
order: nil,
|
111
|
-
order_direction:
|
118
|
+
order_direction: ConfigurationProvider.value_for(:ORDER_DIRECTION),
|
112
119
|
page: 1,
|
113
|
-
page_method_name:
|
114
|
-
per_page:
|
120
|
+
page_method_name: ConfigurationProvider.value_for(:PAGE_METHOD_NAME),
|
121
|
+
per_page: ConfigurationProvider.value_for(:PER_PAGE),
|
115
122
|
saved_query: nil,
|
116
123
|
total_entries: nil,
|
117
124
|
with_paginated_resultset: nil,
|
118
|
-
with_resultset: nil
|
125
|
+
with_resultset: nil,
|
126
|
+
use_default_scope: ConfigurationProvider.value_for(:USE_DEFAULT_SCOPE)
|
119
127
|
}
|
120
128
|
rescue NameError
|
121
|
-
raise NameError.new('A constant is missing in wice_grid_config.rb: ' +
|
122
|
-
'. This can happen when you upgrade the WiceGrid to a newer version with a new configuration constant. '
|
129
|
+
raise NameError.new('A constant is missing in wice_grid_config.rb: ' + $ERROR_INFO.message +
|
130
|
+
'. This can happen when you upgrade the WiceGrid to a newer version with a new configuration constant. ' \
|
123
131
|
'Add the constant manually or re-run `bundle exec rails g wice_grid:install`.')
|
124
132
|
end
|
125
133
|
# validate parameters
|
@@ -135,9 +143,9 @@ module Wice
|
|
135
143
|
when Symbol
|
136
144
|
@name = @name.to_s
|
137
145
|
else
|
138
|
-
|
146
|
+
fail WiceGridArgumentError.new('name of the grid should be a string or a symbol')
|
139
147
|
end
|
140
|
-
|
148
|
+
fail WiceGridArgumentError.new('name of the grid can only contain alphanumeruc characters') unless @name =~ /^[a-zA-Z\d_]*$/
|
141
149
|
|
142
150
|
@table_column_matrix = TableColumnMatrix.new
|
143
151
|
@table_column_matrix.default_model_class = @klass
|
@@ -162,7 +170,6 @@ module Wice
|
|
162
170
|
process_params
|
163
171
|
|
164
172
|
@ar_options_formed = false
|
165
|
-
|
166
173
|
end
|
167
174
|
|
168
175
|
# A block executed from within the plugin to process records of the current page.
|
@@ -212,18 +219,29 @@ module Wice
|
|
212
219
|
end
|
213
220
|
end
|
214
221
|
|
215
|
-
|
222
|
+
# declare_column(String, ActiveRecord, CustomFilterSpec, nil | string, nil | Boolean)
|
223
|
+
def declare_column(
|
224
|
+
column_name: nil,
|
225
|
+
model: nil,
|
226
|
+
custom_filter_active: nil,
|
227
|
+
table_alias: nil,
|
228
|
+
filter_type: nil,
|
229
|
+
assocs: []) #:nodoc:
|
230
|
+
|
231
|
+
|
232
|
+
@options[:include] = Wice.build_includes(@options[:include], assocs)
|
233
|
+
|
216
234
|
if model # this is an included table
|
217
235
|
column = @table_column_matrix.get_column_by_model_class_and_column_name(model, column_name)
|
218
|
-
|
236
|
+
fail WiceGridArgumentError.new("Column '#{column_name}' is not found in table '#{model.table_name}'!") if column.nil?
|
219
237
|
main_table = false
|
220
238
|
table_name = model.table_name
|
221
239
|
else
|
222
240
|
column = @table_column_matrix.get_column_in_default_model_class_by_column_name(column_name)
|
223
241
|
if column.nil?
|
224
|
-
|
225
|
-
"If '#{column_name}' belongs to another table you should declare it in :include or :join when initialising "
|
226
|
-
|
242
|
+
fail WiceGridArgumentError.new("Column '#{column_name}' is not found in table '#{@klass.table_name}'! " \
|
243
|
+
"If '#{column_name}' belongs to another table you should declare it in :include or :join when initialising " \
|
244
|
+
'the grid, and specify :model in column declaration.')
|
227
245
|
end
|
228
246
|
main_table = true
|
229
247
|
table_name = @table_column_matrix.default_model_class.table_name
|
@@ -238,14 +256,13 @@ module Wice
|
|
238
256
|
end
|
239
257
|
|
240
258
|
@table_column_matrix.add_condition(column, conditions)
|
241
|
-
|
242
|
-
|
243
|
-
|
259
|
+
|
260
|
+
# [ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column, String, Boolean]
|
261
|
+
[column, table_name, main_table]
|
244
262
|
end
|
245
263
|
end
|
246
264
|
|
247
265
|
def form_ar_options(opts = {}) #:nodoc:
|
248
|
-
|
249
266
|
return if @ar_options_formed
|
250
267
|
@ar_options_formed = true unless opts[:forget_generated_options]
|
251
268
|
|
@@ -266,11 +283,17 @@ module Wice
|
|
266
283
|
# @status.delete(:f)
|
267
284
|
# end
|
268
285
|
|
269
|
-
|
286
|
+
initial_conditions_active_relation = @klass.where(@status[:conditions])
|
287
|
+
|
288
|
+
@ar_options[:conditions] =
|
289
|
+
@table_column_matrix.conditions.reduce(initial_conditions_active_relation) do |active_relation_accu, cond|
|
290
|
+
conditions_active_relation = @klass.where(cond)
|
291
|
+
active_relation_accu.merge(conditions_active_relation)
|
292
|
+
end
|
270
293
|
|
271
294
|
# conditions processed
|
272
295
|
|
273
|
-
if (!
|
296
|
+
if (!opts[:skip_ordering]) && ! @status[:order].blank?
|
274
297
|
@ar_options[:order] = add_custom_order_sql(complete_column_name(@status[:order]))
|
275
298
|
|
276
299
|
@ar_options[:order] += ' ' + @status[:order_direction]
|
@@ -287,19 +310,15 @@ module Wice
|
|
287
310
|
if (show_all_limit = Wice::ConfigurationProvider.value_for(:SHOW_ALL_ALLOWED_UP_TO, strict: false)) && all_record_mode?
|
288
311
|
if do_count > show_all_limit # force-reset SHOW-ALL to pagination
|
289
312
|
@status[:pp] = nil
|
290
|
-
else
|
291
|
-
# no resetting
|
292
313
|
end
|
293
314
|
end
|
294
315
|
|
295
316
|
end
|
296
|
-
|
297
317
|
end
|
298
318
|
|
299
|
-
|
300
|
-
def add_references relation
|
319
|
+
def add_references(relation) #:nodoc:
|
301
320
|
if @ar_options[:include] && relation.respond_to?(:references)
|
302
|
-
refs = [@ar_options[:include]] unless @ar_options[:include].is_a?(Array)
|
321
|
+
# refs = [@ar_options[:include]] unless @ar_options[:include].is_a?(Array)
|
303
322
|
relation = relation.references(* @ar_options[:include])
|
304
323
|
end
|
305
324
|
relation
|
@@ -308,27 +327,27 @@ module Wice
|
|
308
327
|
# TO DO: what to do with other @ar_options values?
|
309
328
|
def read #:nodoc:
|
310
329
|
form_ar_options
|
311
|
-
|
330
|
+
use_default_or_unscoped do
|
312
331
|
@resultset = if self.output_csv? || all_record_mode?
|
313
|
-
relation = @relation
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
332
|
+
relation = @relation
|
333
|
+
.includes(@ar_options[:include])
|
334
|
+
.joins(@ar_options[:joins])
|
335
|
+
.order(@ar_options[:order])
|
336
|
+
.group(@ar_options[:group])
|
337
|
+
.merge(@ar_options[:conditions])
|
319
338
|
relation = add_references relation
|
320
339
|
|
321
340
|
relation
|
322
341
|
else
|
323
342
|
# p @ar_options
|
324
|
-
relation = @relation
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
343
|
+
relation = @relation
|
344
|
+
.send(@options[:page_method_name], @ar_options[:page])
|
345
|
+
.per(@ar_options[:per_page])
|
346
|
+
.includes(@ar_options[:include])
|
347
|
+
.joins(@ar_options[:joins])
|
348
|
+
.order(@ar_options[:order])
|
349
|
+
.group(@ar_options[:group])
|
350
|
+
.merge(@ar_options[:conditions])
|
332
351
|
|
333
352
|
relation = add_references relation
|
334
353
|
|
@@ -338,7 +357,6 @@ module Wice
|
|
338
357
|
invoke_resultset_callbacks
|
339
358
|
end
|
340
359
|
|
341
|
-
|
342
360
|
# core workflow methods END
|
343
361
|
|
344
362
|
# Getters
|
@@ -366,7 +384,7 @@ module Wice
|
|
366
384
|
|
367
385
|
def ordered_by?(column) #:nodoc:
|
368
386
|
return nil if @status[:order].blank?
|
369
|
-
if column.main_table && !
|
387
|
+
if column.main_table && ! @status[:order].index('.')
|
370
388
|
@status[:order] == column.attribute
|
371
389
|
else
|
372
390
|
@status[:order] == column.table_alias_or_table_name + '.' + column.attribute
|
@@ -377,13 +395,12 @@ module Wice
|
|
377
395
|
@status[:order]
|
378
396
|
end
|
379
397
|
|
380
|
-
|
381
398
|
def order_direction #:nodoc:
|
382
399
|
@status[:order_direction]
|
383
400
|
end
|
384
401
|
|
385
402
|
def filtering_on? #:nodoc:
|
386
|
-
|
403
|
+
!@status[:f].blank?
|
387
404
|
end
|
388
405
|
|
389
406
|
def filtered_by #:nodoc:
|
@@ -391,7 +408,7 @@ module Wice
|
|
391
408
|
end
|
392
409
|
|
393
410
|
def filtered_by?(view_column) #:nodoc:
|
394
|
-
@status[:f].nil? ? false : @status[:f].
|
411
|
+
@status[:f].nil? ? false : @status[:f].key?(view_column.attribute_name_fully_qualified_for_all_but_main_table_columns)
|
395
412
|
end
|
396
413
|
|
397
414
|
def get_state_as_parameter_value_pairs(including_saved_query_request = false) #:nodoc:
|
@@ -410,13 +427,13 @@ module Wice
|
|
410
427
|
end
|
411
428
|
|
412
429
|
if including_saved_query_request && @saved_query
|
413
|
-
res << ["#{name}[q]", @saved_query.id
|
430
|
+
res << ["#{name}[q]", @saved_query.id]
|
414
431
|
end
|
415
432
|
|
416
|
-
[:order, :order_direction].select
|
433
|
+
[:order, :order_direction].select do|parameter|
|
417
434
|
status[parameter]
|
418
|
-
|
419
|
-
res << ["#{name}[#{parameter}]", status[parameter]
|
435
|
+
end.collect do |parameter|
|
436
|
+
res << ["#{name}[#{parameter}]", status[parameter]]
|
420
437
|
end
|
421
438
|
|
422
439
|
res
|
@@ -427,13 +444,14 @@ module Wice
|
|
427
444
|
do_count
|
428
445
|
end
|
429
446
|
|
430
|
-
def do_count
|
431
|
-
@relation
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
447
|
+
def do_count #:nodoc:
|
448
|
+
@relation
|
449
|
+
.all
|
450
|
+
.merge(@ar_options[:conditions]).count(
|
451
|
+
joins: @ar_options[:joins],
|
452
|
+
include: @ar_options[:include],
|
453
|
+
group: @ar_options[:group]
|
454
|
+
)
|
437
455
|
end
|
438
456
|
|
439
457
|
alias_method :size, :count
|
@@ -444,12 +462,11 @@ module Wice
|
|
444
462
|
|
445
463
|
# with this variant we get even those values which do not appear in the resultset
|
446
464
|
def distinct_values_for_column(column) #:nodoc:
|
447
|
-
|
465
|
+
column.model.select("distinct #{column.name}").order("#{column.name} asc").collect do|ar|
|
448
466
|
ar[column.name]
|
449
|
-
|
467
|
+
end.reject(&:blank?).map { |i| [i, i] }
|
450
468
|
end
|
451
469
|
|
452
|
-
|
453
470
|
def distinct_values_for_column_in_resultset(messages) #:nodoc:
|
454
471
|
uniq_vals = Set.new
|
455
472
|
|
@@ -457,15 +474,15 @@ module Wice
|
|
457
474
|
v = ar.deep_send(*messages)
|
458
475
|
uniq_vals << v unless v.nil?
|
459
476
|
end
|
460
|
-
|
477
|
+
uniq_vals.to_a.map do|i|
|
461
478
|
if i.is_a?(Array) && i.size == 2
|
462
479
|
i
|
463
480
|
elsif i.is_a?(Hash) && i.size == 1
|
464
481
|
i.to_a.flatten
|
465
482
|
else
|
466
|
-
[i,i]
|
483
|
+
[i, i]
|
467
484
|
end
|
468
|
-
|
485
|
+
end.sort { |a, b| a[0] <=> b[0] }
|
469
486
|
end
|
470
487
|
|
471
488
|
def output_csv? #:nodoc:
|
@@ -481,27 +498,23 @@ module Wice
|
|
481
498
|
end
|
482
499
|
|
483
500
|
def dump_status #:nodoc:
|
484
|
-
" params: #{params[name].inspect}\n"
|
485
|
-
|
486
|
-
" ar_options #{@ar_options.inspect}\n"
|
501
|
+
" params: #{params[name].inspect}\n" + " status: #{@status.inspect}\n" \
|
502
|
+
" ar_options #{@ar_options.inspect}\n"
|
487
503
|
end
|
488
504
|
|
489
|
-
|
490
505
|
# Returns the list of objects browsable through all pages with the current filters.
|
491
506
|
# Should only be called after the +grid+ helper.
|
492
507
|
def all_pages_records
|
493
|
-
|
508
|
+
fail WiceGridException.new('all_pages_records can only be called only after the grid view helper') unless self.view_helper_finished
|
494
509
|
resultset_without_paging_with_user_filters
|
495
510
|
end
|
496
511
|
|
497
512
|
# Returns the list of objects displayed on current page. Should only be called after the +grid+ helper.
|
498
513
|
def current_page_records
|
499
|
-
|
514
|
+
fail WiceGridException.new('current_page_records can only be called only after the grid view helper') unless self.view_helper_finished
|
500
515
|
@resultset
|
501
516
|
end
|
502
517
|
|
503
|
-
|
504
|
-
|
505
518
|
protected
|
506
519
|
|
507
520
|
def invoke_resultset_callback(callback, argument) #:nodoc:
|
@@ -518,22 +531,18 @@ module Wice
|
|
518
531
|
invoke_resultset_callback(@options[:with_resultset], self.active_relation_for_resultset_without_paging_with_user_filters)
|
519
532
|
end
|
520
533
|
|
521
|
-
|
522
|
-
|
523
534
|
def add_custom_order_sql(fully_qualified_column_name) #:nodoc:
|
524
|
-
custom_order = if @options[:custom_order].
|
535
|
+
custom_order = if @options[:custom_order].key?(fully_qualified_column_name)
|
525
536
|
@options[:custom_order][fully_qualified_column_name]
|
526
537
|
else
|
527
538
|
if view_column = @renderer[fully_qualified_column_name]
|
528
539
|
view_column.custom_order
|
529
|
-
else
|
530
|
-
nil
|
531
540
|
end
|
532
541
|
end
|
533
542
|
|
534
543
|
if custom_order.blank?
|
535
544
|
if ActiveRecord::ConnectionAdapters.const_defined?(:SQLite3Adapter) && ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::SQLite3Adapter)
|
536
|
-
fully_qualified_column_name.strip.split('.').map{|chunk| ActiveRecord::Base.connection.quote_table_name(chunk)}.join('.')
|
545
|
+
fully_qualified_column_name.strip.split('.').map { |chunk| ActiveRecord::Base.connection.quote_table_name(chunk) }.join('.')
|
537
546
|
else
|
538
547
|
ActiveRecord::Base.connection.quote_table_name(fully_qualified_column_name.strip)
|
539
548
|
end
|
@@ -543,7 +552,7 @@ module Wice
|
|
543
552
|
elsif custom_order.is_a? Proc
|
544
553
|
custom_order.call(fully_qualified_column_name)
|
545
554
|
else
|
546
|
-
|
555
|
+
fail WiceGridArgumentError.new("invalid custom order #{custom_order.inspect}")
|
547
556
|
end
|
548
557
|
end
|
549
558
|
end
|
@@ -564,14 +573,14 @@ module Wice
|
|
564
573
|
params[name]
|
565
574
|
end
|
566
575
|
|
567
|
-
|
568
576
|
def resultset_without_paging_without_user_filters #:nodoc:
|
569
577
|
form_ar_options
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
578
|
+
|
579
|
+
use_default_or_unscoped do
|
580
|
+
relation = @relation.joins(@ar_options[:joins])
|
581
|
+
.includes(@ar_options[:include])
|
582
|
+
.group(@ar_options[:group])
|
583
|
+
.where(@options[:conditions])
|
575
584
|
|
576
585
|
relation = add_references relation
|
577
586
|
|
@@ -593,35 +602,39 @@ module Wice
|
|
593
602
|
# end
|
594
603
|
|
595
604
|
def resultset_without_paging_with_user_filters #:nodoc:
|
596
|
-
|
597
|
-
active_relation_for_resultset_without_paging_with_user_filters.to_a
|
598
|
-
end
|
605
|
+
active_relation_for_resultset_without_paging_with_user_filters.to_a
|
599
606
|
end
|
600
607
|
|
601
608
|
def active_relation_for_resultset_without_paging_with_user_filters #:nodoc:
|
602
609
|
form_ar_options
|
603
610
|
relation = nil
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
611
|
+
|
612
|
+
use_default_or_unscoped do
|
613
|
+
relation = @relation
|
614
|
+
.joins(@ar_options[:joins])
|
615
|
+
.includes(@ar_options[:include])
|
616
|
+
.order(@ar_options[:order])
|
617
|
+
.merge(@ar_options[:conditions])
|
610
618
|
|
611
619
|
relation = add_references relation
|
612
620
|
end
|
613
621
|
relation
|
614
622
|
end
|
615
623
|
|
616
|
-
|
617
|
-
|
618
624
|
def load_query(query_id) #:nodoc:
|
619
|
-
@query_store_model ||= Wice
|
625
|
+
@query_store_model ||= Wice.get_query_store_model
|
620
626
|
query = @query_store_model.find_by_id_and_grid_name(query_id, self.name)
|
621
|
-
Wice
|
627
|
+
Wice.log("Query with id #{query_id} for grid '#{self.name}' not found!!!") if query.nil?
|
622
628
|
query
|
623
629
|
end
|
624
630
|
|
631
|
+
def use_default_or_unscoped #:nodoc:
|
632
|
+
if @options[:use_default_scope]
|
633
|
+
yield
|
634
|
+
else
|
635
|
+
@klass.unscoped { yield }
|
636
|
+
end
|
637
|
+
end
|
625
638
|
|
626
639
|
end
|
627
640
|
|
@@ -635,7 +648,7 @@ module Wice
|
|
635
648
|
# create a Time instance out of parameters
|
636
649
|
def params_2_datetime(par) #:nodoc:
|
637
650
|
return nil if par.blank?
|
638
|
-
params = [par[:year], par[:month], par[:day], par[:hour], par[:minute]].collect{|v| v.blank? ? nil : v.to_i}
|
651
|
+
params = [par[:year], par[:month], par[:day], par[:hour], par[:minute]].collect { |v| v.blank? ? nil : v.to_i }
|
639
652
|
begin
|
640
653
|
Time.local(*params)
|
641
654
|
rescue ArgumentError, TypeError
|
@@ -646,17 +659,13 @@ module Wice
|
|
646
659
|
# create a Date instance out of parameters
|
647
660
|
def params_2_date(par) #:nodoc:
|
648
661
|
return nil if par.blank?
|
649
|
-
params = [par[:year], par[:month], par[:day]].collect{|v| v.blank? ? nil : v.to_i}
|
662
|
+
params = [par[:year], par[:month], par[:day]].collect { |v| v.blank? ? nil : v.to_i }
|
650
663
|
begin
|
651
664
|
Date.civil(*params)
|
652
665
|
rescue ArgumentError, TypeError
|
653
666
|
nil
|
654
667
|
end
|
655
668
|
end
|
656
|
-
|
657
669
|
end
|
658
670
|
end
|
659
|
-
|
660
|
-
|
661
|
-
|
662
671
|
end
|