will_filter 5.1.0 → 5.1.1
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/Gemfile.lock +2 -2
- data/lib/will_filter/containers/boolean.rb +6 -6
- data/lib/will_filter/containers/date.rb +9 -9
- data/lib/will_filter/containers/date_range.rb +4 -4
- data/lib/will_filter/containers/date_time.rb +8 -8
- data/lib/will_filter/containers/date_time_range.rb +6 -6
- data/lib/will_filter/containers/double.rb +8 -8
- data/lib/will_filter/containers/double_delimited.rb +7 -7
- data/lib/will_filter/containers/double_range.rb +12 -11
- data/lib/will_filter/containers/filter_list.rb +7 -12
- data/lib/will_filter/containers/list.rb +8 -7
- data/lib/will_filter/containers/nil.rb +5 -5
- data/lib/will_filter/containers/numeric.rb +8 -8
- data/lib/will_filter/containers/numeric_delimited.rb +7 -7
- data/lib/will_filter/containers/numeric_range.rb +10 -10
- data/lib/will_filter/containers/single_date.rb +7 -8
- data/lib/will_filter/containers/text.rb +9 -8
- data/lib/will_filter/containers/text_delimited.rb +10 -9
- data/lib/will_filter/version.rb +1 -1
- data/test/dummy/app/assets/javascripts/bootstrap.js +1951 -1951
- data/test/dummy/app/assets/stylesheets/bootstrap.min.css +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fe8cebd409b2e307d3720d1073ea9d6bd5f79d2
|
4
|
+
data.tar.gz: ae57f12d3fff3f71bfeb92fb6c2117e4fe314878
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11dc83721d03a91f5c5c5b271850fd0714d96cf7b7c662969d3fd4819603cdcda8c3b64535d7229a3ef9e0a781e06bed62afa1be3ff946f43a2e2fe214b4a264
|
7
|
+
data.tar.gz: f266ee2c9b40ce0239792a014cc556237e687c8c6868ce31d10a8b15ca1ba43c5d187041ed2eec7e739ca1adfbc75cdd16cf8f6a89ce377174588e92dec823bf
|
data/Gemfile.lock
CHANGED
@@ -33,20 +33,20 @@
|
|
33
33
|
module WillFilter
|
34
34
|
module Containers
|
35
35
|
class Boolean < WillFilter::FilterContainer
|
36
|
-
|
36
|
+
|
37
37
|
def self.operators
|
38
38
|
[:is]
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def selected?
|
42
|
-
value ==
|
42
|
+
value.to_s == '1'
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def sql_condition
|
46
46
|
return [" #{condition.full_key} = ? ", (selected? ? true : false)] if operator == :is
|
47
47
|
end
|
48
|
-
|
49
|
-
end
|
48
|
+
|
49
|
+
end
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -36,19 +36,19 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is, :is_not, :is_after, :is_before]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def validate
|
41
|
-
return
|
42
|
-
return
|
41
|
+
return 'Value must be provided' if value.blank?
|
42
|
+
return 'Value must be a valid date (2008-01-01)' if date.nil?
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def sql_condition
|
46
|
-
return [" #{condition.full_key} = ? ",
|
47
|
-
return [" #{condition.full_key} <> ? ", date]
|
48
|
-
return [" #{condition.full_key} > ? ",
|
49
|
-
return [" #{condition.full_key} < ? ",
|
46
|
+
return [" #{condition.full_key} = ? ", date] if operator == :is
|
47
|
+
return [" #{condition.full_key} <> ? ", date] if operator == :is_not
|
48
|
+
return [" #{condition.full_key} > ? ", date] if operator == :is_after
|
49
|
+
return [" #{condition.full_key} < ? ", date] if operator == :is_before
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -36,24 +36,24 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is_in_the_range]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def initialize(filter, criteria_key, operator, values)
|
41
41
|
super(filter, criteria_key, operator, values)
|
42
42
|
@start_date = values[0]
|
43
43
|
@end_date = values[1] if values.size > 1
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def validate
|
47
47
|
return "Start value must be provided" if @start_date.blank?
|
48
48
|
return "Start value must be a valid date (2008-01-01)" if date(@start_date).nil?
|
49
49
|
return "End value must be provided" if @end_date.blank?
|
50
50
|
return "End value must be a valid date (2008-01-01)" if date(@end_date).nil?
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def sql_condition
|
54
54
|
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", date(@start_date), date(@end_date)] if operator == :is_in_the_range
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -36,17 +36,17 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is, :is_not, :is_after, :is_before]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def validate
|
41
|
-
return
|
42
|
-
return
|
41
|
+
return 'Value must be provided' if value.blank?
|
42
|
+
return 'Value must be a valid date/time (2008-01-01 14:30:00)' if time.nil?
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def sql_condition
|
46
|
-
return [" #{condition.full_key} = ? ",
|
47
|
-
return [" #{condition.full_key} <> ? ",
|
48
|
-
return [" #{condition.full_key} > ? ",
|
49
|
-
return [" #{condition.full_key} < ? ",
|
46
|
+
return [" #{condition.full_key} = ? ", time] if operator == :is
|
47
|
+
return [" #{condition.full_key} <> ? ", time] if operator == :is_not
|
48
|
+
return [" #{condition.full_key} > ? ", time] if operator == :is_after
|
49
|
+
return [" #{condition.full_key} < ? ", time] if operator == :is_before
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -34,28 +34,28 @@ module WillFilter
|
|
34
34
|
module Containers
|
35
35
|
class DateTimeRange < WillFilter::FilterContainer
|
36
36
|
attr_accessor :start_value, :end_value
|
37
|
-
|
37
|
+
|
38
38
|
def self.operators
|
39
39
|
[:is_in_the_range]
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def initialize(filter, criteria_key, operator, values)
|
43
43
|
super(filter, criteria_key, operator, values)
|
44
|
-
|
44
|
+
|
45
45
|
@start_value = values[0]
|
46
46
|
@end_value = values[1] if values.size > 1
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def validate
|
50
50
|
return "Start value must be provided" if start_value.blank?
|
51
51
|
return "Start value must be a valid date/time (2008-01-01 14:30:00)" if time(start_value).nil?
|
52
52
|
return "End value must be provided" if end_value.blank?
|
53
53
|
return "End value must be a valid date/time (2008-01-01 14:30:00)" if time(end_value).nil?
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def sql_condition
|
57
57
|
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", time(start_value), time(end_value)] if operator == :is_in_the_range
|
58
58
|
end
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
61
61
|
end
|
@@ -36,25 +36,25 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is, :is_not, :is_less_than, :is_greater_than]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def template_name
|
41
41
|
'text'
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def numeric_value
|
45
45
|
value.to_f
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def validate
|
49
49
|
return "Value must be provided" if value.blank?
|
50
50
|
return "Value must be a valid floating point number" unless is_floating_point?(value)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def sql_condition
|
54
|
-
return [" #{condition.full_key} = ? ",
|
55
|
-
return [" #{condition.full_key} <> ? ",
|
56
|
-
return [" #{condition.full_key} < ? ",
|
57
|
-
return [" #{condition.full_key} > ? ",
|
54
|
+
return [" #{condition.full_key} = ? ", numeric_value] if operator == :is
|
55
|
+
return [" #{condition.full_key} <> ? ", numeric_value] if operator == :is_not
|
56
|
+
return [" #{condition.full_key} < ? ", numeric_value] if operator == :is_less_than
|
57
|
+
return [" #{condition.full_key} > ? ", numeric_value] if operator == :is_greater_than
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -33,24 +33,24 @@
|
|
33
33
|
module WillFilter
|
34
34
|
module Containers
|
35
35
|
class DoubleDelimited < WillFilter::FilterContainer
|
36
|
-
NUMERIC_DELIMITER = ","
|
37
|
-
|
36
|
+
NUMERIC_DELIMITER = "," unless defined?(NUMERIC_DELIMITER)
|
37
|
+
|
38
38
|
def self.operators
|
39
39
|
[:is_in]
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def template_name
|
43
43
|
'text'
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def validate
|
47
47
|
return "Values must be provided. Separate values with '#{NUMERIC_DELIMITER}'" if value.blank?
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def split_values
|
51
|
-
value.split(NUMERIC_DELIMITER).collect{|v| v.strip.to_f}
|
51
|
+
value.split(NUMERIC_DELIMITER).collect {|v| v.strip.to_f}
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def sql_condition
|
55
55
|
return [" #{condition.full_key} in (?) ", split_values] if operator == :is_in
|
56
56
|
end
|
@@ -30,29 +30,30 @@
|
|
30
30
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
31
|
#++
|
32
32
|
|
33
|
+
|
33
34
|
module WillFilter
|
34
35
|
module Containers
|
35
36
|
class DoubleRange < WillFilter::FilterContainer
|
36
37
|
attr_accessor :start_value, :end_value
|
37
|
-
|
38
|
+
|
38
39
|
def self.operators
|
39
40
|
[:is_in_the_range]
|
40
41
|
end
|
41
|
-
|
42
|
+
|
42
43
|
def initialize(filter, criteria_key, operator, values)
|
43
44
|
super(filter, criteria_key, operator, values)
|
44
|
-
|
45
|
+
|
45
46
|
@start_value = values[0]
|
46
47
|
@end_value = values[1] if values.size > 1
|
47
48
|
end
|
48
|
-
|
49
|
+
|
49
50
|
def validate
|
50
|
-
return "Start value must be provided"
|
51
|
-
return "Start value must be a floating point number"
|
52
|
-
return "End value must be provided"
|
53
|
-
return "End value must be a floating point number"
|
51
|
+
return "Start value must be provided" if start_value.blank?
|
52
|
+
return "Start value must be a floating point number" unless is_floating_point?(start_value)
|
53
|
+
return "End value must be provided" if end_value.blank?
|
54
|
+
return "End value must be a floating point number" unless is_floating_point?(end_value)
|
54
55
|
end
|
55
|
-
|
56
|
+
|
56
57
|
def template_name
|
57
58
|
'numeric_range'
|
58
59
|
end
|
@@ -60,11 +61,11 @@ module WillFilter
|
|
60
61
|
def numeric_start_value
|
61
62
|
start_value.to_f
|
62
63
|
end
|
63
|
-
|
64
|
+
|
64
65
|
def numeric_end_value
|
65
66
|
end_value.to_f
|
66
67
|
end
|
67
|
-
|
68
|
+
|
68
69
|
def sql_condition
|
69
70
|
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range
|
70
71
|
end
|
@@ -36,39 +36,34 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is_filtered_by]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def validate
|
41
41
|
return "Value must be provided" if value.blank?
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def template_name
|
45
45
|
'list'
|
46
46
|
end
|
47
47
|
|
48
48
|
def linked_filter
|
49
49
|
@linked_filter ||= begin
|
50
|
-
|
51
|
-
|
52
|
-
if model_class
|
53
|
-
model_class_name = model_class.name
|
54
|
-
elsif condition.key == :id
|
50
|
+
if condition.key == :id
|
55
51
|
model_class_name = filter.model_class_name
|
56
52
|
else
|
57
53
|
model_class_name = condition.key.to_s[0..-4].camelcase
|
58
54
|
end
|
59
|
-
|
60
55
|
WillFilter::Filter.new(model_class_name)
|
61
56
|
end
|
62
57
|
end
|
63
|
-
|
58
|
+
|
64
59
|
def options
|
65
60
|
linked_filter.saved_filters(false)
|
66
61
|
end
|
67
|
-
|
62
|
+
|
68
63
|
def sql_condition
|
69
64
|
return nil unless operator == :is_filtered_by
|
70
65
|
sub_filter = WillFilter::Filter.find_by_id(value) || linked_filter.user_filters.first
|
71
|
-
return [
|
66
|
+
return [''] unless sub_filter
|
72
67
|
|
73
68
|
sub_conds = sub_filter.sql_conditions
|
74
69
|
|
@@ -76,7 +71,7 @@ module WillFilter
|
|
76
71
|
sub_conds[0] = " #{condition.full_key} IN (SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name}) "
|
77
72
|
else
|
78
73
|
sub_conds[0] = " #{condition.full_key} IN (SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name} WHERE #{sub_conds[0]}) "
|
79
|
-
end
|
74
|
+
end
|
80
75
|
|
81
76
|
sub_conds
|
82
77
|
end
|
@@ -36,7 +36,7 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is, :is_not, :contains, :does_not_contain]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def options
|
41
41
|
opts = []
|
42
42
|
filter.value_options_for(condition.key).each do |item|
|
@@ -52,14 +52,15 @@ module WillFilter
|
|
52
52
|
end
|
53
53
|
opts
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def sql_condition
|
57
|
-
|
58
|
-
return [" #{condition.full_key}
|
59
|
-
return [" #{condition.full_key}
|
60
|
-
return [" #{condition.full_key}
|
57
|
+
sanitized_value = value.to_s.downcase
|
58
|
+
return [" lower(#{condition.full_key}) = ? ", sanitized_value] if operator == :is
|
59
|
+
return [" lower(#{condition.full_key}) <> ? ", sanitized_value] if operator == :is_not
|
60
|
+
return [" lower(#{condition.full_key}) like ? ", "%#{sanitized_value}%"] if operator == :contains
|
61
|
+
return [" lower(#{condition.full_key}) not like ? ", "%#{sanitized_value}%"] if operator == :does_not_cotain
|
61
62
|
end
|
62
|
-
|
63
|
+
|
63
64
|
end
|
64
65
|
end
|
65
66
|
end
|
@@ -36,18 +36,18 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is_provided, :is_not_provided]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def template_name
|
41
41
|
'blank'
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def validate
|
45
45
|
# no validation is necessary
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def sql_condition
|
49
|
-
return [" #{condition.full_key} is not null "]
|
50
|
-
return [" #{condition.full_key} is null "]
|
49
|
+
return [" #{condition.full_key} is not null "] if operator == :is_provided
|
50
|
+
return [" #{condition.full_key} is null "] if operator == :is_not_provided
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -36,25 +36,25 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is, :is_not, :is_less_than, :is_greater_than]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def template_name
|
41
41
|
'text'
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def numeric_value
|
45
45
|
value.to_i
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def validate
|
49
49
|
return "Value must be provided" if value.blank?
|
50
50
|
return "Value must be numeric" unless is_numeric?(value)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def sql_condition
|
54
|
-
return [" #{condition.full_key} = ? ",
|
55
|
-
return [" #{condition.full_key} <> ? ",
|
56
|
-
return [" #{condition.full_key} < ? ",
|
57
|
-
return [" #{condition.full_key} > ? ",
|
54
|
+
return [" #{condition.full_key} = ? ", numeric_value] if operator == :is
|
55
|
+
return [" #{condition.full_key} <> ? ", numeric_value] if operator == :is_not
|
56
|
+
return [" #{condition.full_key} < ? ", numeric_value] if operator == :is_less_than
|
57
|
+
return [" #{condition.full_key} > ? ", numeric_value] if operator == :is_greater_than
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -33,24 +33,24 @@
|
|
33
33
|
module WillFilter
|
34
34
|
module Containers
|
35
35
|
class NumericDelimited < WillFilter::FilterContainer
|
36
|
-
NUMERIC_DELIMITER = ","
|
37
|
-
|
36
|
+
NUMERIC_DELIMITER = "," unless defined?(NUMERIC_DELIMITER)
|
37
|
+
|
38
38
|
def self.operators
|
39
39
|
[:is_in]
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def template_name
|
43
43
|
'text'
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def validate
|
47
47
|
return "Values must be provided. Separate values with '#{NUMERIC_DELIMITER}'" if value.blank?
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def split_values
|
51
|
-
value.split(NUMERIC_DELIMITER).collect{|v| v.strip.to_i}
|
51
|
+
value.split(NUMERIC_DELIMITER).collect {|v| v.strip.to_i}
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def sql_condition
|
55
55
|
return [" #{condition.full_key} in (?) ", split_values] if operator == :is_in
|
56
56
|
end
|
@@ -34,33 +34,33 @@ module WillFilter
|
|
34
34
|
module Containers
|
35
35
|
class NumericRange < WillFilter::FilterContainer
|
36
36
|
attr_accessor :start_value, :end_value
|
37
|
-
|
37
|
+
|
38
38
|
def self.operators
|
39
39
|
[:is_in_the_range]
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def initialize(filter, criteria_key, operator, values)
|
43
43
|
super(filter, criteria_key, operator, values)
|
44
|
-
|
44
|
+
|
45
45
|
@start_value = values[0]
|
46
46
|
@end_value = values[1] if values.size > 1
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def validate
|
50
50
|
return "Start value must be provided" if start_value.blank?
|
51
|
-
return "Start value must be numeric"
|
52
|
-
return "End value must be provided"
|
53
|
-
return "End value must be numeric"
|
51
|
+
return "Start value must be numeric" unless is_numeric?(start_value)
|
52
|
+
return "End value must be provided" if end_value.blank?
|
53
|
+
return "End value must be numeric" unless is_numeric?(end_value)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def numeric_start_value
|
57
57
|
start_value.to_i
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def numeric_end_value
|
61
61
|
end_value.to_i
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def sql_condition
|
65
65
|
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range
|
66
66
|
end
|
@@ -36,32 +36,31 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is_on, :is_not_on]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def template_name
|
41
41
|
'date'
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def validate
|
45
45
|
return "Value must be provided" if value.blank?
|
46
46
|
return "Value must be a valid date (2008-01-01)" if start_date_time == nil
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def start_date_time
|
50
50
|
@start_date_time ||= Time.parse(value)
|
51
51
|
rescue ArgumentError
|
52
52
|
nil
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def end_date_time
|
56
56
|
(start_date_time + 1.day)
|
57
57
|
rescue ArgumentError
|
58
58
|
nil
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def sql_condition
|
62
|
-
return [
|
63
|
-
return [" #{condition.full_key}
|
64
|
-
return [" #{condition.full_key} < ? and #{condition.full_key} >= ? ", time, time + 1.day] if operator == :is_not_on
|
62
|
+
return [" #{condition.full_key} >= ? and #{condition.full_key} < ? ", time, time + 1.day] if operator == :is_on
|
63
|
+
return [" #{condition.full_key} < ? and #{condition.full_key} >= ? ", time, time + 1.day] if operator == :is_not_on
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
@@ -36,18 +36,19 @@ module WillFilter
|
|
36
36
|
def self.operators
|
37
37
|
[:is, :is_not, :contains, :does_not_contain, :starts_with, :ends_with]
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def validate
|
41
41
|
# always valid, even when it is empty
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def sql_condition
|
45
|
-
|
46
|
-
return [" #{condition.full_key}
|
47
|
-
return [" #{condition.full_key}
|
48
|
-
return [" #{condition.full_key}
|
49
|
-
return [" #{condition.full_key} like ? ", "
|
50
|
-
return [" #{condition.full_key} like ? ", "
|
45
|
+
sanitized_value = value.to_s.downcase
|
46
|
+
return [" lower(#{condition.full_key}) = ? ", sanitized_value] if operator == :is
|
47
|
+
return [" lower(#{condition.full_key}) <> ? ", sanitized_value] if operator == :is_not
|
48
|
+
return [" lower(#{condition.full_key}) like ? ", "%#{sanitized_value}%"] if operator == :contains
|
49
|
+
return [" lower(#{condition.full_key}) not like ? ", "%#{sanitized_value}%"] if operator == :does_not_contain
|
50
|
+
return [" lower(#{condition.full_key}) like ? ", "#{sanitized_value}%"] if operator == :starts_with
|
51
|
+
return [" lower(#{condition.full_key}) like ? ", "%#{sanitized_value}"] if operator == :ends_with
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -33,27 +33,28 @@
|
|
33
33
|
module WillFilter
|
34
34
|
module Containers
|
35
35
|
class TextDelimited < WillFilter::FilterContainer
|
36
|
-
TEXT_DELIMITER = ","
|
37
|
-
|
36
|
+
TEXT_DELIMITER = "," unless defined?(TEXT_DELIMITER)
|
37
|
+
|
38
38
|
def self.operators
|
39
39
|
[:is_in, :is_not_in]
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def template_name
|
43
43
|
'text'
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def validate
|
47
47
|
return "Values must be provided. Separate values with '#{TEXT_DELIMITER}'" if value.blank?
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def split_values
|
51
|
-
value.
|
51
|
+
value.split(TEXT_DELIMITER)
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def sql_condition
|
55
|
-
|
56
|
-
return [" #{condition.full_key}
|
55
|
+
sanitized_values = split_values.collect {|val| val.to_s.downcase}
|
56
|
+
return [" lower(#{condition.full_key}) in (?) ", sanitized_values] if operator == :is_in
|
57
|
+
return [" lower(#{condition.full_key}) not in (?) ", sanitized_values] if operator == :is_not_in
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
data/lib/will_filter/version.rb
CHANGED