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
data/.loadpath
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<loadpath>
|
3
|
+
<pathentry path="" type="src"/>
|
4
|
+
<pathentry path="org.rubypeople.rdt.launching.RUBY_CONTAINER" type="con"/>
|
5
|
+
<pathentry path="GEM_LIB/activerecord-2.3.2/lib" type="var"/>
|
6
|
+
<pathentry path="GEM_LIB/rake-0.8.4/lib" type="var"/>
|
7
|
+
<pathentry path="GEM_LIB/activeresource-2.3.2/lib" type="var"/>
|
8
|
+
<pathentry path="GEM_LIB/rails-2.3.2/lib" type="var"/>
|
9
|
+
<pathentry path="GEM_LIB/actionmailer-2.3.2/lib" type="var"/>
|
10
|
+
<pathentry path="GEM_LIB/actionpack-2.3.2/lib" type="var"/>
|
11
|
+
<pathentry path="GEM_LIB/activesupport-2.3.2/lib" type="var"/>
|
12
|
+
</loadpath>
|
data/.project
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<projectDescription>
|
3
|
+
<name>will_filter</name>
|
4
|
+
<comment></comment>
|
5
|
+
<projects>
|
6
|
+
</projects>
|
7
|
+
<buildSpec>
|
8
|
+
<buildCommand>
|
9
|
+
<name>org.rubypeople.rdt.core.rubybuilder</name>
|
10
|
+
<arguments>
|
11
|
+
</arguments>
|
12
|
+
</buildCommand>
|
13
|
+
</buildSpec>
|
14
|
+
<natures>
|
15
|
+
<nature>org.rubypeople.rdt.core.rubynature</nature>
|
16
|
+
<nature>org.radrails.rails.core.railsnature</nature>
|
17
|
+
</natures>
|
18
|
+
</projectDescription>
|
data/CHANGELOG.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
== 0.1.0, released 2011-05-29
|
data/Gemfile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 3.0.0'
|
4
|
+
gem "will_paginate", "~> 3.0.pre2"
|
5
|
+
|
6
|
+
# Bundle edge Rails instead:
|
7
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
8
|
+
|
9
|
+
# gem 'sqlite3'
|
10
|
+
|
11
|
+
# Use unicorn as the web server
|
12
|
+
# gem 'unicorn'
|
13
|
+
|
14
|
+
# Deploy with Capistrano
|
15
|
+
# gem 'capistrano'
|
16
|
+
|
17
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
18
|
+
# gem 'ruby-debug'
|
19
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|
20
|
+
|
21
|
+
# Bundle the extra gems:
|
22
|
+
# gem 'bj'
|
23
|
+
# gem 'nokogiri'
|
24
|
+
# gem 'sqlite3-ruby', :require => 'sqlite3'
|
25
|
+
# gem 'aws-s3', :require => 'aws/s3'
|
26
|
+
|
27
|
+
# Bundle gems for the local environment. Make sure to
|
28
|
+
# put test-only gems in this group so their generators
|
29
|
+
# and rake tasks are available in development mode:
|
30
|
+
# group :development, :test do
|
31
|
+
# gem 'webrat'
|
32
|
+
# end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.7)
|
6
|
+
actionpack (= 3.0.7)
|
7
|
+
mail (~> 2.2.15)
|
8
|
+
actionpack (3.0.7)
|
9
|
+
activemodel (= 3.0.7)
|
10
|
+
activesupport (= 3.0.7)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.14)
|
16
|
+
rack-test (~> 0.5.7)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.7)
|
19
|
+
activesupport (= 3.0.7)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.5.0)
|
22
|
+
activerecord (3.0.7)
|
23
|
+
activemodel (= 3.0.7)
|
24
|
+
activesupport (= 3.0.7)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.7)
|
28
|
+
activemodel (= 3.0.7)
|
29
|
+
activesupport (= 3.0.7)
|
30
|
+
activesupport (3.0.7)
|
31
|
+
arel (2.0.10)
|
32
|
+
builder (2.1.2)
|
33
|
+
erubis (2.6.6)
|
34
|
+
abstract (>= 1.0.0)
|
35
|
+
i18n (0.5.0)
|
36
|
+
mail (2.2.19)
|
37
|
+
activesupport (>= 2.3.6)
|
38
|
+
i18n (>= 0.4.0)
|
39
|
+
mime-types (~> 1.16)
|
40
|
+
treetop (~> 1.4.8)
|
41
|
+
mime-types (1.16)
|
42
|
+
polyglot (0.3.1)
|
43
|
+
rack (1.2.3)
|
44
|
+
rack-mount (0.6.14)
|
45
|
+
rack (>= 1.0.0)
|
46
|
+
rack-test (0.5.7)
|
47
|
+
rack (>= 1.0)
|
48
|
+
rails (3.0.7)
|
49
|
+
actionmailer (= 3.0.7)
|
50
|
+
actionpack (= 3.0.7)
|
51
|
+
activerecord (= 3.0.7)
|
52
|
+
activeresource (= 3.0.7)
|
53
|
+
activesupport (= 3.0.7)
|
54
|
+
bundler (~> 1.0)
|
55
|
+
railties (= 3.0.7)
|
56
|
+
railties (3.0.7)
|
57
|
+
actionpack (= 3.0.7)
|
58
|
+
activesupport (= 3.0.7)
|
59
|
+
rake (>= 0.8.7)
|
60
|
+
thor (~> 0.14.4)
|
61
|
+
rake (0.9.1)
|
62
|
+
thor (0.14.6)
|
63
|
+
treetop (1.4.9)
|
64
|
+
polyglot (>= 0.3.1)
|
65
|
+
tzinfo (0.3.27)
|
66
|
+
will_paginate (3.0.pre2)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
rails (= 3.0.7)
|
73
|
+
will_paginate (~> 3.0.pre2)
|
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2011 Michael Berkovich
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= WillFilter
|
2
|
+
|
3
|
+
will_filter is a Rails engine plugin that extends the functionality of will_paginate by adding filters to your pages.
|
4
|
+
|
5
|
+
== Preamble
|
6
|
+
|
7
|
+
If you ever had to build an admin tool for your web site that displayed a list of objects that can be filtered using
|
8
|
+
various criteria, this plugin will make your life easier. Adding a filtered page can now be
|
9
|
+
a matter of adding two lines of code - one to your controller and one to your view. See examples below.
|
10
|
+
|
11
|
+
For advanced samples of how to use the filters, please download and install the following project:
|
12
|
+
|
13
|
+
http://github.com/berk/will_filter_examples
|
14
|
+
|
15
|
+
== Installation Instructions
|
16
|
+
|
17
|
+
Add the following gems to your Gemfile:
|
18
|
+
|
19
|
+
gem "will_paginate", "~> 3.0.pre2"
|
20
|
+
gem 'will_filter', "0.1.1"
|
21
|
+
|
22
|
+
And run:
|
23
|
+
|
24
|
+
$ bundle install
|
25
|
+
|
26
|
+
To configure and initialize will_filter engine, run the following commands:
|
27
|
+
|
28
|
+
$ rails generate will_filter
|
29
|
+
$ rake db:migrate
|
30
|
+
|
31
|
+
== Examples
|
32
|
+
|
33
|
+
To add a filtered result-set to your controller use the following method call:
|
34
|
+
|
35
|
+
class OrderController < ApplicationController
|
36
|
+
|
37
|
+
def index
|
38
|
+
@orders = Order.filter(:params => params)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
Note: 'Order' is a Rails ActiveRecord model
|
44
|
+
|
45
|
+
Now all you have to do is create a view for this action and add the following tag where you want the filter to be rendered:
|
46
|
+
|
47
|
+
<%= will_filter(@orders) %>
|
48
|
+
|
49
|
+
And optionally you can do (for results table):
|
50
|
+
|
51
|
+
<%= will_filter_table_tag(@orders) %>
|
52
|
+
|
53
|
+
That's it. This will render a filter box with various conditions, operators and values for the model object you selected.
|
54
|
+
|
55
|
+
Below are a couple of screenshot of what the filter looks like when it is rendered on a page:
|
56
|
+
|
57
|
+
http://wiki.tr8n.org/images/d/da/Will_filter_1.png
|
58
|
+
|
59
|
+
http://wiki.tr8n.org/images/e/ec/Will_filter_2.png
|
60
|
+
|
61
|
+
will_filter_examples project contains some samples that show you how to customize filters and much more
|
62
|
+
|
63
|
+
git://github.com/berk/will_filter_examples.git
|
64
|
+
|
65
|
+
Live will_filter_examples application is running here:
|
66
|
+
|
67
|
+
http://wf.tr8n.org
|
68
|
+
|
69
|
+
If you have any questions, comments or suggestions, email me at michael@geni.com
|
70
|
+
|
71
|
+
== Authors and credits
|
72
|
+
|
73
|
+
Authors:: Michael Berkovich
|
74
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
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
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
25
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new do |test|
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.libs << 'test'
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
require 'jeweler'
|
36
|
+
Jeweler::Tasks.new do |s|
|
37
|
+
s.name = "will_filter"
|
38
|
+
s.summary = "Rails engine for filtering ActiveRecord model objects."
|
39
|
+
s.email = "theiceberk@gmail.com"
|
40
|
+
s.homepage = "http://github.com/berk/will_filter"
|
41
|
+
s.description = "Rails engine for filtering ActiveRecord model objects."
|
42
|
+
s.authors = ["Michael Berkovich"]
|
43
|
+
end
|
44
|
+
Jeweler::GemcutterTasks.new
|
45
|
+
rescue LoadError
|
46
|
+
puts "Jeweler not available. Install it with: sudo gem install jeweler"
|
47
|
+
end
|
48
|
+
|
49
|
+
#require File.expand_path('../config/application', __FILE__)
|
50
|
+
#require 'rake'
|
51
|
+
#
|
52
|
+
#WillFilter::Application.load_tasks
|
53
|
+
|
54
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.0
|
@@ -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
|
+
class ApplicationController < ActionController::Base
|
25
|
+
# protect_from_forgery
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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 CalendarController < ApplicationController
|
26
|
+
def index
|
27
|
+
@calendar = WillFilter::Calendar.new(params[:wf_calendar_selected_date], params[:wf_calendar_start_date], params[:wf_calendar_show_time] == 'true', params[:wf_calendar_mode] || 'month')
|
28
|
+
render :layout => false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,122 @@
|
|
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
|
+
require 'csv'
|
25
|
+
|
26
|
+
module WillFilter
|
27
|
+
class ExporterController < ApplicationController
|
28
|
+
def index
|
29
|
+
@wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
30
|
+
render :layout => false
|
31
|
+
end
|
32
|
+
|
33
|
+
def export
|
34
|
+
params[:page] = 1
|
35
|
+
params[:per_page] = 10000 # mas export limit
|
36
|
+
|
37
|
+
@wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
38
|
+
|
39
|
+
if @wf_filter.custom_format?
|
40
|
+
send_data(@wf_filter.process_custom_format, :type => 'text', :charset => 'utf-8')
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
unless @wf_filter.valid_format?
|
45
|
+
render :text => "The export format is not supported (#{@wf_filter.format})"
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
if @wf_filter.format == :xml
|
50
|
+
return send_xml_data(@wf_filter)
|
51
|
+
end
|
52
|
+
|
53
|
+
if @wf_filter.format == :json
|
54
|
+
return send_json_data(@wf_filter)
|
55
|
+
end
|
56
|
+
|
57
|
+
if @wf_filter.format == :csv
|
58
|
+
return send_csv_data(@wf_filter)
|
59
|
+
end
|
60
|
+
|
61
|
+
render :layout => false
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def send_xml_data(wf_filter)
|
67
|
+
class_name = wf_filter.model_class_name.underscore
|
68
|
+
|
69
|
+
result = ""
|
70
|
+
xml = Builder::XmlMarkup.new(:target => result, :indent => 1)
|
71
|
+
xml.instruct!
|
72
|
+
xml.tag!(class_name.pluralize) do
|
73
|
+
wf_filter.results.each do |obj|
|
74
|
+
xml.tag!(class_name.underscore) do
|
75
|
+
wf_filter.fields.each do |field|
|
76
|
+
xml.tag!(field.to_s, obj.send(field).to_s)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
send_data(result, :type => 'text/xml', :charset => 'utf-8')
|
83
|
+
end
|
84
|
+
|
85
|
+
def send_json_data(wf_filter)
|
86
|
+
result = []
|
87
|
+
|
88
|
+
wf_filter.results.each do |obj|
|
89
|
+
hash = {}
|
90
|
+
wf_filter.fields.each do |field|
|
91
|
+
hash[field] = obj.send(field).to_s
|
92
|
+
end
|
93
|
+
result << hash
|
94
|
+
end
|
95
|
+
|
96
|
+
send_data(result.to_json, :type => 'text', :charset => 'utf-8')
|
97
|
+
end
|
98
|
+
|
99
|
+
def send_csv_data(wf_filter)
|
100
|
+
result = StringIO.new
|
101
|
+
|
102
|
+
# CSV.open(result) do |csv|
|
103
|
+
# csv << ["row", "of", "CSV", "data"]
|
104
|
+
# csv << ["another", "row"]
|
105
|
+
# # ...
|
106
|
+
# end
|
107
|
+
|
108
|
+
CSV::Writer.generate(result) do |csv|
|
109
|
+
csv << wf_filter.fields
|
110
|
+
wf_filter.results.each do |obj|
|
111
|
+
row = []
|
112
|
+
wf_filter.fields.each do |field|
|
113
|
+
row << obj.send(field).to_s
|
114
|
+
end
|
115
|
+
csv << row
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
send_data(result.string, :type => 'text/csv', :charset => 'utf-8')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,107 @@
|
|
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 FilterController < ApplicationController
|
26
|
+
def index
|
27
|
+
@filters = WillFilter::Filter.new(WillFilter::Filter).deserialize_from_params(params).results
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_condition
|
31
|
+
wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
32
|
+
condition = wf_filter.condition_at(params[:at_index].to_i)
|
33
|
+
condition.container.reset_values
|
34
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
35
|
+
end
|
36
|
+
|
37
|
+
def remove_condition
|
38
|
+
wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
39
|
+
wf_filter.remove_condition_at(params[:at_index].to_i)
|
40
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_condition
|
44
|
+
wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
45
|
+
index = params[:after_index].to_i
|
46
|
+
if index == -1
|
47
|
+
wf_filter.add_default_condition_at(wf_filter.size)
|
48
|
+
else
|
49
|
+
wf_filter.add_default_condition_at(params[:after_index].to_i + 1)
|
50
|
+
end
|
51
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
52
|
+
end
|
53
|
+
|
54
|
+
def remove_all_conditions
|
55
|
+
wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
56
|
+
wf_filter.remove_all
|
57
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_filter
|
61
|
+
wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
62
|
+
wf_filter = wf_filter.load_filter!(params[:wf_key])
|
63
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
64
|
+
end
|
65
|
+
|
66
|
+
def save_filter
|
67
|
+
params.delete(:wf_id)
|
68
|
+
|
69
|
+
wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
70
|
+
wf_filter.validate!
|
71
|
+
|
72
|
+
unless wf_filter.errors?
|
73
|
+
wf_filter.save
|
74
|
+
end
|
75
|
+
|
76
|
+
wf_filter.key= wf_filter.id.to_s
|
77
|
+
|
78
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
79
|
+
end
|
80
|
+
|
81
|
+
def update_filter
|
82
|
+
wf_filter = WillFilter::Filter.find_by_id(params.delete(:wf_id))
|
83
|
+
wf_filter.deserialize_from_params(params)
|
84
|
+
wf_filter.validate!
|
85
|
+
|
86
|
+
unless wf_filter.errors?
|
87
|
+
wf_filter.save
|
88
|
+
end
|
89
|
+
|
90
|
+
wf_filter.key= wf_filter.id.to_s
|
91
|
+
|
92
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
93
|
+
end
|
94
|
+
|
95
|
+
def delete_filter
|
96
|
+
wf_filter = WillFilter::Filter.find_by_id(params[:wf_id])
|
97
|
+
wf_filter.destroy if wf_filter
|
98
|
+
|
99
|
+
wf_filter = WillFilter::Filter.deserialize_from_params(params)
|
100
|
+
wf_filter.id=nil
|
101
|
+
wf_filter.key=nil
|
102
|
+
wf_filter.remove_all
|
103
|
+
|
104
|
+
render(:partial => '/will_filter/filter/conditions', :layout=>false, :locals => {:wf_filter => wf_filter})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
|
26
|
+
end
|