will_filter 3.1.3 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rvmrc +1 -1
- data/Gemfile.lock +2 -2
- data/README.rdoc +0 -3
- data/app/assets/javascripts/will_filter/filter.js +5 -5
- data/app/assets/javascripts/will_filter/filter_prototype_effects.js +1 -1
- data/app/assets/stylesheets/will_filter/exporter.css.scss +72 -49
- data/app/assets/stylesheets/will_filter/filter.css.scss +1 -0
- data/app/controllers/will_filter/application_controller.rb +1 -1
- data/app/controllers/will_filter/calendar_controller.rb +1 -1
- data/app/controllers/will_filter/exporter_controller.rb +15 -26
- data/app/controllers/will_filter/filter_controller.rb +7 -1
- data/app/models/will_filter/filter.rb +69 -12
- data/app/views/will_filter/exporter/export.html.erb +26 -2
- data/app/views/will_filter/exporter/index.html.erb +35 -43
- data/app/views/will_filter/filter/_conditions.html.erb +13 -32
- data/app/views/will_filter/filter/_conditions_footer.html.erb +17 -0
- data/app/views/will_filter/filter/_conditions_header.html.erb +38 -0
- data/app/views/will_filter/filter/_container.html.erb +3 -25
- data/lib/generators/will_filter/templates/config.yml +34 -1
- data/lib/generators/will_filter/will_filter_generator.rb +1 -1
- data/lib/tasks/will_filter_tasks.rake +1 -5
- data/lib/will_filter.rb +1 -1
- data/lib/will_filter/calendar.rb +1 -1
- data/lib/will_filter/config.rb +9 -1
- data/lib/will_filter/containers/boolean.rb +1 -1
- data/lib/will_filter/containers/date.rb +2 -8
- data/lib/will_filter/containers/date_range.rb +3 -9
- data/lib/will_filter/containers/date_time.rb +2 -8
- data/lib/will_filter/containers/date_time_range.rb +4 -16
- data/lib/will_filter/containers/double.rb +52 -0
- data/lib/will_filter/containers/double_delimited.rb +50 -0
- data/lib/will_filter/containers/double_range.rb +64 -0
- data/lib/will_filter/containers/filter_list.rb +1 -1
- data/lib/will_filter/containers/list.rb +1 -1
- data/lib/will_filter/containers/nil.rb +1 -1
- data/lib/will_filter/containers/numeric.rb +1 -1
- data/lib/will_filter/containers/numeric_delimited.rb +1 -1
- data/lib/will_filter/containers/numeric_range.rb +1 -1
- data/lib/will_filter/containers/single_date.rb +3 -3
- data/lib/will_filter/containers/text.rb +1 -1
- data/lib/will_filter/containers/text_delimited.rb +1 -1
- data/lib/will_filter/engine.rb +1 -1
- data/lib/will_filter/extensions/action_controller_extension.rb +1 -1
- data/lib/will_filter/extensions/action_view_extension.rb +1 -1
- data/lib/will_filter/extensions/active_record_extension.rb +1 -1
- data/lib/will_filter/extensions/array_extension.rb +1 -1
- data/lib/will_filter/filter_condition.rb +1 -1
- data/lib/will_filter/filter_container.rb +21 -3
- data/lib/will_filter/filter_exception.rb +1 -1
- data/lib/will_filter/railtie.rb +1 -1
- data/lib/will_filter/version.rb +2 -2
- data/spec/containers/double_spec.rb +16 -0
- data/spec/fake_app.rb +6 -12
- data/test/dummy/app/models/event.rb +1 -1
- data/test/dummy/app/models/event_filter.rb +4 -0
- data/test/dummy/app/models/event_user_filter.rb +4 -0
- data/test/dummy/app/models/user_filter.rb +31 -2
- data/test/dummy/config/will_filter/config.yml +9 -1
- data/test/dummy/db/migrate/20120223232000_add_rank_to_events.rb +5 -0
- data/test/dummy/db/schema.rb +2 -1
- metadata +40 -108
- data/config/will_filter/config.yml +0 -97
- data/db/migrate/20110924023807_create_will_filter_filters.rb +0 -15
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -30,13 +30,7 @@ module WillFilter
|
|
30
30
|
|
31
31
|
def validate
|
32
32
|
return "Value must be provided" if value.blank?
|
33
|
-
return "Value must be a valid date/time (2008-01-01 14:30:00)" if time
|
34
|
-
end
|
35
|
-
|
36
|
-
def time
|
37
|
-
Time.parse(value)
|
38
|
-
rescue ArgumentError
|
39
|
-
nil
|
33
|
+
return "Value must be a valid date/time (2008-01-01 14:30:00)" if time.nil?
|
40
34
|
end
|
41
35
|
|
42
36
|
def sql_condition
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -39,25 +39,13 @@ module WillFilter
|
|
39
39
|
|
40
40
|
def validate
|
41
41
|
return "Start value must be provided" if start_value.blank?
|
42
|
-
return "Start value must be a valid date/time (2008-01-01 14:30:00)" if start_time
|
42
|
+
return "Start value must be a valid date/time (2008-01-01 14:30:00)" if start_time.nil?
|
43
43
|
return "End value must be provided" if end_value.blank?
|
44
|
-
return "End value must be a valid date/time (2008-01-01 14:30:00)" if end_time
|
45
|
-
end
|
46
|
-
|
47
|
-
def start_time
|
48
|
-
Time.parse(start_value)
|
49
|
-
rescue ArgumentError
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
|
53
|
-
def end_time
|
54
|
-
Time.parse(end_value)
|
55
|
-
rescue ArgumentError
|
56
|
-
nil
|
44
|
+
return "End value must be a valid date/time (2008-01-01 14:30:00)" if end_time.nil?
|
57
45
|
end
|
58
46
|
|
59
47
|
def sql_condition
|
60
|
-
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ",
|
48
|
+
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", time(start_value), time(end_value)] if operator == :is_in_the_range
|
61
49
|
end
|
62
50
|
end
|
63
51
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
module WillFilter
|
25
|
+
module Containers
|
26
|
+
class Double < WillFilter::FilterContainer
|
27
|
+
def self.operators
|
28
|
+
[:is, :is_not, :is_less_than, :is_greater_than]
|
29
|
+
end
|
30
|
+
|
31
|
+
def template_name
|
32
|
+
'text'
|
33
|
+
end
|
34
|
+
|
35
|
+
def numeric_value
|
36
|
+
value.to_f
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate
|
40
|
+
return "Value must be provided" if value.blank?
|
41
|
+
return "Value must be a valid floating point number" unless is_floating_point?(value)
|
42
|
+
end
|
43
|
+
|
44
|
+
def sql_condition
|
45
|
+
return [" #{condition.full_key} = ? ", numeric_value] if operator == :is
|
46
|
+
return [" #{condition.full_key} <> ? ", numeric_value] if operator == :is_not
|
47
|
+
return [" #{condition.full_key} < ? ", numeric_value] if operator == :is_less_than
|
48
|
+
return [" #{condition.full_key} > ? ", numeric_value] if operator == :is_greater_than
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
module WillFilter
|
25
|
+
module Containers
|
26
|
+
class DoubleDelimited < WillFilter::FilterContainer
|
27
|
+
NUMERIC_DELIMITER = "," unless defined?(NUMERIC_DELIMITER)
|
28
|
+
|
29
|
+
def self.operators
|
30
|
+
[:is_in]
|
31
|
+
end
|
32
|
+
|
33
|
+
def template_name
|
34
|
+
'text'
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate
|
38
|
+
return "Values must be provided. Separate values with '#{NUMERIC_DELIMITER}'" if value.blank?
|
39
|
+
end
|
40
|
+
|
41
|
+
def split_values
|
42
|
+
value.split(NUMERIC_DELIMITER).collect{|v| v.strip.to_f}
|
43
|
+
end
|
44
|
+
|
45
|
+
def sql_condition
|
46
|
+
return [" #{condition.full_key} in (?) ", split_values] if operator == :is_in
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
module WillFilter
|
25
|
+
module Containers
|
26
|
+
class DoubleRange < WillFilter::FilterContainer
|
27
|
+
attr_accessor :start_value, :end_value
|
28
|
+
|
29
|
+
def self.operators
|
30
|
+
[:is_in_the_range]
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(filter, criteria_key, operator, values)
|
34
|
+
super(filter, criteria_key, operator, values)
|
35
|
+
|
36
|
+
@start_value = values[0]
|
37
|
+
@end_value = values[1] if values.size > 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate
|
41
|
+
return "Start value must be provided" if start_value.blank?
|
42
|
+
return "Start value must be a floating point number" unless is_floating_point?(start_value)
|
43
|
+
return "End value must be provided" if end_value.blank?
|
44
|
+
return "End value must be a floating point number" unless is_floating_point?(end_value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def template_name
|
48
|
+
'numeric_range'
|
49
|
+
end
|
50
|
+
|
51
|
+
def numeric_start_value
|
52
|
+
start_value.to_f
|
53
|
+
end
|
54
|
+
|
55
|
+
def numeric_end_value
|
56
|
+
end_value.to_f
|
57
|
+
end
|
58
|
+
|
59
|
+
def sql_condition
|
60
|
+
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -49,8 +49,8 @@ module WillFilter
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def sql_condition
|
52
|
-
return [" #{condition.full_key} >= ? and #{condition.full_key} < ? ",
|
53
|
-
return [" #{condition.full_key} < ? and #{condition.full_key} >= ? ",
|
52
|
+
return [" #{condition.full_key} >= ? and #{condition.full_key} < ? ", time, time + 1.day] if operator == :is_on
|
53
|
+
return [" #{condition.full_key} < ? and #{condition.full_key} >= ? ", time, time + 1.day] if operator == :is_not_on
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/will_filter/engine.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -36,6 +36,20 @@ module WillFilter
|
|
36
36
|
values.first
|
37
37
|
end
|
38
38
|
|
39
|
+
def date(dt = value)
|
40
|
+
return nil unless dt
|
41
|
+
Time.parse(dt).to_date
|
42
|
+
rescue
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def time(tm = value)
|
47
|
+
return nil unless tm
|
48
|
+
Time.parse(tm)
|
49
|
+
rescue
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
39
53
|
def sanitized_value(index = 0)
|
40
54
|
return '' if index >= values.size
|
41
55
|
return '' if values[index].blank?
|
@@ -64,9 +78,13 @@ module WillFilter
|
|
64
78
|
params["wf_v#{index}_#{v_index}"] = v
|
65
79
|
end
|
66
80
|
end
|
67
|
-
|
81
|
+
|
82
|
+
def is_floating_point?(s)
|
83
|
+
s.to_s.match(/\A[-+]?[0-9]*\.?[0-9]+\Z/) == nil ? false : true
|
84
|
+
end
|
85
|
+
|
68
86
|
def is_numeric?(s)
|
69
|
-
s.to_s.match(/\A[
|
87
|
+
s.to_s.match(/\A[-+]?[0-9]*\Z/) == nil ? false : true
|
70
88
|
end
|
71
89
|
|
72
90
|
end
|
data/lib/will_filter/railtie.rb
CHANGED
data/lib/will_filter/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2010-
|
2
|
+
# Copyright (c) 2010-2012 Michael Berkovich
|
3
3
|
#
|
4
4
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
5
|
# a copy of this software and associated documentation files (the
|
@@ -22,5 +22,5 @@
|
|
22
22
|
#++
|
23
23
|
|
24
24
|
module WillFilter
|
25
|
-
VERSION = "3.1.
|
25
|
+
VERSION = "3.1.5"
|
26
26
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe WillFilter::Containers::Double do
|
4
|
+
describe '#filter' do
|
5
|
+
before :all do
|
6
|
+
5.times {|i| User.create(:first_name => "User #{i}")}
|
7
|
+
end
|
8
|
+
|
9
|
+
context "filtering with is operator" do
|
10
|
+
it "should return a single result" do
|
11
|
+
User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "is", :wf_v0_0 => "User 1"}).total_count.should == 1
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|