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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.inch.yml +3 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +181 -0
  5. data/.travis.yml +22 -0
  6. data/{CHANGELOG → CHANGELOG.md} +95 -31
  7. data/Gemfile +4 -1
  8. data/README.md +1517 -0
  9. data/Rakefile +51 -7
  10. data/{SAVED_QUERIES_HOWTO.rdoc → SAVED_QUERIES_HOWTO.md} +34 -31
  11. data/TODO.md +16 -0
  12. data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +4 -6
  13. data/lib/generators/wice_grid/install_generator.rb +2 -5
  14. data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +1 -0
  15. data/lib/generators/wice_grid/templates/wice_grid_config.rb +29 -34
  16. data/lib/wice/active_record_column_wrapper.rb +36 -17
  17. data/lib/wice/columns.rb +53 -52
  18. data/lib/wice/columns/column_action.rb +11 -13
  19. data/lib/wice/columns/column_boolean.rb +9 -11
  20. data/lib/wice/columns/column_bootstrap_datepicker.rb +48 -0
  21. data/lib/wice/columns/column_custom_dropdown.rb +22 -23
  22. data/lib/wice/columns/column_float.rb +2 -6
  23. data/lib/wice/columns/column_html5_datepicker.rb +31 -0
  24. data/lib/wice/columns/column_integer.rb +9 -13
  25. data/lib/wice/columns/column_jquery_datepicker.rb +49 -0
  26. data/lib/wice/columns/column_processor_index.rb +18 -13
  27. data/lib/wice/columns/column_rails_date_helper.rb +41 -0
  28. data/lib/wice/columns/column_rails_datetime_helper.rb +40 -0
  29. data/lib/wice/columns/column_range.rb +7 -11
  30. data/lib/wice/columns/column_string.rb +24 -20
  31. data/lib/wice/columns/common_date_datetime_mixin.rb +20 -0
  32. data/lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb +39 -0
  33. data/lib/wice/columns/common_js_date_datetime_mixin.rb +15 -0
  34. data/lib/wice/columns/{column_date.rb → common_rails_date_datetime_conditions_generator_mixin.rb} +4 -22
  35. data/lib/wice/columns/common_standard_helper_date_datetime_mixin.rb +22 -0
  36. data/lib/wice/grid_output_buffer.rb +19 -10
  37. data/lib/wice/grid_renderer.rb +146 -85
  38. data/lib/wice/helpers/bs_calendar_helpers.rb +6 -7
  39. data/lib/wice/helpers/js_calendar_helpers.rb +19 -17
  40. data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +18 -18
  41. data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +44 -49
  42. data/lib/wice/helpers/wice_grid_view_helpers.rb +131 -134
  43. data/lib/wice/kaminari_monkey_patching.rb +3 -1
  44. data/lib/wice/table_column_matrix.rb +23 -8
  45. data/lib/wice/wice_grid_controller.rb +12 -16
  46. data/lib/wice/wice_grid_core_ext.rb +12 -20
  47. data/lib/wice/wice_grid_misc.rb +131 -53
  48. data/lib/wice/wice_grid_serialized_queries_controller.rb +10 -11
  49. data/lib/wice/wice_grid_serialized_query.rb +4 -3
  50. data/lib/wice/wice_grid_spreadsheet.rb +19 -18
  51. data/lib/wice_grid.rb +144 -135
  52. data/spec/schema.rb +9 -0
  53. data/spec/spec_helper.rb +75 -0
  54. data/spec/support/active_record.rb +11 -0
  55. data/spec/support/wice_grid_test_config.rb +172 -0
  56. data/spec/wice/grid_output_buffer_spec.rb +41 -0
  57. data/spec/wice/table_column_matrix_spec.rb +38 -0
  58. data/spec/wice/wice_grid_misc_spec.rb +159 -0
  59. data/spec/wice/wice_grid_spreadsheet_spec.rb +14 -0
  60. data/test/readme.txt +1 -1
  61. data/vendor/assets/javascripts/wice_grid_init.js.coffee +14 -8
  62. data/vendor/assets/stylesheets/wice_grid.scss +84 -0
  63. data/wice_grid.gemspec +32 -16
  64. metadata +217 -25
  65. data/README.rdoc +0 -1325
  66. data/lib/generators/wice_grid/templates/wice_grid.scss +0 -140
  67. data/lib/wice/columns/column_datetime.rb +0 -171
  68. data/vendor/assets/images/icons/grid/arrow_down.gif +0 -0
  69. data/vendor/assets/images/icons/grid/arrow_up.gif +0 -0
  70. data/vendor/assets/images/icons/grid/calendar_view_month.png +0 -0
  71. data/vendor/assets/images/icons/grid/collapse.gif +0 -0
  72. data/vendor/assets/images/icons/grid/delete.png +0 -0
  73. data/vendor/assets/images/icons/grid/expand.gif +0 -0
  74. data/vendor/assets/images/icons/grid/page_white_excel.png +0 -0
  75. data/vendor/assets/images/icons/grid/page_white_find.png +0 -0
  76. data/vendor/assets/images/icons/grid/table.png +0 -0
  77. data/vendor/assets/images/icons/grid/table_refresh.png +0 -0
  78. data/vendor/assets/images/icons/grid/tick_all.png +0 -0
  79. data/vendor/assets/images/icons/grid/untick_all.png +0 -0
