will_filter 3.1.3 → 3.1.5

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 (64) hide show
  1. data/.gitignore +1 -0
  2. data/.rvmrc +1 -1
  3. data/Gemfile.lock +2 -2
  4. data/README.rdoc +0 -3
  5. data/app/assets/javascripts/will_filter/filter.js +5 -5
  6. data/app/assets/javascripts/will_filter/filter_prototype_effects.js +1 -1
  7. data/app/assets/stylesheets/will_filter/exporter.css.scss +72 -49
  8. data/app/assets/stylesheets/will_filter/filter.css.scss +1 -0
  9. data/app/controllers/will_filter/application_controller.rb +1 -1
  10. data/app/controllers/will_filter/calendar_controller.rb +1 -1
  11. data/app/controllers/will_filter/exporter_controller.rb +15 -26
  12. data/app/controllers/will_filter/filter_controller.rb +7 -1
  13. data/app/models/will_filter/filter.rb +69 -12
  14. data/app/views/will_filter/exporter/export.html.erb +26 -2
  15. data/app/views/will_filter/exporter/index.html.erb +35 -43
  16. data/app/views/will_filter/filter/_conditions.html.erb +13 -32
  17. data/app/views/will_filter/filter/_conditions_footer.html.erb +17 -0
  18. data/app/views/will_filter/filter/_conditions_header.html.erb +38 -0
  19. data/app/views/will_filter/filter/_container.html.erb +3 -25
  20. data/lib/generators/will_filter/templates/config.yml +34 -1
  21. data/lib/generators/will_filter/will_filter_generator.rb +1 -1
  22. data/lib/tasks/will_filter_tasks.rake +1 -5
  23. data/lib/will_filter.rb +1 -1
  24. data/lib/will_filter/calendar.rb +1 -1
  25. data/lib/will_filter/config.rb +9 -1
  26. data/lib/will_filter/containers/boolean.rb +1 -1
  27. data/lib/will_filter/containers/date.rb +2 -8
  28. data/lib/will_filter/containers/date_range.rb +3 -9
  29. data/lib/will_filter/containers/date_time.rb +2 -8
  30. data/lib/will_filter/containers/date_time_range.rb +4 -16
  31. data/lib/will_filter/containers/double.rb +52 -0
  32. data/lib/will_filter/containers/double_delimited.rb +50 -0
  33. data/lib/will_filter/containers/double_range.rb +64 -0
  34. data/lib/will_filter/containers/filter_list.rb +1 -1
  35. data/lib/will_filter/containers/list.rb +1 -1
  36. data/lib/will_filter/containers/nil.rb +1 -1
  37. data/lib/will_filter/containers/numeric.rb +1 -1
  38. data/lib/will_filter/containers/numeric_delimited.rb +1 -1
  39. data/lib/will_filter/containers/numeric_range.rb +1 -1
  40. data/lib/will_filter/containers/single_date.rb +3 -3
  41. data/lib/will_filter/containers/text.rb +1 -1
  42. data/lib/will_filter/containers/text_delimited.rb +1 -1
  43. data/lib/will_filter/engine.rb +1 -1
  44. data/lib/will_filter/extensions/action_controller_extension.rb +1 -1
  45. data/lib/will_filter/extensions/action_view_extension.rb +1 -1
  46. data/lib/will_filter/extensions/active_record_extension.rb +1 -1
  47. data/lib/will_filter/extensions/array_extension.rb +1 -1
  48. data/lib/will_filter/filter_condition.rb +1 -1
  49. data/lib/will_filter/filter_container.rb +21 -3
  50. data/lib/will_filter/filter_exception.rb +1 -1
  51. data/lib/will_filter/railtie.rb +1 -1
  52. data/lib/will_filter/version.rb +2 -2
  53. data/spec/containers/double_spec.rb +16 -0
  54. data/spec/fake_app.rb +6 -12
  55. data/test/dummy/app/models/event.rb +1 -1
  56. data/test/dummy/app/models/event_filter.rb +4 -0
  57. data/test/dummy/app/models/event_user_filter.rb +4 -0
  58. data/test/dummy/app/models/user_filter.rb +31 -2
  59. data/test/dummy/config/will_filter/config.yml +9 -1
  60. data/test/dummy/db/migrate/20120223232000_add_rank_to_events.rb +5 -0
  61. data/test/dummy/db/schema.rb +2 -1
  62. metadata +40 -108
  63. data/config/will_filter/config.yml +0 -97
  64. data/db/migrate/20110924023807_create_will_filter_filters.rb +0 -15
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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 == nil
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) 2011 Michael Berkovich
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 == nil
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 == nil
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} <= ?) ", start_time, end_time] if operator == :is_in_the_range
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) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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} < ? ", start_date_time, end_date_time] if operator == :is_on
53
- return [" #{condition.full_key} < ? and #{condition.full_key} >= ? ", start_date_time, end_date_time] if operator == :is_not_on
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
87
+ s.to_s.match(/\A[-+]?[0-9]*\Z/) == nil ? false : true
70
88
  end
71
89
 
72
90
  end
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
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
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2010-2011 Michael Berkovich
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.3"
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