will_filter 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.loadpath +12 -0
- data/.project +18 -0
- data/CHANGELOG.rdoc +1 -0
- data/Gemfile +32 -0
- data/Gemfile.lock +73 -0
- data/LICENSE +18 -0
- data/README.rdoc +74 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/app/controllers/application_controller.rb +27 -0
- data/app/controllers/will_filter/calendar_controller.rb +31 -0
- data/app/controllers/will_filter/exporter_controller.rb +122 -0
- data/app/controllers/will_filter/filter_controller.rb +107 -0
- data/app/helpers/application_helper.rb +26 -0
- data/app/models/will_filter/filter.rb +694 -0
- data/app/views/layouts/application.html.erb +11 -0
- data/app/views/will_filter/calendar/_annual.html.erb +14 -0
- data/app/views/will_filter/calendar/_month.html.erb +39 -0
- data/app/views/will_filter/calendar/_quarter.html.erb +15 -0
- data/app/views/will_filter/calendar/index.html.erb +52 -0
- data/app/views/will_filter/common/_actions_bar.html.erb +5 -0
- data/app/views/will_filter/common/_results_table.html.erb +129 -0
- data/app/views/will_filter/common/_scripts.html.erb +10 -0
- data/app/views/will_filter/exporter/export.html.erb +11 -0
- data/app/views/will_filter/exporter/index.html.erb +47 -0
- data/app/views/will_filter/filter/_condition.html.erb +30 -0
- data/app/views/will_filter/filter/_conditions.html.erb +56 -0
- data/app/views/will_filter/filter/_container.html.erb +31 -0
- data/app/views/will_filter/filter/containers/_blank.html.erb +1 -0
- data/app/views/will_filter/filter/containers/_boolean.html.erb +5 -0
- data/app/views/will_filter/filter/containers/_date.html.erb +12 -0
- data/app/views/will_filter/filter/containers/_date_range.html.erb +20 -0
- data/app/views/will_filter/filter/containers/_date_time.html.erb +12 -0
- data/app/views/will_filter/filter/containers/_date_time_range.html.erb +20 -0
- data/app/views/will_filter/filter/containers/_list.html.erb +7 -0
- data/app/views/will_filter/filter/containers/_numeric_range.html.erb +13 -0
- data/app/views/will_filter/filter/containers/_text.html.erb +7 -0
- data/app/views/will_filter/filter/index.html.erb +4 -0
- data/config/application.rb +45 -0
- data/config/boot.rb +6 -0
- data/config/database.yml +22 -0
- data/config/environment.rb +13 -0
- data/config/environments/development.rb +26 -0
- data/config/environments/production.rb +49 -0
- data/config/environments/test.rb +38 -0
- data/config/routes.rb +64 -0
- data/config/will_filter/config.yml +97 -0
- data/config.ru +4 -0
- data/db/development.sqlite3 +0 -0
- data/db/migrate/20090730070119_create_will_filter_tables.rb +19 -0
- data/db/seeds.rb +7 -0
- data/db/test.sqlite3 +0 -0
- data/doc/README_FOR_APP +2 -0
- data/examples/README +1 -0
- data/lib/application_helper.rb +45 -0
- data/lib/core_ext/active_record/base.rb +44 -0
- data/lib/core_ext/array.rb +34 -0
- data/lib/core_ext/object.rb +34 -0
- data/lib/generators/will_filter/templates/config.yml +97 -0
- data/lib/generators/will_filter/templates/create_will_filter_tables.rb +19 -0
- data/lib/generators/will_filter/will_filter_generator.rb +24 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/will_filter_tasks.rake +32 -0
- data/lib/will_filter/calendar.rb +168 -0
- data/lib/will_filter/common_methods.rb +49 -0
- data/lib/will_filter/config.rb +104 -0
- data/lib/will_filter/containers/boolean.rb +43 -0
- data/lib/will_filter/containers/date.rb +51 -0
- data/lib/will_filter/containers/date_range.rb +56 -0
- data/lib/will_filter/containers/date_time.rb +50 -0
- data/lib/will_filter/containers/date_time_range.rb +64 -0
- data/lib/will_filter/containers/filter_list.rb +59 -0
- data/lib/will_filter/containers/list.rb +56 -0
- data/lib/will_filter/containers/nil.rb +45 -0
- data/lib/will_filter/containers/numeric.rb +52 -0
- data/lib/will_filter/containers/numeric_delimited.rb +50 -0
- data/lib/will_filter/containers/numeric_range.rb +60 -0
- data/lib/will_filter/containers/single_date.rb +57 -0
- data/lib/will_filter/containers/text.rb +45 -0
- data/lib/will_filter/containers/text_delimited.rb +51 -0
- data/lib/will_filter/engine.rb +11 -0
- data/lib/will_filter/filter_condition.rb +59 -0
- data/lib/will_filter/filter_container.rb +73 -0
- data/lib/will_filter/filter_exception.rb +27 -0
- data/lib/will_filter.rb +15 -0
- data/pkg/will_filter-0.1.0.gem +0 -0
- data/pkg/will_filter-0.1.1.gem +0 -0
- data/public/404.html +26 -0
- data/public/422.html +26 -0
- data/public/500.html +26 -0
- data/public/favicon.ico +0 -0
- data/public/robots.txt +5 -0
- data/public/will_filter/images/buttons.png +0 -0
- data/public/will_filter/images/calendar.png +0 -0
- data/public/will_filter/images/clock.png +0 -0
- data/public/will_filter/images/close.gif +0 -0
- data/public/will_filter/images/results_table_th_active.gif +0 -0
- data/public/will_filter/images/sort_arrow_all.gif +0 -0
- data/public/will_filter/images/sort_bg.gif +0 -0
- data/public/will_filter/images/spinner.gif +0 -0
- data/public/will_filter/javascripts/will_filter.js +568 -0
- data/public/will_filter/javascripts/will_filter_prototype_effects.js +15 -0
- data/public/will_filter/stylesheets/will_filter.css +168 -0
- data/script/rails +6 -0
- data/test/functional/models/will_filter/filter_test.rb +297 -0
- data/test/performance/browsing_test.rb +9 -0
- data/test/test_helper.rb +71 -0
- data/uninstall.rb +24 -0
- data/will_filter.gemspec +7 -0
- metadata +208 -0
@@ -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 List < WillFilter::FilterContainer
|
27
|
+
def self.operators
|
28
|
+
[:is, :is_not, :contains, :does_not_contain]
|
29
|
+
end
|
30
|
+
|
31
|
+
def options
|
32
|
+
opts = []
|
33
|
+
filter.value_options_for(condition.key).each do |item|
|
34
|
+
if item.is_a?(Array)
|
35
|
+
opt_name = item.first.to_s
|
36
|
+
opt_value = item.last.to_s
|
37
|
+
else
|
38
|
+
opt_name = item.to_s
|
39
|
+
opt_value = item.to_s
|
40
|
+
end
|
41
|
+
next if opt_name.strip == ""
|
42
|
+
opts << [ERB::Util.html_escape(opt_name), ERB::Util.html_escape(opt_value)]
|
43
|
+
end
|
44
|
+
opts
|
45
|
+
end
|
46
|
+
|
47
|
+
def sql_condition
|
48
|
+
return [" #{condition.full_key} = ? ", value] if operator == :is
|
49
|
+
return [" #{condition.full_key} <> ? ", value] if operator == :is_not
|
50
|
+
return [" #{condition.full_key} like ? ", "%#{value}%"] if operator == :contains
|
51
|
+
return [" #{condition.full_key} not like ? ", "%#{value}%"] if operator == :does_not_cotain
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 Nil < WillFilter::FilterContainer
|
27
|
+
def self.operators
|
28
|
+
[:is_provided, :is_not_provided]
|
29
|
+
end
|
30
|
+
|
31
|
+
def template_name
|
32
|
+
'blank'
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate
|
36
|
+
# no validation is necessary
|
37
|
+
end
|
38
|
+
|
39
|
+
def sql_condition
|
40
|
+
return [" #{condition.full_key} is not null "] if operator == :is_provided
|
41
|
+
return [" #{condition.full_key} is null "] if operator == :is_not_provided
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,52 @@
|
|
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 Numeric < 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_i
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate
|
40
|
+
return "Value must be provided" if value.blank?
|
41
|
+
return "Value must be numeric" unless is_numeric?(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) 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 NumericDelimited < WillFilter::FilterContainer
|
27
|
+
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_i}
|
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,60 @@
|
|
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 NumericRange < 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 numeric" unless is_numeric?(start_value)
|
43
|
+
return "End value must be provided" if end_value.blank?
|
44
|
+
return "End value must be numeric" unless is_numeric?(end_value)
|
45
|
+
end
|
46
|
+
|
47
|
+
def numeric_start_value
|
48
|
+
start_value.to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
def numeric_end_value
|
52
|
+
end_value.to_i
|
53
|
+
end
|
54
|
+
|
55
|
+
def sql_condition
|
56
|
+
return [" (#{condition.full_key} >= ? and #{condition.full_key} <= ?) ", numeric_start_value, numeric_end_value] if operator == :is_in_the_range
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,57 @@
|
|
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
|
+
module WillFilter
|
24
|
+
module Containers
|
25
|
+
class SingleDate < WillFilter::FilterContainer
|
26
|
+
def self.operators
|
27
|
+
[:is_on, :is_not_on]
|
28
|
+
end
|
29
|
+
|
30
|
+
def template_name
|
31
|
+
'date'
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate
|
35
|
+
return "Value must be provided" if value.blank?
|
36
|
+
return "Value must be a valid date (2008-01-01)" if start_date_time == nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def start_date_time
|
40
|
+
@start_date_time ||= Time.parse(value)
|
41
|
+
rescue ArgumentError
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def end_date_time
|
46
|
+
(start_date_time + 1.day)
|
47
|
+
rescue ArgumentError
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
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
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 Text < WillFilter::FilterContainer
|
27
|
+
def self.operators
|
28
|
+
[:is, :is_not, :contains, :does_not_contain, :starts_with, :ends_with]
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate
|
32
|
+
# always valid, even when it is empty
|
33
|
+
end
|
34
|
+
|
35
|
+
def sql_condition
|
36
|
+
return [" #{condition.full_key} = ? ", value] if operator == :is
|
37
|
+
return [" #{condition.full_key} <> ? ", value] if operator == :is_not
|
38
|
+
return [" #{condition.full_key} like ? ", "%#{value}%"] if operator == :contains
|
39
|
+
return [" #{condition.full_key} not like ? ", "%#{value}%"] if operator == :does_not_contain
|
40
|
+
return [" #{condition.full_key} like ? ", "#{value}%"] if operator == :starts_with
|
41
|
+
return [" #{condition.full_key} like ? ", "%#{value}"] if operator == :ends_with
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -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 TextDelimited < WillFilter::FilterContainer
|
27
|
+
TEXT_DELIMITER = ","
|
28
|
+
|
29
|
+
def self.operators
|
30
|
+
[:is_in, :is_not_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 '#{TEXT_DELIMITER}'" if value.blank?
|
39
|
+
end
|
40
|
+
|
41
|
+
def split_values
|
42
|
+
value.split(TEXT_DELIMITER)
|
43
|
+
end
|
44
|
+
|
45
|
+
def sql_condition
|
46
|
+
return [" #{condition.full_key} in (?) ", split_values] if operator == :is_in
|
47
|
+
return [" #{condition.full_key} not in (?) ", split_values] if operator == :is_not_in
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "will_filter" # Require all the real code
|
2
|
+
require "rails"
|
3
|
+
|
4
|
+
module WillFilter
|
5
|
+
class Engine < Rails::Engine
|
6
|
+
initializer "static assets" do |app|
|
7
|
+
# app.middleware.use ActionDispatch::Static, "#{root}/public" # Old way, does not work in production
|
8
|
+
app.middleware.insert_after ActionDispatch::Static, ActionDispatch::Static, "#{root}/public"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
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
|
+
class FilterCondition
|
26
|
+
attr_accessor :filter, :key, :operator, :container
|
27
|
+
|
28
|
+
def initialize(filter, key, operator, container_class, values)
|
29
|
+
@filter = filter
|
30
|
+
@key = key
|
31
|
+
@operator = operator
|
32
|
+
@container = WillFilter::Config.containers[container_class].constantize.new(filter, self, operator, values)
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate
|
36
|
+
container.validate
|
37
|
+
end
|
38
|
+
|
39
|
+
def serialize_to_params(params, index)
|
40
|
+
params["wf_c#{index}"] = key
|
41
|
+
params["wf_o#{index}"] = operator
|
42
|
+
container.serialize_to_params(params, index)
|
43
|
+
params
|
44
|
+
end
|
45
|
+
|
46
|
+
def full_key
|
47
|
+
if key.to_s.index('.')
|
48
|
+
parts = key.to_s.split(".")
|
49
|
+
join_class = parts.first.camelcase.constantize
|
50
|
+
return "#{join_class.table_name}.#{parts.last}"
|
51
|
+
end
|
52
|
+
"#{filter.table_name}.#{key}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_s
|
56
|
+
key
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,73 @@
|
|
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 FilterContainer
|
26
|
+
attr_accessor :filter, :condition, :operator, :values, :index
|
27
|
+
|
28
|
+
def initialize(filter, condition, operator, values)
|
29
|
+
@filter = filter
|
30
|
+
@condition = condition
|
31
|
+
@operator = operator
|
32
|
+
@values = values
|
33
|
+
end
|
34
|
+
|
35
|
+
def value
|
36
|
+
values.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def sanitized_value(index = 0)
|
40
|
+
return '' if index >= values.size
|
41
|
+
return '' if values[index].blank?
|
42
|
+
values[index].to_s.gsub("'", "'")
|
43
|
+
end
|
44
|
+
|
45
|
+
# used by the list based containers
|
46
|
+
def options
|
47
|
+
[]
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate
|
51
|
+
return "Value must be provided" if value.blank?
|
52
|
+
end
|
53
|
+
|
54
|
+
def reset_values
|
55
|
+
@values = []
|
56
|
+
end
|
57
|
+
|
58
|
+
def template_name
|
59
|
+
self.class.name.underscore.split('/').last
|
60
|
+
end
|
61
|
+
|
62
|
+
def serialize_to_params(params, index)
|
63
|
+
values.each_with_index do |v, v_index|
|
64
|
+
params["wf_v#{index}_#{v_index}"] = v
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def is_numeric?(s)
|
69
|
+
s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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 FilterException < Exception
|
26
|
+
end
|
27
|
+
end
|
data/lib/will_filter.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module WillFilter
|
2
|
+
[
|
3
|
+
"core_ext/**",
|
4
|
+
"will_filter",
|
5
|
+
"will_filter/containers",
|
6
|
+
"../app/models/will_filter"
|
7
|
+
].each do |dir|
|
8
|
+
Dir[File.expand_path("#{File.dirname(__FILE__)}/#{dir}/*.rb")].sort.each do |file|
|
9
|
+
require(file)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'application_helper'
|
14
|
+
|
15
|
+
end
|
Binary file
|
Binary file
|
data/public/404.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
data/public/422.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|