data/Rakefile CHANGED
@@ -1,15 +1,59 @@
1
- require "bundler/gem_tasks"
2
- require 'rdoc/task'
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ require 'bundler/gem_tasks'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts 'Run `bundle install` to install missing gems'
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'rspec/core'
16
+ require 'rspec/core/rake_task'
17
+
18
+ RSpec::Core::RakeTask.new(:spec)
19
+
20
+ require 'rubocop/rake_task'
21
+
22
+ desc 'Run RuboCop on the lib directory'
23
+ RuboCop::RakeTask.new(:rubocop) do |task|
24
+ task.patterns = ['lib/**/*.rb']
25
+ # don't abort rake on failure
26
+ task.fail_on_error = false
27
+ end
28
+
29
+ desc 'Run RSpec with code coverage'
30
+ task :coverage do
31
+ ENV['COVERAGE'] = 'true'
32
+ Rake::Task['spec'].execute
33
+ end
3
34
 
4
- task default: :rdoc
35
+ # Experimenting with documentation system we will keep both Yardoc and Rdoc for some time, plus Inch
5
36
 
6
- desc 'Generate documentation for the wice_grid plugin.'
37
+ require 'yard'
38
+ require 'yard/rake/yardoc_task'
39
+ desc 'Generate YARDOC documentation for the plugin'
40
+ YARD::Rake::YardocTask.new(:yardoc) do |t|
41
+ OTHER_PATHS = %w()
42
+ t.files = ['lib/**/*.rb', OTHER_PATHS]
43
+ t.options = %w(--main=README.md --file TODO.md,CHANGELOG.md,SAVED_QUERIES_HOWTO.md,MIT-LICENSE)
44
+ t.stats_options = ['--list-undoc']
45
+ end
46
+
47
+ gem 'rdoc'
48
+ require 'rdoc/task'
7
49
  Rake::RDocTask.new(:rdoc) do |rdoc|
8
50
  rdoc.rdoc_dir = 'rdoc'
9
51
  rdoc.title = 'WiceGrid'
10
52
  rdoc.options << '--line-numbers' << '--inline-source'
11
- rdoc.rdoc_files.include('README.rdoc')
12
- rdoc.rdoc_files.include('SAVED_QUERIES_HOWTO.rdoc')
13
- rdoc.rdoc_files.include('CHANGELOG')
53
+ rdoc.rdoc_files.include('README.md')
54
+ rdoc.rdoc_files.include('SAVED_QUERIES_HOWTO.md')
55
+ rdoc.rdoc_files.include('CHANGELOG.md')
14
56
  rdoc.rdoc_files.include('lib/**/*.rb')
15
57
  end
58
+
59
+ task default: [:rubocop, :spec, :yardoc]
@@ -1,63 +1,63 @@
1
- == Saving Queries How-To
1
+ ## Saving Queries How-To
2
2
 
