will_filter 3.0.0

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 (110) hide show
  1. data/.loadpath +12 -0
  2. data/.project +18 -0
  3. data/CHANGELOG.rdoc +1 -0
  4. data/Gemfile +32 -0
  5. data/Gemfile.lock +73 -0
  6. data/LICENSE +18 -0
  7. data/README.rdoc +74 -0
  8. data/Rakefile +54 -0
  9. data/VERSION +1 -0
  10. data/app/controllers/application_controller.rb +27 -0
  11. data/app/controllers/will_filter/calendar_controller.rb +31 -0
  12. data/app/controllers/will_filter/exporter_controller.rb +122 -0
  13. data/app/controllers/will_filter/filter_controller.rb +107 -0
  14. data/app/helpers/application_helper.rb +26 -0
  15. data/app/models/will_filter/filter.rb +694 -0
  16. data/app/views/layouts/application.html.erb +11 -0
  17. data/app/views/will_filter/calendar/_annual.html.erb +14 -0
  18. data/app/views/will_filter/calendar/_month.html.erb +39 -0
  19. data/app/views/will_filter/calendar/_quarter.html.erb +15 -0
  20. data/app/views/will_filter/calendar/index.html.erb +52 -0
  21. data/app/views/will_filter/common/_actions_bar.html.erb +5 -0
  22. data/app/views/will_filter/common/_results_table.html.erb +129 -0
  23. data/app/views/will_filter/common/_scripts.html.erb +10 -0
  24. data/app/views/will_filter/exporter/export.html.erb +11 -0
  25. data/app/views/will_filter/exporter/index.html.erb +47 -0
  26. data/app/views/will_filter/filter/_condition.html.erb +30 -0
  27. data/app/views/will_filter/filter/_conditions.html.erb +56 -0
  28. data/app/views/will_filter/filter/_container.html.erb +31 -0
  29. data/app/views/will_filter/filter/containers/_blank.html.erb +1 -0
  30. data/app/views/will_filter/filter/containers/_boolean.html.erb +5 -0
  31. data/app/views/will_filter/filter/containers/_date.html.erb +12 -0
  32. data/app/views/will_filter/filter/containers/_date_range.html.erb +20 -0
  33. data/app/views/will_filter/filter/containers/_date_time.html.erb +12 -0
  34. data/app/views/will_filter/filter/containers/_date_time_range.html.erb +20 -0
  35. data/app/views/will_filter/filter/containers/_list.html.erb +7 -0
  36. data/app/views/will_filter/filter/containers/_numeric_range.html.erb +13 -0
  37. data/app/views/will_filter/filter/containers/_text.html.erb +7 -0
  38. data/app/views/will_filter/filter/index.html.erb +4 -0
  39. data/config/application.rb +45 -0
  40. data/config/boot.rb +6 -0
  41. data/config/database.yml +22 -0
  42. data/config/environment.rb +13 -0
  43. data/config/environments/development.rb +26 -0
  44. data/config/environments/production.rb +49 -0
  45. data/config/environments/test.rb +38 -0
  46. data/config/routes.rb +64 -0
  47. data/config/will_filter/config.yml +97 -0
  48. data/config.ru +4 -0
  49. data/db/development.sqlite3 +0 -0
  50. data/db/migrate/20090730070119_create_will_filter_tables.rb +19 -0
  51. data/db/seeds.rb +7 -0
  52. data/db/test.sqlite3 +0 -0
  53. data/doc/README_FOR_APP +2 -0
  54. data/examples/README +1 -0
  55. data/lib/application_helper.rb +45 -0
  56. data/lib/core_ext/active_record/base.rb +44 -0
  57. data/lib/core_ext/array.rb +34 -0
  58. data/lib/core_ext/object.rb +34 -0
  59. data/lib/generators/will_filter/templates/config.yml +97 -0
  60. data/lib/generators/will_filter/templates/create_will_filter_tables.rb +19 -0
  61. data/lib/generators/will_filter/will_filter_generator.rb +24 -0
  62. data/lib/tasks/.gitkeep +0 -0
  63. data/lib/tasks/will_filter_tasks.rake +32 -0
  64. data/lib/will_filter/calendar.rb +168 -0
  65. data/lib/will_filter/common_methods.rb +49 -0
  66. data/lib/will_filter/config.rb +104 -0
  67. data/lib/will_filter/containers/boolean.rb +43 -0
  68. data/lib/will_filter/containers/date.rb +51 -0
  69. data/lib/will_filter/containers/date_range.rb +56 -0
  70. data/lib/will_filter/containers/date_time.rb +50 -0
  71. data/lib/will_filter/containers/date_time_range.rb +64 -0
  72. data/lib/will_filter/containers/filter_list.rb +59 -0
  73. data/lib/will_filter/containers/list.rb +56 -0
  74. data/lib/will_filter/containers/nil.rb +45 -0
  75. data/lib/will_filter/containers/numeric.rb +52 -0
  76. data/lib/will_filter/containers/numeric_delimited.rb +50 -0
  77. data/lib/will_filter/containers/numeric_range.rb +60 -0
  78. data/lib/will_filter/containers/single_date.rb +57 -0
  79. data/lib/will_filter/containers/text.rb +45 -0
  80. data/lib/will_filter/containers/text_delimited.rb +51 -0
  81. data/lib/will_filter/engine.rb +11 -0
  82. data/lib/will_filter/filter_condition.rb +59 -0
  83. data/lib/will_filter/filter_container.rb +73 -0
  84. data/lib/will_filter/filter_exception.rb +27 -0
  85. data/lib/will_filter.rb +15 -0
  86. data/pkg/will_filter-0.1.0.gem +0 -0
  87. data/pkg/will_filter-0.1.1.gem +0 -0
  88. data/public/404.html +26 -0
  89. data/public/422.html +26 -0
  90. data/public/500.html +26 -0
  91. data/public/favicon.ico +0 -0
  92. data/public/robots.txt +5 -0
  93. data/public/will_filter/images/buttons.png +0 -0
  94. data/public/will_filter/images/calendar.png +0 -0
  95. data/public/will_filter/images/clock.png +0 -0
  96. data/public/will_filter/images/close.gif +0 -0
  97. data/public/will_filter/images/results_table_th_active.gif +0 -0
  98. data/public/will_filter/images/sort_arrow_all.gif +0 -0
  99. data/public/will_filter/images/sort_bg.gif +0 -0
  100. data/public/will_filter/images/spinner.gif +0 -0
  101. data/public/will_filter/javascripts/will_filter.js +568 -0
  102. data/public/will_filter/javascripts/will_filter_prototype_effects.js +15 -0
  103. data/public/will_filter/stylesheets/will_filter.css +168 -0
  104. data/script/rails +6 -0
  105. data/test/functional/models/will_filter/filter_test.rb +297 -0
  106. data/test/performance/browsing_test.rb +9 -0
  107. data/test/test_helper.rb +71 -0
  108. data/uninstall.rb +24 -0
  109. data/will_filter.gemspec +7 -0
  110. metadata +208 -0
