wice_grid_mongoid 6.2.1 → 6.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.2.1
1
+ 6.2.2
@@ -15,43 +15,44 @@ module Wice
15
15
  end
16
16
  end
17
17
 
18
- # class FilterConditionsGeneratorCustomFilter < FilterConditionsGenerator #:nodoc:
19
-
20
- # def generate_conditions(opts) #:nodoc:
21
- # if opts.empty?
22
- # Wice.log "empty parameters for the grid custom filter"
23
- # return false
24
- # end
25
- # opts = (opts.kind_of?(Array) && opts.size == 1) ? opts[0] : opts
26
-
27
- # if opts.kind_of?(Array)
28
- # opts_with_special_values, normal_opts = opts.partition{|v| ::Wice::GridTools.special_value(v)}
29
-
30
- # conditions_ar = if normal_opts.size > 0
31
- # [" #{@field.alias_or_table_name(table_alias)}.#{@field.name} IN ( " + (['?'] * normal_opts.size).join(', ') + ' )'] + normal_opts
32
- # else
33
- # []
34
- # end
35
-
36
- # if opts_with_special_values.size > 0
37
- # special_conditions = opts_with_special_values.collect{|v| " #{@field.alias_or_table_name(table_alias)}.#{@field.name} is " + v}.join(' or ')
38
- # if conditions_ar.size > 0
39
- # conditions_ar[0] = " (#{conditions_ar[0]} or #{special_conditions} ) "
40
- # else
41
- # conditions_ar = " ( #{special_conditions} ) "
42
- # end
43
- # end
44
- # conditions_ar
45
- # else
46
- # if ::Wice::GridTools.special_value(opts)
47
- # " #{@field.alias_or_table_name(table_alias)}.#{@field.name} is " + opts
48
- # else
49
- # [" #{@field.alias_or_table_name(table_alias)}.#{@field.name} = ?", opts]
50
- # end
51
- # end
52
- # end
53
-
54
- # end
18
+ class FilterConditionsGeneratorCustomFilter < FilterConditionsGenerator #:nodoc:
19
+
20
+ def generate_conditions(opts) #:nodoc:
21
+ return false # should be implemented
22
+ # if opts.empty?
23
+ # Wice.log "empty parameters for the grid custom filter"
24
+ # return false
25
+ # end
26
+ # opts = (opts.kind_of?(Array) && opts.size == 1) ? opts[0] : opts
27
+
28
+ # if opts.kind_of?(Array)
29
+ # opts_with_special_values, normal_opts = opts.partition{|v| ::Wice::GridTools.special_value(v)}
30
+
31
+ # conditions_ar = if normal_opts.size > 0
32
+ # [" #{@field.alias_or_table_name(table_alias)}.#{@field.name} IN ( " + (['?'] * normal_opts.size).join(', ') + ' )'] + normal_opts
33
+ # else
34
+ # []
35
+ # end
36
+
37
+ # if opts_with_special_values.size > 0
38
+ # special_conditions = opts_with_special_values.collect{|v| " #{@field.alias_or_table_name(table_alias)}.#{@field.name} is " + v}.join(' or ')
39
+ # if conditions_ar.size > 0
40
+ # conditions_ar[0] = " (#{conditions_ar[0]} or #{special_conditions} ) "
41
+ # else
42
+ # conditions_ar = " ( #{special_conditions} ) "
43
+ # end
44
+ # end
45
+ # conditions_ar
46
+ # else
47
+ # if ::Wice::GridTools.special_value(opts)
48
+ # " #{@field.alias_or_table_name(table_alias)}.#{@field.name} is " + opts
49
+ # else
50
+ # [" #{@field.alias_or_table_name(table_alias)}.#{@field.name} = ?", opts]
51
+ # end
52
+ # end
53
+ end
54
+
55
+ end
55
56
 
56
57
  class FilterConditionsGeneratorBoolean < FilterConditionsGenerator #:nodoc:
57
58
  @@handled_type[Boolean] = self
data/lib/mongoid_field.rb CHANGED
@@ -10,15 +10,30 @@ module Wice
10
10
  # Preprocess incoming parameters for datetime, if what's coming in is
11
11
  # a datetime (with custom_filter it can be anything else, and not
12
12
  # the datetime hash {"fr" => ..., "to" => ...})
13
- if (self.type == Time) && request_params.is_a?(Hash)
14
- ["fr", "to"].each do |sym|
15
- if request_params[sym]
16
- if request_params[sym].is_a?(String)
17
- request_params[sym] = Time.parse(Wice::Defaults::DATETIME_PARSER.call(request_params[sym]).to_s)
18
- elsif request_params[sym].is_a?(Hash)
19
- request_params[sym] = Time.parse(::Wice::GridTools.params_2_datetime(request_params[sym]).to_s)
13
+ if (self.type == Time)
14
+ if request_params.is_a?(Hash)
15
+ ["fr", "to"].each do |sym|
16
+ if request_params[sym]
17
+ if request_params[sym].is_a?(String)
18
+ request_params[sym] = Time.parse(Wice::Defaults::DATETIME_PARSER.call(request_params[sym]).to_s)
19
+ elsif request_params[sym].is_a?(Hash)
20
+ request_params[sym] = Time.parse(::Wice::GridTools.params_2_datetime(request_params[sym]).to_s)
21
+ end
20
22
  end
21
23
  end
24
+ elsif request_params.is_a?(Array) && request_params.size == 1
25
+ ago = request_params.first
26
+ today = Time.now.beginning_of_day
27
+ agos = {'1 day' => today - 24.hours,
28
+ '1 week' => today - 7.days,
29
+ '1 month' => today - 1.month,
30
+ 'ever' => Time.parse("2000-01-01")}
31
+ if agos.keys.include?(ago)
32
+ request_params = {}
33
+ #regular filtering viea 'fr', 'to' field
34
+ request_params[:fr] = agos[ago]
35
+ custom_filter_active = nil
36
+ end
22
37
  end
23
38
  end
24
39
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wice_grid_mongoid}
8
- s.version = "6.2.1"
8
+ s.version = "6.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yuri Leikind", "Aleksandr Furmanov"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wice_grid_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 6
8
8
  - 2
9
- - 1
10
- version: 6.2.1
9
+ - 2
10
+ version: 6.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Yuri Leikind