3
3
  WiceGrid allows to save the state of filters as a custom query and later restore it from the list of saved queries.
4
4
 
5
- === Step 1: Create the database table to store queries
5
+ ### Step 1: Create the database table to store queries
6
6
 
7
7
  To get started create the database table to store queries. Run the following generator:
8
-
9
- rails g wice_grid:add_migration_for_serialized_queries
10
-
8
+ ```
9
+ rails g wice_grid:add_migration_for_serialized_queries
10
+ ```
11
11
  This add a migration file with the definition of the table. Run the migrate task:
12
-
12
+ ```
13
13
  bundle 'rake db:migrate'
14
-
15
- === Step 2: Create the controller to handle AJAX queries.
14
+ ```
15
+ ### Step 2: Create the controller to handle AJAX queries.
16
16
 
17
17
  Creation and deletion of queries is implemented as AJAX calls, and a controller is needed to handle these calls. Create an empty controller
18
18
  with any name and add method +save_wice_grid_queries+ to it:
19
-
19
+ ```
20
20
  class QueriesController < ApplicationController
21
21
  save_wice_grid_queries
22
22
  end
23
-
23
+ ```
24
24
  This is it. The controller now has the required action methods.
25
25
 
26
- === Step 3: Add routes
27
-
28
- If the name of the query controller is QueriesController, add the following to <tt>routes.rb</tt>:
26
+ ### Step 3: Add routes
29
27
 
28
+ If the name of the query controller is QueriesController, add the following to `routes.rb`:
29
+ ```
30
30
  Wice::define_routes(self, 'queries')
31
-
32
- === Step 4: Add the saved query panel to the view.
31
+ ```
32
+ ### Step 4: Add the saved query panel to the view.
33
33
 
34
34
  To show the list of saved queries and the form to create new queries in a view, add the following helper to the view:
35
-
35
+ ```
36
36
  <%= saved_queries_panel(@grid_object) %>
37
-
37
+ ```
38
38
  Voila!
39
39
 
40
40
  Just like WiceGrid itself, the query panel contains no forms and is thus form-friendly.
41
41
 
42
42
  *Important*: Saved queries of all grids in the application are stored in one table and differentiated by the name of the grid, thus, for all forms
43
- with saved queries it is important to define different names! (use parameter <tt>:name</tt> in +initialize_grid+)
43
+ with saved queries it is important to define different names! (use parameter `:name` in +initialize_grid+)
44
44
 
45
45
  It is also possible to initialize a grid with an initial saved query providing the id of the query record or the ActiveRecord
46
- itself to parameter <tt>saved_query</tt>:
47
-
46
+ itself to parameter `saved_query`:
47
+ ```
48
48
  @products_grid = initialize_grid(Product,
49
49
  name: 'prod_grid',
50
50
  saved_query: SavedQuery.find_by_id_and_grid_name(12, 'prod_grid') )
51
+ ```
51
52
 
52
-
53
- == Adding Application Specific Logic to Saving/Restoring Queries
53
+ ## Adding Application Specific Logic to Saving/Restoring Queries
54
54
 
55
55
  WiceGrid allows to add application specific logic to saving and restoring queries by substituting the default ActiveRecord model provided by WiceGrid with a custom model.
56
56
 
57
- Copy <tt>lib/wice_grid_serialized_query.rb</tt> from the gem to <tt>app/models/</tt>, rename the file and the class to your liking.
57
+ Copy `lib/wice_grid_serialized_query.rb` from the gem to `app/models/`, rename the file and the class to your liking.
58
58
 
59
59
  After renaming the model to SavedQuery it looks like this:
60
-
60
+ ```
61
61
  class SavedQuery < ActiveRecord::Base #:nodoc:
62
62
  serialize :query
63
63
 
@@ -71,11 +71,12 @@ After renaming the model to SavedQuery it looks like this:
71
71
  self.find(:all, conditions: conditions)
72
72
  end
73
73
  end
74
+ ```
74
75
 
75
76
  It is required that the model provides class method +list+ which accepts two parameters: the name of the WiceGrid instance and the controller