@@ -0,0 +1,32 @@
1
+ #--
2
+ # Copyright (c) 2011 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
+ namespace :will_filter do
25
+
26
+ desc "Sync extra files from will_filter plugin."
27
+ task :sync do
28
+ system "rsync -ruv vendor/plugins/will_filter/config/wf ./config"
29
+ system "rsync -ruv vendor/plugins/will_filter/db/migrate ./db"
30
+ end
31
+
32
+ end
@@ -0,0 +1,168 @@
1
+ #--
2
+ # Copyright (c) 2011 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
+ class Calendar
26
+
27
+ MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
28
+ DAYS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
29
+
30
+ def initialize(selected_date = nil, start_date = nil, show_time = false, mode = 'month')
31
+ if selected_date.blank?
32
+ @selected_date = Time.now
33
+ else
34
+ begin
35
+ @selected_date = Time.parse(selected_date)
36
+ rescue
37
+ @selected_date = Time.now
38
+ end
39
+ end
40
+
41
+ if start_date.is_a?(Date)
42
+ @start_date = start_date
43
+ else
44
+ @start_date = start_date.blank? ? Date.new(@selected_date.year, @selected_date.month, 1) : Date.parse(start_date)
45
+ end
46
+
47
+ @show_time = show_time
48
+ @mode = mode
49
+ end
50
+
51
+ def mode
52
+ @mode ||= 'month'
53
+ end
54
+
55
+ def selected_date
56
+ @selected_date ||= Time.now
57
+ end
58
+
59
+ def month
60
+ start_date.month
61
+ end
62
+
63
+ def year
64
+ start_date.year
65
+ end
66
+
67
+ def hour
68
+ selected_date.hour
69
+ end
70
+
71
+ def minute
72
+ selected_date.min
73
+ end
74
+
75
+ def second
76
+ selected_date.sec
77
+ end
78
+
79
+ def start_date
80
+ @start_date ||= Date.new(Date.today.year, Date.today.month, 1)
81
+ end
82
+
83
+ def end_date
84
+ @end_date ||= Date.new(start_date.year, start_date.month, days_in_month)
85
+ end
86
+
87
+ def days_in_month
88
+ @days_in_month ||= (Date.new(year, 12, 31).to_date<<(12 - month)).day
89
+ end
90
+
91
+ def show_time?
92
+ @show_time
93
+ end
94
+
95
+ def move(delta)
96
+ return self if delta.blank? or delta == 0
97
+ WillFilter::Calendar.new(selected_date, start_date + delta, show_time?, mode)
98
+ end
99
+
100
+ def title
101
+ "#{MONTHS[month-1]}, #{year}"
102
+ end
103
+
104
+ def next_start_date
105
+ return start_date + 1.year if mode == 'annual'
106
+ start_date + 1.month
107
+ end
108
+
109
+ def previous_start_date
110
+ return start_date - 1.year if mode == 'annual'
111
+ start_date - 1.month
112
+ end
113
+
114
+
115
+ def self.year_options
116
+ @year_options ||= begin
117
+ yo = []
118
+ (Date.today.year - 100).upto(Date.today.year + 30) do |year|
119
+ yo << [year, year]
120
+ end
121
+ yo
122
+ end
123
+ end
124
+
125
+ def self.month_options
126
+ @month_options ||= begin
127
+ mo = []
128
+ MONTHS.each_with_index do |m, i|
129
+ mo << [m, i+1]
130
+ end
131
+ mo
132
+ end
133
+ end
134
+
135
+ def self.days
136
+ DAYS
137
+ end
138
+
139
+ def self.hour_options
140
+ @hour_options ||= begin
141
+ ho = []
142
+ 0.upto(23) do |i|
143
+ ho << [prepand_zero(i), i]
144
+ end
145
+ ho
146
+ end
147
+ end
148
+
149
+ def self.minute_options
150
+ @minute_options ||= begin
151
+ mo = []
152
+ 0.upto(59) do |i|
153
+ mo << [prepand_zero(i), i]
154
+ end
155
+ mo
156
+ end
157
+ end
158
+
159
+ def self.second_options
160
+ @second_options ||= minute_options
161
+ end
162
+
163
+ def self.prepand_zero(num)
164
+ (num < 10 ? "0#{num}" : "#{num}")
165
+ end
166
+
167
+ end
168
+ end
@@ -0,0 +1,49 @@
1
+ #--
2
+ # Copyright (c) 2011 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 CommonMethods
26
+
27
+ def self.included(base)
28
+ if 'ApplicationController' == base.name
29
+ base.append_before_filter :init_will_filter
30
+ end
31
+ end
32
+
33
+ def init_will_filter
34
+ # only if the filters need to be
35
+ return unless WillFilter::Config.user_filters_enabled?
36
+
37
+ wf_current_user = nil
38
+ begin
39
+ wf_current_user = eval(WillFilter::Config.current_user_method)
40
+ rescue Exception => ex
41
+ raise WillFilter::Exception.new("will_filter cannot be initialized because #{WillFilter::Config.current_user_method} failed with: #{ex.message}")
42
+ end
43
+
44
+ WillFilter::Config.init(wf_current_user)
45
+ end
46
+
47
+ end
48
+ end
49
+
@@ -0,0 +1,104 @@
1
+ #--
2
+ # Copyright (c) 2011 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
+ class Config
26
+
27
+ def self.init(site_current_user)
28
+ Thread.current[:current_user] = site_current_user
29
+ end
30
+
31
+ def self.current_user
32
+ Thread.current[:current_user]
33
+ end
34
+
35
+ def self.reset!
36
+ Thread.current[:current_user] = nil
37
+ end
38
+
39
+ def self.load_yml(file_path)
40
+ yml = YAML.load_file("#{Rails.root}#{file_path}")[Rails.env]
41
+ HashWithIndifferentAccess.new(yml)
42
+ end
43
+
44
+ def self.config
45
+ @config ||= load_yml("/config/will_filter/config.yml")
46
+ end
47
+
48
+ def self.effects_options
49
+ config[:effects_options]
50
+ end
51
+
52
+ def self.save_options
53
+ config[:save_options]
54
+ end
55
+
56
+ def self.export_options
57
+ config[:export_options]
58
+ end
59
+
60
+ def self.containers
61
+ config[:containers]
62
+ end
63
+
64
+ def self.data_types
65
+ config[:data_types]
66
+ end
67
+
68
+ def self.operators
69
+ config[:operators]
70
+ end
71
+
72
+ def self.operator_order
73
+ @operator_order ||= begin
74
+ keys = operators.keys
75
+ keys.sort! { |a,b| operators[a] <=> operators[b] }
76
+ keys
77
+ end
78
+ end
79
+
80
+ def self.saving_enabled?
81
+ save_options[:enabled]
82
+ end
83
+
84
+ def self.user_filters_enabled?
85
+ save_options[:user_filters_enabled]
86
+ end
87
+
88
+ def self.user_class_name
89
+ save_options[:user_class_name]
90
+ end
91
+
92
+ def self.current_user_method
93
+ save_options[:current_user_method]
94
+ end
95
+
96
+ def self.exporting_enabled?
97
+ export_options[:enabled]
98
+ end
99
+
100
+ def self.default_export_formats
101
+ export_options[:default_formats]
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,43 @@
1
+ #--
2
+ # Copyright (c) 2011 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 Boolean < WillFilter::FilterContainer
27
+
28
+ def self.operators
29
+ [:is]
30
+ end
31
+
32
+ def selected?
33
+ value == "1"
34
+ end
35
+
36
+ def sql_condition
37
+ return [" #{condition.full_key} = ? ", (selected? ? true : false)] if operator == :is
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,51 @@
1
+ #--
2
+ # Copyright (c) 2011 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 Date < WillFilter::FilterContainer
27
+ def self.operators
28
+ [:is, :is_not, :is_after, :is_before]
29
+ end
30
+
31
+ def validate
32
+ return "Value must be provided" if value.blank?
33
+ return "Value must be a valid date (2008-01-01)" if date == nil
34
+ end
35
+
36
+ def date
37
+ @date ||= Time.parse(value).to_date
38
+ rescue ArgumentError
39
+ nil
40
+ end
41
+
42
+ def sql_condition
43
+ return [" #{condition.full_key} = ? ", date] if operator == :is
44
+ return [" #{condition.full_key} <> ? ", date] if operator == :is_not
45
+ return [" #{condition.full_key} > ? ", date] if operator == :is_after
46
+ return [" #{condition.full_key} < ? ", date] if operator == :is_before
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,56 @@
1
+ #--
2
+ # Copyright (c) 2011 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 DateRange < WillFilter::FilterContainer
27
+ def self.operators
28
+ [:is_in_the_range]
29
+ end
30
+
31
+ def initialize(filter, criteria_key, operator, values)
32
+ super(filter, criteria_key, operator, values)
33
+ @start_date = values[0]
34
+ @end_date = values[1] if values.size > 1
35
+ end
36
+
37
+ def validate
38
+ return "Start value must be provided" if @start_date.blank?
39
+ return "Start value must be a valid date (2008-01-01)" if date(@start_date) == nil
40
+ return "End value must be provided" if @end_date.blank?
41
+ return "End value must be a valid date (2008-01-01)" if date(@end_date) == nil
42
+ end
43
+
44
+ def date(dt)
45
+ Time.parse(dt).to_date
46
+ rescue ArgumentError
47
+ nil
48
+ end
49
+
50
+ def sql_condition
51
+ return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", date(@start_date), date(@end_date)] if operator == :is_in_the_range
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,50 @@
1
+ #--
2
+ # Copyright (c) 2011 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 DateTime < WillFilter::FilterContainer
27
+ def self.operators
28
+ [:is, :is_not, :is_after, :is_before]
29
+ end
30
+
31
+ def validate
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
40
+ end
41
+
42
+ def sql_condition
43
+ return [" #{condition.full_key} = ? ", time] if operator == :is
44
+ return [" #{condition.full_key} <> ? ", time] if operator == :is_not
45
+ return [" #{condition.full_key} > ? ", time] if operator == :is_after
46
+ return [" #{condition.full_key} < ? ", time] if operator == :is_before
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,64 @@
1
+ #--
2
+ # Copyright (c) 2011 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 DateTimeRange < 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 valid date/time (2008-01-01 14:30:00)" if start_time == nil
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
57
+ end
58
+
59
+ def sql_condition
60
+ return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", start_time, end_time] if operator == :is_in_the_range
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,59 @@
1
+ #--
2
+ # Copyright (c) 2011 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 FilterList < WillFilter::FilterContainer
27
+ def self.operators
28
+ [:is_filtered_by]
29
+ end
30
+
31
+ def validate
32
+ return "Value must be provided" if value.blank?
33
+ end
34
+
35
+ def template_name
36
+ 'list'
37
+ end
38
+
39
+ def options
40
+ if condition.key == :id
41
+ model_class_name = filter.model_class_name
42
+ else
43
+ model_class_name = condition.key.to_s[0..-4].camelcase
44
+ end
45
+
46
+ Wf::Filter.new(model_class_name).saved_filters(false)
47
+ end
48
+
49
+ def sql_condition
50
+ return nil unless operator == :is_filtered_by
51
+ sub_filter = Wf::Filter.find_by_id(value)
52
+ sub_conds = sub_filter.sql_conditions
53
+ sub_sql = "SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name} WHERE #{sub_conds[0]}"
54
+ sub_conds[0] = " #{condition.full_key} IN (#{sub_sql}) "
55
+ sub_conds
56
+ end
57
+ end
58
+ end
59
+ end