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,13 @@
|
|
1
|
+
# Load the rails application
|
2
|
+
require File.expand_path('../application', __FILE__)
|
3
|
+
|
4
|
+
["../lib/core_ext/**",
|
5
|
+
"../lib/will_filter",
|
6
|
+
"../lib/will_filter/containers"].each do |dir|
|
7
|
+
Dir[File.expand_path("#{File.dirname(__FILE__)}/#{dir}/*.rb")].sort.each do |file|
|
8
|
+
require file
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Initialize the rails application
|
13
|
+
WillFilter::Application.initialize!
|
@@ -0,0 +1,26 @@
|
|
1
|
+
WillFilter::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
|
20
|
+
# Print deprecation notices to the Rails logger
|
21
|
+
config.active_support.deprecation = :log
|
22
|
+
|
23
|
+
# Only use best-standards-support built into browsers
|
24
|
+
config.action_dispatch.best_standards_support = :builtin
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
WillFilter::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The production environment is meant for finished, "live" apps.
|
5
|
+
# Code is not reloaded between requests
|
6
|
+
config.cache_classes = true
|
7
|
+
|
8
|
+
# Full error reports are disabled and caching is turned on
|
9
|
+
config.consider_all_requests_local = false
|
10
|
+
config.action_controller.perform_caching = true
|
11
|
+
|
12
|
+
# Specifies the header that your server uses for sending files
|
13
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
14
|
+
|
15
|
+
# For nginx:
|
16
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
|
17
|
+
|
18
|
+
# If you have no front-end server that supports something like X-Sendfile,
|
19
|
+
# just comment this out and Rails will serve the files
|
20
|
+
|
21
|
+
# See everything in the log (default is :info)
|
22
|
+
# config.log_level = :debug
|
23
|
+
|
24
|
+
# Use a different logger for distributed setups
|
25
|
+
# config.logger = SyslogLogger.new
|
26
|
+
|
27
|
+
# Use a different cache store in production
|
28
|
+
# config.cache_store = :mem_cache_store
|
29
|
+
|
30
|
+
# Disable Rails's static asset server
|
31
|
+
# In production, Apache or nginx will already do this
|
32
|
+
config.serve_static_assets = false
|
33
|
+
|
34
|
+
# Enable serving of images, stylesheets, and javascripts from an asset server
|
35
|
+
# config.action_controller.asset_host = "http://assets.example.com"
|
36
|
+
|
37
|
+
# Disable delivery errors, bad email addresses will be ignored
|
38
|
+
# config.action_mailer.raise_delivery_errors = false
|
39
|
+
|
40
|
+
# Enable threaded mode
|
41
|
+
# config.threadsafe!
|
42
|
+
|
43
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
44
|
+
# the I18n.default_locale when a translation can not be found)
|
45
|
+
config.i18n.fallbacks = true
|
46
|
+
|
47
|
+
# Send deprecation notices to registered listeners
|
48
|
+
config.active_support.deprecation = :notify
|
49
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
WillFilter::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Raise exceptions instead of rendering exception templates
|
18
|
+
config.action_dispatch.show_exceptions = false
|
19
|
+
|
20
|
+
# Disable request forgery protection in test environment
|
21
|
+
config.action_controller.allow_forgery_protection = false
|
22
|
+
|
23
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
24
|
+
# The :test delivery method accumulates sent emails in the
|
25
|
+
# ActionMailer::Base.deliveries array.
|
26
|
+
config.action_mailer.delivery_method = :test
|
27
|
+
|
28
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
29
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
30
|
+
# like if you have constraints or database-specific column types
|
31
|
+
# config.active_record.schema_format = :sql
|
32
|
+
|
33
|
+
# Print deprecation notices to the stderr
|
34
|
+
config.active_support.deprecation = :stderr
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
# The priority is based upon order of creation:
|
3
|
+
# first created -> highest priority.
|
4
|
+
|
5
|
+
# Sample of regular route:
|
6
|
+
# match 'products/:id' => 'catalog#view'
|
7
|
+
# Keep in mind you can assign values other than :controller and :action
|
8
|
+
|
9
|
+
# Sample of named route:
|
10
|
+
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
11
|
+
# This route can be invoked with purchase_url(:id => product.id)
|
12
|
+
|
13
|
+
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
14
|
+
# resources :products
|
15
|
+
|
16
|
+
# Sample resource route with options:
|
17
|
+
# resources :products do
|
18
|
+
# member do
|
19
|
+
# get 'short'
|
20
|
+
# post 'toggle'
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# collection do
|
24
|
+
# get 'sold'
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
# Sample resource route with sub-resources:
|
29
|
+
# resources :products do
|
30
|
+
# resources :comments, :sales
|
31
|
+
# resource :seller
|
32
|
+
# end
|
33
|
+
|
34
|
+
# Sample resource route with more complex sub-resources
|
35
|
+
# resources :products do
|
36
|
+
# resources :comments
|
37
|
+
# resources :sales do
|
38
|
+
# get 'recent', :on => :collection
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Sample resource route within a namespace:
|
43
|
+
# namespace :admin do
|
44
|
+
# # Directs /admin/products/* to Admin::ProductsController
|
45
|
+
# # (app/controllers/admin/products_controller.rb)
|
46
|
+
# resources :products
|
47
|
+
# end
|
48
|
+
|
49
|
+
# You can have the root of your site routed with "root"
|
50
|
+
# just remember to delete public/index.html.
|
51
|
+
root :to => "will_filter/filter#index"
|
52
|
+
|
53
|
+
# mount_at = WillFilter::Engine.config.mount_at
|
54
|
+
# match mount_at => 'will_filter/filter#index'
|
55
|
+
# map.resources :filter, :controller => "will_filter/filter", :path_prefix => mount_at, :name_prefix => "will_filter_"
|
56
|
+
|
57
|
+
# See how all your routes lay out with "rake routes"
|
58
|
+
|
59
|
+
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
60
|
+
# Note: This route will make all actions in every controller accessible via GET requests.
|
61
|
+
match ':controller(/:action(/:id(.:format)))'
|
62
|
+
match ':controller(/:action(/:id))', :controller => /will_filter\/[^\/]+/
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# will_filter configuration
|
3
|
+
#
|
4
|
+
# Default settings for all environments
|
5
|
+
#
|
6
|
+
# You can overload any feature for any environment by changing the
|
7
|
+
# environment settings at the bottom of the file.
|
8
|
+
#
|
9
|
+
# Alternatively, you can overload any of the methods of WillFilter::Config
|
10
|
+
#############################################################################
|
11
|
+
|
12
|
+
defaults: &defaults
|
13
|
+
effects_options:
|
14
|
+
enabled: false
|
15
|
+
script_path: "/will_filter/javascripts/will_filter_prototype_effects.js"
|
16
|
+
|
17
|
+
save_options:
|
18
|
+
enabled: true
|
19
|
+
user_filters_enabled: false # if set to true, the filters will be private
|
20
|
+
user_class_name: User
|
21
|
+
current_user_method: current_user
|
22
|
+
|
23
|
+
export_options:
|
24
|
+
enabled: true
|
25
|
+
default_formats: [html, csv, xml, json]
|
26
|
+
|
27
|
+
containers: # container implementation mapping
|
28
|
+
nil: WillFilter::Containers::Nil
|
29
|
+
numeric: WillFilter::Containers::Numeric
|
30
|
+
numeric_range: WillFilter::Containers::NumericRange
|
31
|
+
numeric_delimited: WillFilter::Containers::NumericDelimited
|
32
|
+
date_time_range: WillFilter::Containers::DateTimeRange
|
33
|
+
single_date: WillFilter::Containers::SingleDate
|
34
|
+
date: WillFilter::Containers::Date
|
35
|
+
date_time: WillFilter::Containers::DateTime
|
36
|
+
date_range: WillFilter::Containers::DateRange
|
37
|
+
text: WillFilter::Containers::Text
|
38
|
+
text_delimited: WillFilter::Containers::TextDelimited
|
39
|
+
boolean: WillFilter::Containers::Boolean
|
40
|
+
list: WillFilter::Containers::List
|
41
|
+
filter_list: WillFilter::Containers::FilterList
|
42
|
+
|
43
|
+
data_types: # mapping between data types and containers
|
44
|
+
bigint: [nil, numeric, numeric_range, numeric_delimited]
|
45
|
+
numeric: [nil, numeric, numeric_range, numeric_delimited]
|
46
|
+
smallint: [nil, numeric, numeric_range, numeric_delimited]
|
47
|
+
integer: [nil, numeric, numeric_range, numeric_delimited]
|
48
|
+
int: [nil, numeric, numeric_range, numeric_delimited]
|
49
|
+
double: [nil, numeric, numeric_range, numeric_delimited]
|
50
|
+
timestamp: [nil, date_time, date_time_range, single_date]
|
51
|
+
datetime: [nil, date_time, date_time_range, single_date]
|
52
|
+
date: [nil, date, date_range]
|
53
|
+
character: [nil, text, text_delimited]
|
54
|
+
varchar: [nil, text, text_delimited]
|
55
|
+
text: [nil, text, text_delimited]
|
56
|
+
text[]: [nil, text, text_delimited]
|
57
|
+
bytea: [nil, text, text_delimited]
|
58
|
+
boolean: [nil, boolean]
|
59
|
+
tinyint: [nil, boolean]
|
60
|
+
|
61
|
+
operators: # operators precedence
|
62
|
+
is: 100
|
63
|
+
is_not: 200
|
64
|
+
is_on: 300
|
65
|
+
is_in: 400
|
66
|
+
is_provided: 500
|
67
|
+
is_not_provided: 600
|
68
|
+
is_after: 700
|
69
|
+
is_before: 800
|
70
|
+
is_in_the_range: 900
|
71
|
+
contains: 1000
|
72
|
+
does_not_contain: 1100
|
73
|
+
starts_with: 1200
|
74
|
+
ends_with: 1300
|
75
|
+
is_greater_than: 1400
|
76
|
+
is_less_than: 1500
|
77
|
+
is_filtered_by: 1600
|
78
|
+
|
79
|
+
|
80
|
+
#############################################################################
|
81
|
+
# Environment Settings
|
82
|
+
# You can overload any feature defined in the defaults for any environment
|
83
|
+
#############################################################################
|
84
|
+
development:
|
85
|
+
<<: *defaults
|
86
|
+
|
87
|
+
test:
|
88
|
+
<<: *defaults
|
89
|
+
|
90
|
+
qa:
|
91
|
+
<<: *defaults
|
92
|
+
|
93
|
+
stage:
|
94
|
+
<<: *defaults
|
95
|
+
|
96
|
+
production:
|
97
|
+
<<: *defaults
|
data/config.ru
ADDED
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateWillFilterTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :wf_filters do |t|
|
4
|
+
t.string :type
|
5
|
+
t.string :name
|
6
|
+
t.text :data
|
7
|
+
t.integer :user_id
|
8
|
+
t.string :model_class_name
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :wf_filters, [:user_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :wf_filters
|
18
|
+
end
|
19
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This file should contain all the record creation needed to seed the database with its default values.
|
2
|
+
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
3
|
+
#
|
4
|
+
# Examples:
|
5
|
+
#
|
6
|
+
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
7
|
+
# Mayor.create(:name => 'Daley', :city => cities.first)
|
data/db/test.sqlite3
ADDED
Binary file
|
data/doc/README_FOR_APP
ADDED
data/examples/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Please install will_filter_examples project to see how to configure the model_filters.
|
@@ -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 ApplicationHelper
|
25
|
+
def will_filter(results)
|
26
|
+
render(:partial => "/will_filter/filter/container", :locals => {:wf_filter => results.wf_filter})
|
27
|
+
end
|
28
|
+
|
29
|
+
def will_filter_scripts_tag
|
30
|
+
render(:partial => "/will_filter/common/scripts")
|
31
|
+
end
|
32
|
+
|
33
|
+
def will_filter_table_tag(results, opts = {})
|
34
|
+
filter = results.wf_filter
|
35
|
+
opts[:columns] ||= filter.model_column_keys
|
36
|
+
render(:partial => "/will_filter/common/results_table", :locals => {:results => results, :filter => filter, :opts => opts})
|
37
|
+
end
|
38
|
+
|
39
|
+
def will_filter_actions_bar_tag(results, actions, opts = {})
|
40
|
+
filter = results.wf_filter
|
41
|
+
opts[:class] ||= "wf_actions_bar_blue"
|
42
|
+
opts[:style] ||= ""
|
43
|
+
render(:partial => "/will_filter/common/actions_bar", :locals => {:results => results, :filter => filter, :actions => actions, :opts => opts})
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,44 @@
|
|
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
|
+
class ActiveRecord::Base
|
25
|
+
def self.filter(opts = {})
|
26
|
+
if ActiveRecord::Base == self.class
|
27
|
+
raise WillFilter::FilterException.new("Cannot apply filter to the ActiveRecord::Base object")
|
28
|
+
end
|
29
|
+
|
30
|
+
params = opts[:params] || {}
|
31
|
+
|
32
|
+
if opts[:filter]
|
33
|
+
case opts[:filter].class.name
|
34
|
+
when "String" then filter_class = opts[:filter].constantize
|
35
|
+
when "Symbol" then filter_class = opts[:filter].to_s.camelcase.constantize
|
36
|
+
else filter_class = opts[:filter]
|
37
|
+
end
|
38
|
+
else
|
39
|
+
filter_class = WillFilter::Filter
|
40
|
+
end
|
41
|
+
|
42
|
+
filter_class.new(self).deserialize_from_params(params).results
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
class Array
|
25
|
+
|
26
|
+
def wf_filter=(filter)
|
27
|
+
@wf_filter = filter
|
28
|
+
end
|
29
|
+
|
30
|
+
def wf_filter
|
31
|
+
@wf_filter
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
class Object
|
25
|
+
|
26
|
+
def wf_filter=(filter)
|
27
|
+
@wf_filter = filter
|
28
|
+
end
|
29
|
+
|
30
|
+
def wf_filter
|
31
|
+
@wf_filter
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#############################################################################
|
2
|
+
# will_filter configuration
|
3
|
+
#
|
4
|
+
# Default settings for all environments
|
5
|
+
#
|
6
|
+
# You can overload any feature for any environment by changing the
|
7
|
+
# environment settings at the bottom of the file.
|
8
|
+
#
|
9
|
+
# Alternatively, you can overload any of the methods of WillFilter::Config
|
10
|
+
#############################################################################
|
11
|
+
|
12
|
+
defaults: &defaults
|
13
|
+
effects_options:
|
14
|
+
enabled: false
|
15
|
+
script_path: "/will_filter/javascripts/will_filter_prototype_effects.js"
|
16
|
+
|
17
|
+
save_options:
|
18
|
+
enabled: true
|
19
|
+
user_filters_enabled: false # if set to true, the filters will be private
|
20
|
+
user_class_name: User
|
21
|
+
current_user_method: current_user
|
22
|
+
|
23
|
+
export_options:
|
24
|
+
enabled: true
|
25
|
+
default_formats: [html, csv, xml, json]
|
26
|
+
|
27
|
+
containers: # container implementation mapping
|
28
|
+
nil: WillFilter::Containers::Nil
|
29
|
+
numeric: WillFilter::Containers::Numeric
|
30
|
+
numeric_range: WillFilter::Containers::NumericRange
|
31
|
+
numeric_delimited: WillFilter::Containers::NumericDelimited
|
32
|
+
date_time_range: WillFilter::Containers::DateTimeRange
|
33
|
+
single_date: WillFilter::Containers::SingleDate
|
34
|
+
date: WillFilter::Containers::Date
|
35
|
+
date_time: WillFilter::Containers::DateTime
|
36
|
+
date_range: WillFilter::Containers::DateRange
|
37
|
+
text: WillFilter::Containers::Text
|
38
|
+
text_delimited: WillFilter::Containers::TextDelimited
|
39
|
+
boolean: WillFilter::Containers::Boolean
|
40
|
+
list: WillFilter::Containers::List
|
41
|
+
filter_list: WillFilter::Containers::FilterList
|
42
|
+
|
43
|
+
data_types: # mapping between data types and containers
|
44
|
+
bigint: [nil, numeric, numeric_range, numeric_delimited]
|
45
|
+
numeric: [nil, numeric, numeric_range, numeric_delimited]
|
46
|
+
smallint: [nil, numeric, numeric_range, numeric_delimited]
|
47
|
+
integer: [nil, numeric, numeric_range, numeric_delimited]
|
48
|
+
int: [nil, numeric, numeric_range, numeric_delimited]
|
49
|
+
double: [nil, numeric, numeric_range, numeric_delimited]
|
50
|
+
timestamp: [nil, date_time, date_time_range, single_date]
|
51
|
+
datetime: [nil, date_time, date_time_range, single_date]
|
52
|
+
date: [nil, date, date_range]
|
53
|
+
character: [nil, text, text_delimited]
|
54
|
+
varchar: [nil, text, text_delimited]
|
55
|
+
text: [nil, text, text_delimited]
|
56
|
+
text[]: [nil, text, text_delimited]
|
57
|
+
bytea: [nil, text, text_delimited]
|
58
|
+
boolean: [nil, boolean]
|
59
|
+
tinyint: [nil, boolean]
|
60
|
+
|
61
|
+
operators: # operators precedence
|
62
|
+
is: 100
|
63
|
+
is_not: 200
|
64
|
+
is_on: 300
|
65
|
+
is_in: 400
|
66
|
+
is_provided: 500
|
67
|
+
is_not_provided: 600
|
68
|
+
is_after: 700
|
69
|
+
is_before: 800
|
70
|
+
is_in_the_range: 900
|
71
|
+
contains: 1000
|
72
|
+
does_not_contain: 1100
|
73
|
+
starts_with: 1200
|
74
|
+
ends_with: 1300
|
75
|
+
is_greater_than: 1400
|
76
|
+
is_less_than: 1500
|
77
|
+
is_filtered_by: 1600
|
78
|
+
|
79
|
+
|
80
|
+
#############################################################################
|
81
|
+
# Environment Settings
|
82
|
+
# You can overload any feature defined in the defaults for any environment
|
83
|
+
#############################################################################
|
84
|
+
development:
|
85
|
+
<<: *defaults
|
86
|
+
|
87
|
+
test:
|
88
|
+
<<: *defaults
|
89
|
+
|
90
|
+
qa:
|
91
|
+
<<: *defaults
|
92
|
+
|
93
|
+
stage:
|
94
|
+
<<: *defaults
|
95
|
+
|
96
|
+
production:
|
97
|
+
<<: *defaults
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateWillFilterTables < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :wf_filters do |t|
|
4
|
+
t.string :type
|
5
|
+
t.string :name
|
6
|
+
t.text :data
|
7
|
+
t.integer :user_id
|
8
|
+
t.string :model_class_name
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :wf_filters, [:user_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :wf_filters
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class WillFilterGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.expand_path('../templates', __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Implement the required interface for Rails::Generators::Migration.
|
12
|
+
def self.next_migration_number(dirname)
|
13
|
+
if ActiveRecord::Base.timestamped_migrations
|
14
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
15
|
+
else
|
16
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_migration_file
|
21
|
+
migration_template 'create_will_filter_tables.rb', 'db/migrate/create_will_filter_tables.rb'
|
22
|
+
copy_file 'config.yml', 'config/will_filter/config.yml'
|
23
|
+
end
|
24
|
+
end
|
data/lib/tasks/.gitkeep
ADDED
File without changes
|