76
77
  object, and returns a list of queries. The controller object is needed to provide the application context. For instance, if it is needed to
77
78
  store queries for each user, we could add +user_id+ to the table and modify the code so it looks like the following:
78
-
79
+ ```
79
80
  class SavedQuery < ActiveRecord::Base
80
81
  serialize :query
81
82
 
@@ -94,17 +95,19 @@ store queries for each user, we could add +user_id+ to the table and modify the
94
95
  self.find(:all, conditions: conditions)
95
96
  end
96
97
  end
98
+ ```
97
99
 
98
100
  The following step is to make sure that a new query is saved with the correct +user_id+. To do so, change the helper
99
- <tt>saved_queries_panel(@grid_object)</tt> to the following:
100
-
101
+ `saved_queries_panel(@grid_object)` to the following:
101
102
 
103
+ ```
102
104
  <%= saved_queries_panel(@identities_grid, extra_parameters: {user_id: @current_user.id}) %>
103
-
105
+ ```
104
106
  For every key in has :extra_parameters there must exist a field in the model - this hash will be used as a parameter to
105
- <tt>attributes=</tt> method of the query object.
107
+ `attributes=` method of the query object.
106
108
 
107
109
  Finally, let WiceGrid know which model to use for saving queries by changing constant +QUERY_STORE_MODEL+
