wice_grid_ms 3.6.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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.inch.yml +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +181 -0
- data/.travis.yml +22 -0
- data/CHANGELOG.md +714 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +1518 -0
- data/Rakefile +59 -0
- data/SAVED_QUERIES_HOWTO.md +113 -0
- data/TODO.md +16 -0
- data/app/views/kaminari/wice_grid/_gap.html.erb +1 -0
- data/app/views/kaminari/wice_grid/_next_page.html.erb +1 -0
- data/app/views/kaminari/wice_grid/_page.html.erb +1 -0
- data/app/views/kaminari/wice_grid/_paginator.html.erb +19 -0
- data/app/views/kaminari/wice_grid/_prev_page.html.erb +1 -0
- data/config/locales/cz.yml +45 -0
- data/config/locales/de.yml +47 -0
- data/config/locales/en.yml +47 -0
- data/config/locales/es.yml +47 -0
- data/config/locales/fr.yml +45 -0
- data/config/locales/is.yml +46 -0
- data/config/locales/it.yml +38 -0
- data/config/locales/ja.yml +47 -0
- data/config/locales/nl.yml +45 -0
- data/config/locales/pt-BR.yml +36 -0
- data/config/locales/pt.yml +45 -0
- data/config/locales/ru.yml +45 -0
- data/config/locales/sk.yml +45 -0
- data/config/locales/uk.yml +45 -0
- data/config/locales/zh.yml +45 -0
- data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +20 -0
- data/lib/generators/wice_grid/install_generator.rb +14 -0
- data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +14 -0
- data/lib/generators/wice_grid/templates/wice_grid_config.rb +192 -0
- data/lib/wice/active_record_column_wrapper.rb +123 -0
- data/lib/wice/columns.rb +276 -0
- data/lib/wice/columns/column_action.rb +52 -0
- data/lib/wice/columns/column_boolean.rb +40 -0
- data/lib/wice/columns/column_bootstrap_datepicker.rb +48 -0
- data/lib/wice/columns/column_custom_dropdown.rb +115 -0
- data/lib/wice/columns/column_float.rb +9 -0
- data/lib/wice/columns/column_html5_datepicker.rb +31 -0
- data/lib/wice/columns/column_integer.rb +78 -0
- data/lib/wice/columns/column_jquery_datepicker.rb +49 -0
- data/lib/wice/columns/column_processor_index.rb +23 -0
- 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 +72 -0
- data/lib/wice/columns/column_string.rb +92 -0
- data/lib/wice/columns/common_date_datetime_mixin.rb +20 -0
- data/lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb +42 -0
- data/lib/wice/columns/common_js_date_datetime_mixin.rb +15 -0
- data/lib/wice/columns/common_rails_date_datetime_conditions_generator_mixin.rb +26 -0
- data/lib/wice/columns/common_standard_helper_date_datetime_mixin.rb +22 -0
- data/lib/wice/grid_output_buffer.rb +49 -0
- data/lib/wice/grid_renderer.rb +609 -0
- data/lib/wice/helpers/bs_calendar_helpers.rb +66 -0
- data/lib/wice/helpers/js_calendar_helpers.rb +83 -0
- data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +75 -0
- data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +95 -0
- data/lib/wice/helpers/wice_grid_view_helpers.rb +718 -0
- data/lib/wice/kaminari_monkey_patching.rb +14 -0
- data/lib/wice/table_column_matrix.rb +65 -0
- data/lib/wice/wice_grid_controller.rb +223 -0
- data/lib/wice/wice_grid_core_ext.rb +142 -0
- data/lib/wice/wice_grid_misc.rb +209 -0
- data/lib/wice/wice_grid_serialized_queries_controller.rb +87 -0
- data/lib/wice/wice_grid_serialized_query.rb +14 -0
- data/lib/wice/wice_grid_spreadsheet.rb +20 -0
- data/lib/wice_grid.rb +676 -0
- data/release_notes/RELEASE_NOTES_3.2.pre1.rdoc +81 -0
- data/release_notes/RELEASE_NOTES_3.2.pre2.rdoc +6 -0
- data/release_notes/RELEASE_NOTES_3.3.0.rdoc +21 -0
- 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 +175 -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 -0
- data/vendor/assets/javascripts/wice_grid.js +3 -0
- data/vendor/assets/javascripts/wice_grid_init.js.coffee +339 -0
- data/vendor/assets/javascripts/wice_grid_processor.js.coffee +133 -0
- data/vendor/assets/javascripts/wice_grid_saved_queries_init.js.coffee +103 -0
- data/vendor/assets/stylesheets/wice_grid.scss +81 -0
- data/wice_grid.gemspec +36 -0
- metadata +335 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WiceGrid #:nodoc:
|
3
|
+
module Generators #:nodoc:
|
4
|
+
class AddMigrationForSerializedQueriesGenerator < Rails::Generators::Base #:nodoc:
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
desc 'Add a migration which creates a table for serialized queries'
|
8
|
+
|
9
|
+
source_root File.expand_path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def self.next_migration_number(_path)
|
12
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_model_file
|
16
|
+
migration_template 'create_wice_grid_serialized_queries.rb', 'db/migrate/create_wice_grid_serialized_queries.rb'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module WiceGrid #:nodoc:
|
3
|
+
module Generators #:nodoc:
|
4
|
+
class InstallGenerator < Rails::Generators::Base #:nodoc:
|
5
|
+
desc 'Copy WiceGrid wice_grid_config.rb to config/initializers'
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
def copy_stuff #:nodoc:
|
10
|
+
template 'wice_grid_config.rb', 'config/initializers/wice_grid_config.rb'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class CreateWiceGridSerializedQueries < ::ActiveRecord::Migration #:nodoc:
|
3
|
+
def change #:nodoc:
|
4
|
+
create_table :wice_grid_serialized_queries do |t|
|
5
|
+
t.column :name, :string
|
6
|
+
t.column :grid_name, :string
|
7
|
+
t.column :query, :text
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :wice_grid_serialized_queries, :grid_name
|
12
|
+
add_index :wice_grid_serialized_queries, [:grid_name, :id]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
if defined?(Wice::Defaults)
|
3
|
+
|
4
|
+
# Default number of rows to show per page.
|
5
|
+
Wice::Defaults::PER_PAGE = 20
|
6
|
+
|
7
|
+
# Default order direction
|
8
|
+
Wice::Defaults::ORDER_DIRECTION = 'asc'
|
9
|
+
|
10
|
+
# Default name for a grid. A grid name is the basis for a lot of
|
11
|
+
# names including parameter names, DOM IDs, etc
|
12
|
+
# The shorter the name is the shorter the request URI will be.
|
13
|
+
Wice::Defaults::GRID_NAME = 'grid'
|
14
|
+
|
15
|
+
# If REUSE_LAST_COLUMN_FOR_FILTER_ICONS is true and the last column doesn't have any filter and column name, it will be used
|
16
|
+
# for filter related icons (filter icon, reset icon, show/hide icon), otherwise an additional table column is added.
|
17
|
+
Wice::Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS = true
|
18
|
+
|
19
|
+
# The label of the first option of a custom dropdown list meaning 'All items'
|
20
|
+
Wice::Defaults::CUSTOM_FILTER_ALL_LABEL = '--'
|
21
|
+
|
22
|
+
# A list of classes for the table tag of the grid
|
23
|
+
Wice::Defaults::DEFAULT_TABLE_CLASSES = ['table', 'table-bordered', 'table-striped']
|
24
|
+
|
25
|
+
# Allow switching between a single and multiple selection modes in custom filters (dropdown boxes)
|
26
|
+
Wice::Defaults::ALLOW_MULTIPLE_SELECTION = true
|
27
|
+
|
28
|
+
# Show the upper pagination panel by default or not
|
29
|
+
Wice::Defaults::SHOW_UPPER_PAGINATION_PANEL = false
|
30
|
+
|
31
|
+
# Disabling CSV export by default
|
32
|
+
Wice::Defaults::ENABLE_EXPORT_TO_CSV = false
|
33
|
+
|
34
|
+
# Default CSV field separator
|
35
|
+
Wice::Defaults::CSV_FIELD_SEPARATOR = ','
|
36
|
+
|
37
|
+
# Default CSV encoding (p.e. 'CP1252:UTF-8' to make Microsoft Excel(tm) happy)
|
38
|
+
Wice::Defaults::CSV_ENCODING = nil
|
39
|
+
|
40
|
+
# The strategy when to show the filter.
|
41
|
+
# * <tt>:when_filtered</tt> - when the table is the result of filtering
|
42
|
+
# * <tt>:always</tt> - show the filter always
|
43
|
+
# * <tt>:no</tt> - never show the filter
|
44
|
+
Wice::Defaults::SHOW_FILTER = :always
|
45
|
+
|
46
|
+
# A boolean value specifying if a change in a filter triggers reloading of the grid.
|
47
|
+
Wice::Defaults::AUTO_RELOAD = false
|
48
|
+
|
49
|
+
# SQL operator used for matching strings in string filters.
|
50
|
+
Wice::Defaults::STRING_MATCHING_OPERATOR = 'LIKE'
|
51
|
+
# STRING_MATCHING_OPERATOR = 'ILIKE' # Use this for Postgresql case-insensitive matching.
|
52
|
+
|
53
|
+
# Defining one string matching operator globally for the whole application turns is not enough
|
54
|
+
# when you connect to two databases one of which is MySQL and the other is Postgresql.
|
55
|
+
# If the key for an adapter is missing it will fall back to Wice::Defaults::STRING_MATCHING_OPERATOR.
|
56
|
+
#
|
57
|
+
# 'CI_LIKE' is a special value. Setting a value in STRING_MATCHING_OPERATORS to CI_LIKE will result in the following SQL:
|
58
|
+
#
|
59
|
+
# UPPER(table.field) LIKE UPPER(?)"
|
60
|
+
Wice::Defaults::STRING_MATCHING_OPERATORS = {
|
61
|
+
'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE',
|
62
|
+
'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'ILIKE'
|
63
|
+
}
|
64
|
+
|
65
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
66
|
+
# Advanced Filters #
|
67
|
+
|
68
|
+
# Switch of the negation checkbox in all text filters
|
69
|
+
Wice::Defaults::NEGATION_IN_STRING_FILTERS = false
|
70
|
+
|
71
|
+
# Each WiceGrid filter column is defined in two classes, one used for rendering the filter, the other
|
72
|
+
# for generating query conditions. All these columns are in lib/wice/columns/*.rb .
|
73
|
+
# File lib/wice/columns/column_processor_index.rb lists all predefined processors.
|
74
|
+
# In most cases a processor is chosen automatically based on the DB column type,
|
75
|
+
# for example, integer columns
|
76
|
+
# can have two of processors, the default one with one input field, and a processor called "range",
|
77
|
+
# with 2 input fields. In this case it is possible to specify a processor in the column definition:
|
78
|
+
#
|
79
|
+
# g.column filter_type: :range
|
80
|
+
#
|
81
|
+
# It is also possible to define you own processors:
|
82
|
+
#
|
83
|
+
# Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS = {
|
84
|
+
# some_key_identifying_new_column_type: ['AViewColumnProcessorClass', 'ConditionsGeneratorClass'],
|
85
|
+
# another_key_identifying_new_column_type: ['AnotherViewColumnProcessorClass', 'AnotherConditionsGeneratorClass']
|
86
|
+
# }
|
87
|
+
#
|
88
|
+
# Column processor keys/names should not coincide with the existing keys/names (see lib/wice/columns/column_processor_index.rb)
|
89
|
+
# the value is a 2-element array with 2 strings, the first should be a name of view processor class inherited from
|
90
|
+
# Wice::Columns::ViewColumn, the second should be a name of conditions generator class inherited from
|
91
|
+
# Wice::Columns::ConditionsGeneratorColumn .
|
92
|
+
|
93
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
94
|
+
# Showing All Records #
|
95
|
+
|
96
|
+
# Enable or disable showing all records (non-paginated table)
|
97
|
+
Wice::Defaults::ALLOW_SHOWING_ALL_RECORDS = true
|
98
|
+
|
99
|
+
# If number of all queries is more than this value, the user will be given a warning message
|
100
|
+
Wice::Defaults::START_SHOWING_WARNING_FROM = 100
|
101
|
+
|
102
|
+
# Hide the "show all" link if the number of all records is more than...
|
103
|
+
# Force-resets back to pagination starting from this value.
|
104
|
+
# Set to nil to always show it
|
105
|
+
Wice::Defaults::SHOW_ALL_ALLOWED_UP_TO = nil
|
106
|
+
|
107
|
+
#
|
108
|
+
# set to nil to skip the check
|
109
|
+
Wice::Defaults::SWITCH_BACK_TO_PAGINATION_FROM = nil
|
110
|
+
|
111
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
112
|
+
# Saving Queries #
|
113
|
+
|
114
|
+
# ActiveRecord model to store queries. Read the documentation for details
|
115
|
+
# QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
|
116
|
+
Wice::Defaults::QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
|
117
|
+
|
118
|
+
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
119
|
+
# Here go settings related to the date/datetime filters #
|
120
|
+
|
121
|
+
# Default column filters
|
122
|
+
# Possible values:
|
123
|
+
# * <tt>:jquery_datepicker</tt> - Jquery datepicker (works for datetime, too)
|
124
|
+
# * <tt>:bootstrap_datepicker</tt> - Bootstrap datepicker (works for datetime, too)
|
125
|
+
# * <tt>:rails_date_helper</tt> - standard Rails date helper
|
126
|
+
# * <tt>:rails_datetime_helper</tt> - standard Rails datetime helper
|
127
|
+
|
128
|
+
Wice::Defaults::DEFAULT_FILTER_FOR_DATE = :jquery_datepicker
|
129
|
+
Wice::Defaults::DEFAULT_FILTER_FOR_DATETIME = :jquery_datepicker
|
130
|
+
|
131
|
+
# Format of the datetime displayed.
|
132
|
+
# If you change the format, make sure to check if +DATETIME_PARSER+ can still parse this string.
|
133
|
+
Wice::Defaults::DATETIME_FORMAT = '%Y-%m-%d %H:%M'
|
134
|
+
|
135
|
+
# Format of the date displayed.
|
136
|
+
# If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
|
137
|
+
Wice::Defaults::DATE_FORMAT = '%Y-%m-%d'
|
138
|
+
|
139
|
+
# Format of the date displayed in jQuery's Datepicker
|
140
|
+
# If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
|
141
|
+
Wice::Defaults::DATE_FORMAT_JQUERY = 'yy-mm-dd'
|
142
|
+
|
143
|
+
# Format of the date displayed in Bootstrap's Datepicker
|
144
|
+
# If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
|
145
|
+
Wice::Defaults::DATE_FORMAT_BOOTSTRAP = 'yyyy-mm-dd'
|
146
|
+
|
147
|
+
# With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
|
148
|
+
# format defined by +DATETIME_FORMAT+ and must generate a DateTime object.
|
149
|
+
# In many cases <tt>Time.zone.parse</tt> is enough, for instance, <tt>%Y-%m-%d</tt>. If you change the format, make sure to check this code
|
150
|
+
# and modify it if needed.
|
151
|
+
Wice::Defaults::DATETIME_PARSER = lambda do|datetime_string|
|
152
|
+
if datetime_string.blank?
|
153
|
+
nil
|
154
|
+
elsif Time.zone
|
155
|
+
Time.zone.parse(datetime_string)
|
156
|
+
else
|
157
|
+
Time.parse(datetime_string)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# The range of years to display in jQuery Datepicker.
|
162
|
+
# It can always be changed dynamically with the following javascript:
|
163
|
+
# $( ".hasDatepicker" ).datepicker( "option", "yearRange", "2000:2042" );
|
164
|
+
Wice::Defaults::DATEPICKER_YEAR_RANGE = (from = Date.current.year - 10).to_s + ':' + (from + 15).to_s
|
165
|
+
|
166
|
+
# With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
|
167
|
+
# format defined by +DATETIME+ and must generate a Date object.
|
168
|
+
# In many cases <tt>Date.parse</tt> is enough, for instance, <tt>%Y-%m-%d</tt>. If you change the format, make sure to check this code
|
169
|
+
# and modify it if needed.
|
170
|
+
Wice::Defaults::DATE_PARSER = lambda do|date_string|
|
171
|
+
if date_string.blank?
|
172
|
+
nil
|
173
|
+
else
|
174
|
+
begin
|
175
|
+
Date.parse(date_string)
|
176
|
+
rescue ArgumentError
|
177
|
+
nil
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
# The name of the page method (should correspond to Kaminari.config.page_method_name)
|
183
|
+
Wice::Defaults::PAGE_METHOD_NAME = :page
|
184
|
+
|
185
|
+
# The name of the theme to use for the pagination with Kaminari
|
186
|
+
Wice::Defaults::PAGINATION_THEME = :wice_grid
|
187
|
+
|
188
|
+
# By default ActiveRecord calls are always executed inside Model.unscoped{}.
|
189
|
+
# Setting <tt>USE_DEFAULT_SCOPE</tt> to true will use the default scope for all queries.
|
190
|
+
Wice::Defaults::USE_DEFAULT_SCOPE = false
|
191
|
+
|
192
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Wice
|
3
|
+
# to be mixed in into ActiveRecord::ConnectionAdapters::Column
|
4
|
+
module WiceGridExtentionToActiveRecordColumn #:nodoc:
|
5
|
+
# reference to the ActiveRecord model class
|
6
|
+
attr_accessor :model
|
7
|
+
end
|
8
|
+
|
9
|
+
class ActiveRecordColumnWrapper #:nodoc:
|
10
|
+
def initialize(column, all_filter_params, main_table, table_alias, custom_filter_active, filter_type) #:nodoc:
|
11
|
+
@column = column
|
12
|
+
|
13
|
+
# nil | Symbol
|
14
|
+
@filter_type = filter_type
|
15
|
+
|
16
|
+
# Hash { String => String | Array[String]}
|
17
|
+
@all_filter_params = all_filter_params
|
18
|
+
|
19
|
+
# nil | Boolean
|
20
|
+
@main_table = main_table
|
21
|
+
|
22
|
+
# nil | String
|
23
|
+
@table_alias = table_alias
|
24
|
+
|
25
|
+
# nil | Array[String] | Array[Array[...]] | Array[Symbol]
|
26
|
+
@custom_filter_active = custom_filter_active
|
27
|
+
end
|
28
|
+
|
29
|
+
def wg_initialize_request_parameters #:nodoc:
|
30
|
+
@request_params = nil
|
31
|
+
return if @all_filter_params.nil?
|
32
|
+
|
33
|
+
# if the parameter does not specify the table name we only allow columns in the default table to use these parameters
|
34
|
+
if @main_table && @request_params = @all_filter_params[@column.name]
|
35
|
+
current_parameter_name = @column.name
|
36
|
+
elsif @request_params = @all_filter_params[alias_or_table_name(@table_alias) + '.' + @column.name]
|
37
|
+
current_parameter_name = alias_or_table_name(@table_alias) + '.' + @column.name
|
38
|
+
end
|
39
|
+
|
40
|
+
# Preprocess incoming parameters for datetime, if what's coming in is
|
41
|
+
# a datetime (with custom_filter it can be anything else, and not
|
42
|
+
# the datetime hash {fr: ..., to: ...})
|
43
|
+
if @request_params
|
44
|
+
|
45
|
+
if (@column.type == :datetime || @column.type == :timestamp) && @request_params.is_a?(Hash)
|
46
|
+
[:fr, :to].each do |sym|
|
47
|
+
if @request_params[sym]
|
48
|
+
if @request_params[sym].is_a?(String)
|
49
|
+
@request_params[sym] = Wice::ConfigurationProvider.value_for(:DATETIME_PARSER).call(@request_params[sym])
|
50
|
+
elsif @request_params[sym].is_a?(Hash)
|
51
|
+
@request_params[sym] = Wice::GridTools.params_2_datetime(@request_params[sym])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# Preprocess incoming parameters for date, if what's coming in is
|
59
|
+
# a date (with custom_filter it can be anything else, and not
|
60
|
+
# the date hash {fr: ..., to: ...})
|
61
|
+
if @column.type == :date && @request_params.is_a?(Hash)
|
62
|
+
|
63
|
+
[:fr, :to].each do |sym|
|
64
|
+
if @request_params[sym]
|
65
|
+
if @request_params[sym].is_a?(String)
|
66
|
+
@request_params[sym] = Wice::ConfigurationProvider.value_for(:DATE_PARSER).call(@request_params[sym])
|
67
|
+
elsif @request_params[sym].is_a?(Hash)
|
68
|
+
@request_params[sym] = ::Wice::GridTools.params_2_date(@request_params[sym])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
[wg_generate_conditions, current_parameter_name]
|
77
|
+
end
|
78
|
+
|
79
|
+
def wg_generate_conditions #:nodoc:
|
80
|
+
return nil if @request_params.nil?
|
81
|
+
|
82
|
+
if @custom_filter_active
|
83
|
+
custom_processor_klass = ::Wice::Columns.get_conditions_generator_column_processor(:custom)
|
84
|
+
custom_processor = custom_processor_klass.new(self)
|
85
|
+
return custom_processor.generate_conditions(@table_alias, @request_params)
|
86
|
+
end
|
87
|
+
|
88
|
+
column_type = @filter_type || @column.type.to_s.intern
|
89
|
+
|
90
|
+
filter_type = case column_type
|
91
|
+
when :date
|
92
|
+
ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATE)
|
93
|
+
when :datetime
|
94
|
+
ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME)
|
95
|
+
when :timestamp
|
96
|
+
ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME)
|
97
|
+
else
|
98
|
+
column_type
|
99
|
+
end
|
100
|
+
|
101
|
+
processor_class = ::Wice::Columns.get_conditions_generator_column_processor(filter_type)
|
102
|
+
|
103
|
+
if processor_class
|
104
|
+
return processor_class.new(self, column_type).generate_conditions(@table_alias, @request_params)
|
105
|
+
else
|
106
|
+
Wice.log("No processor for database type #{column_type}!!!")
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def name #:nodoc:
|
112
|
+
@column.name
|
113
|
+
end
|
114
|
+
|
115
|
+
def model #:nodoc:
|
116
|
+
@column.model
|
117
|
+
end
|
118
|
+
|
119
|
+
def alias_or_table_name(table_alias) #:nodoc:
|
120
|
+
table_alias || @column.model.table_name
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/lib/wice/columns.rb
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Wice #:nodoc:
|
3
|
+
module Columns #:nodoc:
|
4
|
+
mattr_reader :handled_type_view, :handled_type_conditions_generator
|
5
|
+
|
6
|
+
class << self #:nodoc:
|
7
|
+
def load_column_processors #:nodoc:
|
8
|
+
require_columns
|
9
|
+
|
10
|
+
@@handled_type_view = build_table_of_processors 'view'
|
11
|
+
@@handled_type_conditions_generator = build_table_of_processors 'conditions_generator'
|
12
|
+
|
13
|
+
if Wice::Defaults.const_defined?(:ADDITIONAL_COLUMN_PROCESSORS)
|
14
|
+
|
15
|
+
common_error_prefix = 'Error loading Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS. '
|
16
|
+
|
17
|
+
Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS.each do |key, value|
|
18
|
+
unless key.is_a?(Symbol)
|
19
|
+
fail common_error_prefix + 'A key of Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS should be a Symbol!'
|
20
|
+
end
|
21
|
+
|
22
|
+
if @@handled_type_view.key?(key)
|
23
|
+
fail common_error_prefix +
|
24
|
+
"Column with key \"#{key}\" already exists in WiceGrid, overwriting existing columns is forbidden, please choose another key!"
|
25
|
+
end
|
26
|
+
|
27
|
+
if !value.is_a?(Array) || value.size != 2
|
28
|
+
fail common_error_prefix +
|
29
|
+
'A value of Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS should be a a 2-element array!'
|
30
|
+
end
|
31
|
+
|
32
|
+
view_processor, conditions_generator = value.map(&:to_s).map do |klass|
|
33
|
+
begin
|
34
|
+
eval(klass)
|
35
|
+
rescue NameError
|
36
|
+
raise common_error_prefix + "Class #{klass} is not defined!"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
unless view_processor.ancestors.include?(::Wice::Columns::ViewColumn)
|
41
|
+
fail common_error_prefix +
|
42
|
+
"#{view_processor} should be inherited from Wice::Columns::ViewColumn!"
|
43
|
+
end
|
44
|
+
|
45
|
+
unless conditions_generator.ancestors.include?(::Wice::Columns::ConditionsGeneratorColumn)
|
46
|
+
fail common_error_prefix +
|
47
|
+
"#{conditions_generator} should be inherited from Wice::Columns::ConditionsGeneratorColumn!"
|
48
|
+
end
|
49
|
+
|
50
|
+
@@handled_type_view[key] = view_processor
|
51
|
+
@@handled_type_conditions_generator[key] = conditions_generator
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_view_column_processor(column_type) #:nodoc:
|
57
|
+
@@handled_type_view[column_type] || ViewColumn
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_conditions_generator_column_processor(column_type) #:nodoc:
|
61
|
+
column_type = column_type.intern if column_type.is_a? String
|
62
|
+
@@handled_type_conditions_generator[column_type] || fail("Could not find conditions generator processor for column_type #{column_type}")
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def build_table_of_processors(prefix)
|
68
|
+
{}.tap do |processor_table|
|
69
|
+
loaded_processors = {}
|
70
|
+
|
71
|
+
Wice::Columns::COLUMN_PROCESSOR_INDEX.each do |column_type, column_source_file|
|
72
|
+
unless loaded_processors[column_source_file]
|
73
|
+
processor_class_name = "#{prefix}_#{column_source_file}".classify
|
74
|
+
|
75
|
+
unless Wice::Columns.const_defined?(processor_class_name.intern)
|
76
|
+
fail "#{column_source_file}.rb is expected to define #{processor_class_name}!"
|
77
|
+
end
|
78
|
+
processor_class = eval("Wice::Columns::#{processor_class_name}")
|
79
|
+
|
80
|
+
loaded_processors[column_source_file] = processor_class
|
81
|
+
end
|
82
|
+
|
83
|
+
processor_table[column_type] = loaded_processors[column_source_file]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def require_columns
|
89
|
+
Wice::Columns::COLUMN_PROCESSOR_INDEX.values.uniq do |column_source_file|
|
90
|
+
require "wice/columns/#{column_source_file}.rb"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class ViewColumn #:nodoc:
|
96
|
+
include ActionView::Helpers::FormTagHelper
|
97
|
+
include ActionView::Helpers::TagHelper
|
98
|
+
include ActionView::Helpers::JavaScriptHelper
|
99
|
+
include ActionView::Helpers::AssetTagHelper
|
100
|
+
|
101
|
+
# fields defined from the options parameter
|
102
|
+
FIELDS = [:attribute, :name, :html, :filter, :model, :allow_multiple_selection,
|
103
|
+
:in_html, :in_csv, :table_alias, :custom_order, :detach_with_id, :ordering, :auto_reload]
|
104
|
+
|
105
|
+
attr_accessor(*FIELDS)
|
106
|
+
|
107
|
+
# a Proc object which would return contents of one cell
|
108
|
+
attr_accessor :cell_rendering_block
|
109
|
+
|
110
|
+
# reference to the WiceGrid instance
|
111
|
+
attr_accessor :grid
|
112
|
+
|
113
|
+
# name of the table
|
114
|
+
attr_accessor :table_name
|
115
|
+
|
116
|
+
# name of the main table (first argument to initialize_grid)
|
117
|
+
attr_accessor :main_table
|
118
|
+
|
119
|
+
# attr_accessor :model
|
120
|
+
|
121
|
+
# specification for a custom filter: an array of option label + option value pairs for the select, or a Proc object which returns this array.
|
122
|
+
# Or nil if it is not a custom filter
|
123
|
+
attr_accessor :custom_filter
|
124
|
+
|
125
|
+
# A boolean flag: whether a column has a text input or not
|
126
|
+
attr_reader :contains_a_text_input
|
127
|
+
|
128
|
+
def initialize(block, options, grid_obj, tname, mtable, cfilter, view) #:nodoc:
|
129
|
+
self.cell_rendering_block = block
|
130
|
+
self.grid = grid_obj
|
131
|
+
self.table_name = tname
|
132
|
+
self.main_table = mtable
|
133
|
+
self.custom_filter = cfilter
|
134
|
+
@view = view
|
135
|
+
|
136
|
+
FIELDS.each do |field|
|
137
|
+
self.send(field.to_s + '=', options[field])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def add_css_class(klass_value) #:nodoc:
|
142
|
+
self.html ||= {}
|
143
|
+
if html[:class].nil?
|
144
|
+
html[:class] = klass_value
|
145
|
+
else
|
146
|
+
html[:class] << ' ' unless html[:class].empty?
|
147
|
+
html[:class] << klass_value
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def css_class #:nodoc:
|
152
|
+
if html && html[:class]
|
153
|
+
html[:class]
|
154
|
+
else
|
155
|
+
''
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def yield_declaration_of_column_filter #:nodoc:
|
160
|
+
nil
|
161
|
+
end
|
162
|
+
|
163
|
+
def detachness #:nodoc:
|
164
|
+
(!detach_with_id.blank?).to_s
|
165
|
+
end
|
166
|
+
|
167
|
+
def yield_declaration #:nodoc:
|
168
|
+
declaration = yield_declaration_of_column_filter
|
169
|
+
if declaration
|
170
|
+
{
|
171
|
+
filterName: self.name,
|
172
|
+
detached: detachness,
|
173
|
+
declaration: declaration
|
174
|
+
}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def config #:nodoc:
|
179
|
+
@view.config
|
180
|
+
end
|
181
|
+
|
182
|
+
def controller #:nodoc:
|
183
|
+
@view.controller
|
184
|
+
end
|
185
|
+
|
186
|
+
def render_filter #:nodoc:
|
187
|
+
params = @grid.filter_params(self)
|
188
|
+
render_filter_internal(params)
|
189
|
+
end
|
190
|
+
|
191
|
+
def render_filter_internal(_params) #:nodoc:
|
192
|
+
'<!-- implement me! -->'
|
193
|
+
end
|
194
|
+
|
195
|
+
def form_parameter_name_id_and_query(v) #:nodoc:
|
196
|
+
query = form_parameter_template(v)
|
197
|
+
query_without_equals_sign = query.sub(/=$/, '')
|
198
|
+
parameter_name = CGI.unescape(query_without_equals_sign)
|
199
|
+
dom_id = id_out_of_name(parameter_name)
|
200
|
+
[query, query_without_equals_sign, parameter_name, dom_id.tr('.', '_')]
|
201
|
+
end
|
202
|
+
|
203
|
+
# bad name, because for the main table the name is not really 'fully_qualified'
|
204
|
+
def attribute_name_fully_qualified_for_all_but_main_table_columns #:nodoc:
|
205
|
+
self.main_table ? attribute : table_alias_or_table_name + '.' + attribute
|
206
|
+
end
|
207
|
+
|
208
|
+
def fully_qualified_attribute_name #:nodoc:
|
209
|
+
table_alias_or_table_name + '.' + attribute
|
210
|
+
end
|
211
|
+
|
212
|
+
def filter_shown? #:nodoc:
|
213
|
+
self.attribute && self.filter
|
214
|
+
end
|
215
|
+
|
216
|
+
def filter_shown_in_main_table? #:nodoc:
|
217
|
+
filter_shown? && !self.detach_with_id
|
218
|
+
end
|
219
|
+
|
220
|
+
def table_alias_or_table_name #:nodoc:
|
221
|
+
table_alias || table_name
|
222
|
+
end
|
223
|
+
|
224
|
+
def capable_of_hosting_filter_related_icons? #:nodoc:
|
225
|
+
self.attribute.blank? && self.name.blank? && !self.filter_shown?
|
226
|
+
end
|
227
|
+
|
228
|
+
def has_auto_reloading_input? #:nodoc:
|
229
|
+
false
|
230
|
+
end
|
231
|
+
|
232
|
+
def auto_reloading_input_with_negation_checkbox? #:nodoc:
|
233
|
+
false
|
234
|
+
end
|
235
|
+
|
236
|
+
def has_auto_reloading_select? #:nodoc:
|
237
|
+
false
|
238
|
+
end
|
239
|
+
|
240
|
+
def has_auto_reloading_calendar? #:nodoc:
|
241
|
+
false
|
242
|
+
end
|
243
|
+
|
244
|
+
protected
|
245
|
+
|
246
|
+
def form_parameter_template(v) #:nodoc:
|
247
|
+
{ @grid.name => { f: { self.attribute_name_fully_qualified_for_all_but_main_table_columns => v } } }.to_query
|
248
|
+
end
|
249
|
+
|
250
|
+
def form_parameter_name(v) #:nodoc:
|
251
|
+
form_parameter_template_hash(v).to_query
|
252
|
+
end
|
253
|
+
|
254
|
+
def name_out_of_template(s) #:nodoc:
|
255
|
+
CGI.unescape(s).sub(/=$/, '')
|
256
|
+
end
|
257
|
+
|
258
|
+
def id_out_of_name(s) #:nodoc:
|
259
|
+
s.gsub(/[\[\]]+/, '_').sub(/_+$/, '')
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
class ConditionsGeneratorColumn #:nodoc:
|
264
|
+
def initialize(column_wrapper, column_type = nil) #:nodoc:
|
265
|
+
# Wice::ActiveRecordColumnWrapper
|
266
|
+
@column_wrapper = column_wrapper
|
267
|
+
@column_type = column_type
|
268
|
+
end
|
269
|
+
|
270
|
+
def generate_conditions(_table_alias, _opts) #:nodoc:
|
271
|
+
fail('implement me')
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|