108
- in <tt>lib/wice_grid_config.rb</tt> to the name of the custom model (as a string), in the above example this would look like the following:
109
-
110
+ in `lib/wice_grid_config.rb` to the name of the custom model (as a string), in the above example this would look like the following:
111
+ ```
110
112
  QUERY_STORE_MODEL = 'SavedQuery'
113
+ ```
data/TODO.md ADDED
@@ -0,0 +1,16 @@
1
+ * [done] Replace all icons by Font Awesome, remove the icons
2
+ * [done] Joined tables: Instead of
3
+ model: 'ModelClassName'
4
+ use
5
+ assoc: :comments
6
+ * [done] Use ActiveRelation merge instead of manually merging hashes and arrays
7
+ * [done] Switching between datepickers should be done via :filter_type, not via :helper_style.
8
+ Get rid of :helper_style and Wice::Defaults::HELPER_STYLE
9
+ * [done] Fix datepickers when used with Datetime columns
10
+
11
+ * Implement paging in the app, get rid of Kaminari
12
+ * better tests (https://github.com/leikind/wice_grid_testbed)
13
+ * review css class names in the generated markup
14
+ * More unified and flexible approach to datepickers
15
+ * try to guess :table_alias
16
+ * throw away saved queries?
@@ -1,22 +1,20 @@
1
+ # encoding: utf-8
1
2
  module WiceGrid #:nodoc:
2
3
  module Generators #:nodoc:
3
-
4
4
  class AddMigrationForSerializedQueriesGenerator < Rails::Generators::Base #:nodoc:
5
-
6
5
  include Rails::Generators::Migration
7
6
 
8
7
  desc 'Add a migration which creates a table for serialized queries'
9
8
 
10
9
  source_root File.expand_path('../templates', __FILE__)
11
10
 
12
- def self.next_migration_number(path)
13
- Time.now.utc.strftime("%Y%m%d%H%M%S")
11
+ def self.next_migration_number(_path)
12
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
14
13
  end
15
14
 
16
15
  def create_model_file
17
- migration_template "create_wice_grid_serialized_queries.rb", "db/migrate/create_wice_grid_serialized_queries.rb"
16
+ migration_template 'create_wice_grid_serialized_queries.rb', 'db/migrate/create_wice_grid_serialized_queries.rb'
18
17
  end
19
18
  end
20
-
21
19
  end
22
20
  end
@@ -1,8 +1,8 @@
1
+ # encoding: utf-8
1
2
  module WiceGrid #:nodoc:
2
3
  module Generators #:nodoc:
3
4
  class InstallGenerator < Rails::Generators::Base #:nodoc:
4
-
5
- desc 'Copy WiceGrid wice_grid_config.rb to config/initializers, ' +
5
+ desc 'Copy WiceGrid wice_grid_config.rb to config/initializers, ' \
6
6
  'wice_grid.yml to config/locales/, and wice_grid.scss to assets/stylesheets'
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
@@ -11,9 +11,6 @@ module WiceGrid #:nodoc:
11
11
  template 'wice_grid_config.rb', 'config/initializers/wice_grid_config.rb'
12
12
 
13
13
  copy_file 'wice_grid.yml', 'config/locales/wice_grid.yml'
14
-
15
- copy_file 'wice_grid.scss', 'app/assets/stylesheets/wice_grid.scss'
16
-
17
14
  end
18
15
  end
19
16
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  class CreateWiceGridSerializedQueries < ::ActiveRecord::Migration #:nodoc:
2
3
  def change #:nodoc:
3
4
  create_table :wice_grid_serialized_queries do |t|
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  if defined?(Wice::Defaults)
2
3
 
3
4
  # Default number of rows to show per page.
@@ -33,7 +34,6 @@ if defined?(Wice::Defaults)
33
34
  # Default CSV field separator
34
35
  Wice::Defaults::CSV_FIELD_SEPARATOR = ','
35
36
 
36
-
37
37
  # The strategy when to show the filter.
38
38
  # * <tt>:when_filtered</tt> - when the table is the result of filtering
39
39
  # * <tt>:always</tt> - show the filter always
@@ -43,29 +43,28 @@ if defined?(Wice::Defaults)
43
43
  # A boolean value specifying if a change in a filter triggers reloading of the grid.
44
44
  Wice::Defaults::AUTO_RELOAD = false
45
45
 
46
-
47
46
  # SQL operator used for matching strings in string filters.
48
47
  Wice::Defaults::STRING_MATCHING_OPERATOR = 'LIKE'
49
48
  # STRING_MATCHING_OPERATOR = 'ILIKE' # Use this for Postgresql case-insensitive matching.
50
49
 
51
-
52
50
  # Defining one string matching operator globally for the whole application turns is not enough
53
51
  # when you connect to two databases one of which is MySQL and the other is Postgresql.
54
- # If the key for an adapter is missing it will fall back to Wice::Defaults::STRING_MATCHING_OPERATOR
52
+ # If the key for an adapter is missing it will fall back to Wice::Defaults::STRING_MATCHING_OPERATOR.
53
+ #
54
+ # 'CI_LIKE' is a special value. Setting a value in STRING_MATCHING_OPERATORS to CI_LIKE will result in the following SQL:
55
+ #
56
+ # UPPER(table.field) LIKE UPPER(?)"
55
57
  Wice::Defaults::STRING_MATCHING_OPERATORS = {
56
58
  'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE',
57
59
  'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'ILIKE'
58
60
  }
59
61
 
60
-
61
-
62
62
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
63
63
  # Advanced Filters #
64
64
 
65
65
  # Switch of the negation checkbox in all text filters
66
66
  Wice::Defaults::NEGATION_IN_STRING_FILTERS = false
67
67
 
68
-
69
68
  # Each WiceGrid filter column is defined in two classes, one used for rendering the filter, the other
70
69
  # for generating query conditions. All these columns are in lib/wice/columns/*.rb .
71
70
  # File lib/wice/columns/column_processor_index.rb lists all predefined processors.
@@ -88,7 +87,6 @@ if defined?(Wice::Defaults)
88
87
  # Wice::Columns::ViewColumn, the second should be a name of conditions generator class inherited from
89
88
  # Wice::Columns::ConditionsGeneratorColumn .
90
89
 
91
-
92
90
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
93
91
  # Showing All Records #
94
92
 
@@ -107,7 +105,6 @@ if defined?(Wice::Defaults)
107
105
  # set to nil to skip the check
108
106
  Wice::Defaults::SWITCH_BACK_TO_PAGINATION_FROM = nil
109
107
 
110
-
111
108
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
112
109
  # Saving Queries #
113
110
 
@@ -115,40 +112,40 @@ if defined?(Wice::Defaults)
115
112
  # QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
116
113
  Wice::Defaults::QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
117
114
 
118
-
119
115
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
120
- # Here go settings related to the calendar helpers #
116
+ # Here go settings related to the date/datetime filters #
121
117
 
122
- # The default style of the date and datetime helper
123
- # * <tt>:calendar</tt> - JS calendar
124
- # * <tt>:html5</tt> - HTML5 date input field
125
- # * <tt>:standard</tt> - standard Rails date and datetime helpers
126
- # * <tt>:bootstrap</tt> - Bootstrap datepicker helper
127
- Wice::Defaults::HELPER_STYLE = :calendar
118
+ # Default column filters
119
+ # Possible values:
120
+ # * <tt>:jquery_datepicker</tt> - Jquery datepicker (works for datetime, too)
121
+ # * <tt>:bootstrap_datepicker</tt> - Bootstrap datepicker (works for datetime, too)
122
+ # * <tt>:rails_date_helper</tt> - standard Rails date helper
123
+ # * <tt>:rails_datetime_helper</tt> - standard Rails datetime helper
124
+
125
+ Wice::Defaults::DEFAULT_FILTER_FOR_DATE = :jquery_datepicker
126
+ Wice::Defaults::DEFAULT_FILTER_FOR_DATETIME = :jquery_datepicker
128
127
 
129
128
  # Format of the datetime displayed.
130
129
  # If you change the format, make sure to check if +DATETIME_PARSER+ can still parse this string.
131
- Wice::Defaults::DATETIME_FORMAT = "%Y-%m-%d %H:%M"
130
+ Wice::Defaults::DATETIME_FORMAT = '%Y-%m-%d %H:%M'
132
131
 
133
132
  # Format of the date displayed.
134
133
  # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
135
- Wice::Defaults::DATE_FORMAT = "%Y-%m-%d"
134
+ Wice::Defaults::DATE_FORMAT = '%Y-%m-%d'
136
135
 
137
136
  # Format of the date displayed in jQuery's Datepicker
138
137
  # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
139
- Wice::Defaults::DATE_FORMAT_JQUERY = "yy-mm-dd"
140
-
138
+ Wice::Defaults::DATE_FORMAT_JQUERY = 'yy-mm-dd'
141
139
 
142
140
  # Format of the date displayed in Bootstrap's Datepicker
143
141
  # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
144
- Wice::Defaults::DATE_FORMAT_BOOTSTRAP = "yyyy-mm-dd"
145
-
142
+ Wice::Defaults::DATE_FORMAT_BOOTSTRAP = 'yyyy-mm-dd'
146
143
 
147
144
  # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
148
145
  # format defined by +DATETIME_FORMAT+ and must generate a DateTime object.
149
146
  # 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
147
  # and modify it if needed.
151
- Wice::Defaults::DATETIME_PARSER = lambda{|datetime_string|
148
+ Wice::Defaults::DATETIME_PARSER = lambda do|datetime_string|
152
149
  if datetime_string.blank?
153
150
  nil
154
151
  elsif Time.zone
@@ -156,19 +153,18 @@ if defined?(Wice::Defaults)
156
153
  else
157
154
  Time.parse(datetime_string)
158
155
  end
159
- }
156
+ end
160
157
 
161
158
  # The range of years to display in jQuery Datepicker.
162
159
  # It can always be changed dynamically with the following javascript:
163
160
  # $( ".hasDatepicker" ).datepicker( "option", "yearRange", "2000:2042" );
164
161
  Wice::Defaults::DATEPICKER_YEAR_RANGE = (from = Date.current.year - 10).to_s + ':' + (from + 15).to_s
165
162
 
166
-
167
163
  # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
168
164
  # format defined by +DATETIME+ and must generate a Date object.
169
165
  # 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
170
166
  # and modify it if needed.
171
- Wice::Defaults::DATE_PARSER = lambda{|date_string|
167
+ Wice::Defaults::DATE_PARSER = lambda do|date_string|
172
168
  if date_string.blank?
173
169
  nil
174
170
  else
@@ -178,14 +174,13 @@ if defined?(Wice::Defaults)
178
174
  nil
179
175
  end
180
176
  end
181
- }
182
-
183
- # Icon to popup the calendar.
184
- Wice::Defaults::CALENDAR_ICON = "/assets/icons/grid/calendar_view_month.png"
185
-
186
- # popup calendar will be shown relative to the popup trigger element or to the mouse pointer
187
- Wice::Defaults::POPUP_PLACEMENT_STRATEGY = :trigger # :pointer
177
+ end
188
178
 
189
179
  # The name of the page method (should correspond to Kaminari.config.page_method_name)
190
180
  Wice::Defaults::PAGE_METHOD_NAME = :page
181
+
182
+ # By default ActiveRecord calls are always executed inside Model.unscoped{}.
183
+ # Setting <tt>USE_DEFAULT_SCOPE</tt> to true will use the default scope for all queries.
184
+ Wice::Defaults::USE_DEFAULT_SCOPE = false
185
+
191
186
  end
@@ -1,20 +1,30 @@
1
+ # encoding: utf-8
1
2
  module Wice
2
-
3
3
  # to be mixed in into ActiveRecord::ConnectionAdapters::Column
4
4
  module WiceGridExtentionToActiveRecordColumn #:nodoc:
5
+ # reference to the ActiveRecord model class
5
6
  attr_accessor :model
6
7
  end
7
8
 
8
-
9
-
10
9
  class ActiveRecordColumnWrapper #:nodoc:
11
10
  def initialize(column, all_filter_params, main_table, table_alias, custom_filter_active, filter_type) #:nodoc:
12
11
  @column = column
13
- @filter_type = filter_type
14
- @all_filter_params, @main_table, @table_alias, @custom_filter_active =
15
- all_filter_params, main_table, table_alias, custom_filter_active
16
- end
17
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
18
28
 
19
29
  def wg_initialize_request_parameters #:nodoc:
20
30
  @request_params = nil
@@ -31,6 +41,7 @@ module Wice
31
41
  # a datetime (with custom_filter it can be anything else, and not
32
42
  # the datetime hash {fr: ..., to: ...})
33
43
  if @request_params
44
+
34
45
  if (@column.type == :datetime || @column.type == :timestamp) && @request_params.is_a?(Hash)
35
46
  [:fr, :to].each do |sym|
36
47
  if @request_params[sym]
@@ -48,6 +59,7 @@ module Wice
48
59
  # a date (with custom_filter it can be anything else, and not
49
60
  # the date hash {fr: ..., to: ...})
50
61
  if @column.type == :date && @request_params.is_a?(Hash)
62
+
51
63
  [:fr, :to].each do |sym|
52
64
  if @request_params[sym]
53
65
  if @request_params[sym].is_a?(String)
@@ -57,10 +69,11 @@ module Wice
57
69
  end
58
70
  end
59
71
  end
72
+
60
73
  end
61
74
  end
62
75
 
63
- return wg_generate_conditions, current_parameter_name
76
+ [wg_generate_conditions, current_parameter_name]
64
77
  end
65
78
 
66
79
  def wg_generate_conditions #:nodoc:
@@ -72,12 +85,23 @@ module Wice
72
85
  return custom_processor.generate_conditions(@table_alias, @request_params)
73
86
  end
74
87
 
75
- column_type = @filter_type || @column.type.to_s
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
76
100
 
77
- processor_class = ::Wice::Columns.get_conditions_generator_column_processor(column_type)
101
+ processor_class = ::Wice::Columns.get_conditions_generator_column_processor(filter_type)
78
102
 
79
103
  if processor_class
80
- return processor_class.new(self).generate_conditions(@table_alias, @request_params)
104
+ return processor_class.new(self, column_type).generate_conditions(@table_alias, @request_params)
81
105
  else
82
106
  Wice.log("No processor for database type #{column_type}!!!")
83
107
  nil
@@ -92,13 +116,8 @@ module Wice
92
116
  @column.model
93
117
  end
94
118
 
95
-
96
119
  def alias_or_table_name(table_alias) #:nodoc:
97
120
  table_alias || @column.model.table_name
98
121
  end
99
-
100
-
101
122
  end
102
-
103
-
104
- end
123
+ end