jtable-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +94 -0
- data/LICENSE.txt +22 -0
- data/README.md +2 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/jtable-rails.gemspec +136 -0
- data/lib/jtable-rails.rb +5 -0
- data/lib/jtable-rails/action_controller.rb +8 -0
- data/lib/jtable-rails/active_record.rb +83 -0
- data/spec/controller_specs/people_controller_spec.rb +30 -0
- data/spec/fabricators/person.rb +9 -0
- data/spec/model_specs/person_spec.rb +73 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/rails_app/.gitignore +4 -0
- data/spec/support/rails_app/Gemfile +5 -0
- data/spec/support/rails_app/Gemfile.lock +82 -0
- data/spec/support/rails_app/Rakefile +7 -0
- data/spec/support/rails_app/app/controllers/application_controller.rb +3 -0
- data/spec/support/rails_app/app/controllers/people_controller.rb +83 -0
- data/spec/support/rails_app/app/helpers/application_helper.rb +2 -0
- data/spec/support/rails_app/app/helpers/people_helper.rb +2 -0
- data/spec/support/rails_app/app/models/person.rb +3 -0
- data/spec/support/rails_app/app/views/layouts/application.html.erb +14 -0
- data/spec/support/rails_app/app/views/people/_form.html.erb +41 -0
- data/spec/support/rails_app/app/views/people/edit.html.erb +6 -0
- data/spec/support/rails_app/app/views/people/index.html.erb +33 -0
- data/spec/support/rails_app/app/views/people/new.html.erb +5 -0
- data/spec/support/rails_app/app/views/people/show.html.erb +35 -0
- data/spec/support/rails_app/config.ru +4 -0
- data/spec/support/rails_app/config/application.rb +42 -0
- data/spec/support/rails_app/config/boot.rb +13 -0
- data/spec/support/rails_app/config/database.yml +22 -0
- data/spec/support/rails_app/config/environment.rb +5 -0
- data/spec/support/rails_app/config/environments/development.rb +26 -0
- data/spec/support/rails_app/config/environments/production.rb +49 -0
- data/spec/support/rails_app/config/environments/test.rb +35 -0
- data/spec/support/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/support/rails_app/config/initializers/inflections.rb +10 -0
- data/spec/support/rails_app/config/initializers/mime_types.rb +5 -0
- data/spec/support/rails_app/config/initializers/secret_token.rb +7 -0
- data/spec/support/rails_app/config/initializers/session_store.rb +8 -0
- data/spec/support/rails_app/config/locales/en.yml +5 -0
- data/spec/support/rails_app/config/routes.rb +60 -0
- data/spec/support/rails_app/db/migrate/20110207142623_create_people.rb +18 -0
- data/spec/support/rails_app/db/schema.rb +26 -0
- data/spec/support/rails_app/db/seeds.rb +7 -0
- data/spec/support/rails_app/public/stylesheets/scaffold.css +56 -0
- data/spec/support/rails_app/script/rails +6 -0
- metadata +236 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.3)
|
6
|
+
actionpack (= 3.0.3)
|
7
|
+
mail (~> 2.2.9)
|
8
|
+
actionpack (3.0.3)
|
9
|
+
activemodel (= 3.0.3)
|
10
|
+
activesupport (= 3.0.3)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.6)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.3)
|
19
|
+
activesupport (= 3.0.3)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.3)
|
23
|
+
activemodel (= 3.0.3)
|
24
|
+
activesupport (= 3.0.3)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.3)
|
28
|
+
activemodel (= 3.0.3)
|
29
|
+
activesupport (= 3.0.3)
|
30
|
+
activesupport (3.0.3)
|
31
|
+
arel (2.0.7)
|
32
|
+
builder (2.1.2)
|
33
|
+
diff-lcs (1.1.2)
|
34
|
+
erubis (2.6.6)
|
35
|
+
abstract (>= 1.0.0)
|
36
|
+
fabrication (0.9.4)
|
37
|
+
git (1.2.5)
|
38
|
+
i18n (0.5.0)
|
39
|
+
jeweler (1.5.2)
|
40
|
+
bundler (~> 1.0.0)
|
41
|
+
git (>= 1.2.5)
|
42
|
+
rake
|
43
|
+
mail (2.2.15)
|
44
|
+
activesupport (>= 2.3.6)
|
45
|
+
i18n (>= 0.4.0)
|
46
|
+
mime-types (~> 1.16)
|
47
|
+
treetop (~> 1.4.8)
|
48
|
+
mime-types (1.16)
|
49
|
+
polyglot (0.3.1)
|
50
|
+
rack (1.2.1)
|
51
|
+
rack-mount (0.6.13)
|
52
|
+
rack (>= 1.0.0)
|
53
|
+
rack-test (0.5.7)
|
54
|
+
rack (>= 1.0)
|
55
|
+
rails (3.0.3)
|
56
|
+
actionmailer (= 3.0.3)
|
57
|
+
actionpack (= 3.0.3)
|
58
|
+
activerecord (= 3.0.3)
|
59
|
+
activeresource (= 3.0.3)
|
60
|
+
activesupport (= 3.0.3)
|
61
|
+
bundler (~> 1.0)
|
62
|
+
railties (= 3.0.3)
|
63
|
+
railties (3.0.3)
|
64
|
+
actionpack (= 3.0.3)
|
65
|
+
activesupport (= 3.0.3)
|
66
|
+
rake (>= 0.8.7)
|
67
|
+
thor (~> 0.14.4)
|
68
|
+
rake (0.8.7)
|
69
|
+
rspec (2.3.0)
|
70
|
+
rspec-core (~> 2.3.0)
|
71
|
+
rspec-expectations (~> 2.3.0)
|
72
|
+
rspec-mocks (~> 2.3.0)
|
73
|
+
rspec-core (2.3.1)
|
74
|
+
rspec-expectations (2.3.0)
|
75
|
+
diff-lcs (~> 1.1.2)
|
76
|
+
rspec-mocks (2.3.0)
|
77
|
+
sqlite3 (1.3.3)
|
78
|
+
sqlite3-ruby (1.3.3)
|
79
|
+
sqlite3 (>= 1.3.3)
|
80
|
+
thor (0.14.6)
|
81
|
+
treetop (1.4.9)
|
82
|
+
polyglot (>= 0.3.1)
|
83
|
+
tzinfo (0.3.24)
|
84
|
+
|
85
|
+
PLATFORMS
|
86
|
+
ruby
|
87
|
+
|
88
|
+
DEPENDENCIES
|
89
|
+
bundler
|
90
|
+
fabrication
|
91
|
+
jeweler (~> 1.5.2)
|
92
|
+
rails (= 3.0.3)
|
93
|
+
rspec
|
94
|
+
sqlite3-ruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2011 Taylor Yelverton
|
2
|
+
|
3
|
+
This license governs use of the accompanying software. If you use the software, you
|
4
|
+
accept this license. If you do not accept the license, do not use the software.
|
5
|
+
|
6
|
+
1. Definitions
|
7
|
+
The terms "reproduce," "reproduction," "derivative works," and "distribution" have the
|
8
|
+
same meaning here as under U.S. copyright law.
|
9
|
+
A "contribution" is the original software, or any additions or changes to the software.
|
10
|
+
A "contributor" is any person that distributes its contribution under this license.
|
11
|
+
"Licensed patents" are a contributor's patent claims that read directly on its contribution.
|
12
|
+
|
13
|
+
2. Grant of Rights
|
14
|
+
(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
|
15
|
+
(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
|
16
|
+
|
17
|
+
3. Conditions and Limitations
|
18
|
+
(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
|
19
|
+
(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically.
|
20
|
+
(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software.
|
21
|
+
(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license.
|
22
|
+
(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "jtable-rails"
|
17
|
+
gem.homepage = "http://github.com/yelvert/jtable-rails"
|
18
|
+
gem.license = "Ms-PL"
|
19
|
+
gem.summary = "A Rails gem to power the jTable jQuery plugin"
|
20
|
+
gem.description = "A Rails gem to power the jTable jQuery plugin"
|
21
|
+
gem.email = "taylor@synergy-solutions.biz"
|
22
|
+
gem.authors = ["Taylor Yelverton"]
|
23
|
+
gem.add_runtime_dependency 'rails', '3.0.3'
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rspec/core'
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
30
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :spec
|
34
|
+
|
35
|
+
require 'rake/rdoctask'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
38
|
+
rdoc.rdoc_dir = 'rdoc'
|
39
|
+
rdoc.title = "jtable-rails #{version}"
|
40
|
+
rdoc.rdoc_files.include('README*')
|
41
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{jtable-rails}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Taylor Yelverton"]
|
12
|
+
s.date = %q{2011-02-11}
|
13
|
+
s.description = %q{A Rails gem to power the jTable jQuery plugin}
|
14
|
+
s.email = %q{taylor@synergy-solutions.biz}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
".rvmrc",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"jtable-rails.gemspec",
|
30
|
+
"lib/jtable-rails.rb",
|
31
|
+
"lib/jtable-rails/action_controller.rb",
|
32
|
+
"lib/jtable-rails/active_record.rb",
|
33
|
+
"spec/controller_specs/people_controller_spec.rb",
|
34
|
+
"spec/fabricators/person.rb",
|
35
|
+
"spec/model_specs/person_spec.rb",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"spec/support/rails_app/.gitignore",
|
38
|
+
"spec/support/rails_app/Gemfile",
|
39
|
+
"spec/support/rails_app/Gemfile.lock",
|
40
|
+
"spec/support/rails_app/Rakefile",
|
41
|
+
"spec/support/rails_app/app/controllers/application_controller.rb",
|
42
|
+
"spec/support/rails_app/app/controllers/people_controller.rb",
|
43
|
+
"spec/support/rails_app/app/helpers/application_helper.rb",
|
44
|
+
"spec/support/rails_app/app/helpers/people_helper.rb",
|
45
|
+
"spec/support/rails_app/app/models/person.rb",
|
46
|
+
"spec/support/rails_app/app/views/layouts/application.html.erb",
|
47
|
+
"spec/support/rails_app/app/views/people/_form.html.erb",
|
48
|
+
"spec/support/rails_app/app/views/people/edit.html.erb",
|
49
|
+
"spec/support/rails_app/app/views/people/index.html.erb",
|
50
|
+
"spec/support/rails_app/app/views/people/new.html.erb",
|
51
|
+
"spec/support/rails_app/app/views/people/show.html.erb",
|
52
|
+
"spec/support/rails_app/config.ru",
|
53
|
+
"spec/support/rails_app/config/application.rb",
|
54
|
+
"spec/support/rails_app/config/boot.rb",
|
55
|
+
"spec/support/rails_app/config/database.yml",
|
56
|
+
"spec/support/rails_app/config/environment.rb",
|
57
|
+
"spec/support/rails_app/config/environments/development.rb",
|
58
|
+
"spec/support/rails_app/config/environments/production.rb",
|
59
|
+
"spec/support/rails_app/config/environments/test.rb",
|
60
|
+
"spec/support/rails_app/config/initializers/backtrace_silencers.rb",
|
61
|
+
"spec/support/rails_app/config/initializers/inflections.rb",
|
62
|
+
"spec/support/rails_app/config/initializers/mime_types.rb",
|
63
|
+
"spec/support/rails_app/config/initializers/secret_token.rb",
|
64
|
+
"spec/support/rails_app/config/initializers/session_store.rb",
|
65
|
+
"spec/support/rails_app/config/locales/en.yml",
|
66
|
+
"spec/support/rails_app/config/routes.rb",
|
67
|
+
"spec/support/rails_app/db/migrate/20110207142623_create_people.rb",
|
68
|
+
"spec/support/rails_app/db/schema.rb",
|
69
|
+
"spec/support/rails_app/db/seeds.rb",
|
70
|
+
"spec/support/rails_app/public/stylesheets/scaffold.css",
|
71
|
+
"spec/support/rails_app/script/rails"
|
72
|
+
]
|
73
|
+
s.homepage = %q{http://github.com/yelvert/jtable-rails}
|
74
|
+
s.licenses = ["Ms-PL"]
|
75
|
+
s.require_paths = ["lib"]
|
76
|
+
s.rubygems_version = %q{1.3.7}
|
77
|
+
s.summary = %q{A Rails gem to power the jTable jQuery plugin}
|
78
|
+
s.test_files = [
|
79
|
+
"spec/controller_specs/people_controller_spec.rb",
|
80
|
+
"spec/fabricators/person.rb",
|
81
|
+
"spec/model_specs/person_spec.rb",
|
82
|
+
"spec/spec_helper.rb",
|
83
|
+
"spec/support/rails_app/app/controllers/application_controller.rb",
|
84
|
+
"spec/support/rails_app/app/controllers/people_controller.rb",
|
85
|
+
"spec/support/rails_app/app/helpers/application_helper.rb",
|
86
|
+
"spec/support/rails_app/app/helpers/people_helper.rb",
|
87
|
+
"spec/support/rails_app/app/models/person.rb",
|
88
|
+
"spec/support/rails_app/config/application.rb",
|
89
|
+
"spec/support/rails_app/config/boot.rb",
|
90
|
+
"spec/support/rails_app/config/environment.rb",
|
91
|
+
"spec/support/rails_app/config/environments/development.rb",
|
92
|
+
"spec/support/rails_app/config/environments/production.rb",
|
93
|
+
"spec/support/rails_app/config/environments/test.rb",
|
94
|
+
"spec/support/rails_app/config/initializers/backtrace_silencers.rb",
|
95
|
+
"spec/support/rails_app/config/initializers/inflections.rb",
|
96
|
+
"spec/support/rails_app/config/initializers/mime_types.rb",
|
97
|
+
"spec/support/rails_app/config/initializers/secret_token.rb",
|
98
|
+
"spec/support/rails_app/config/initializers/session_store.rb",
|
99
|
+
"spec/support/rails_app/config/routes.rb",
|
100
|
+
"spec/support/rails_app/db/migrate/20110207142623_create_people.rb",
|
101
|
+
"spec/support/rails_app/db/schema.rb",
|
102
|
+
"spec/support/rails_app/db/seeds.rb"
|
103
|
+
]
|
104
|
+
|
105
|
+
if s.respond_to? :specification_version then
|
106
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
107
|
+
s.specification_version = 3
|
108
|
+
|
109
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
110
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
111
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
112
|
+
s.add_development_dependency(%q<fabrication>, [">= 0"])
|
113
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
114
|
+
s.add_development_dependency(%q<rails>, ["= 3.0.3"])
|
115
|
+
s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
|
116
|
+
s.add_runtime_dependency(%q<rails>, ["= 3.0.3"])
|
117
|
+
else
|
118
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
119
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
120
|
+
s.add_dependency(%q<fabrication>, [">= 0"])
|
121
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
122
|
+
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
123
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
124
|
+
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
125
|
+
end
|
126
|
+
else
|
127
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
128
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
129
|
+
s.add_dependency(%q<fabrication>, [">= 0"])
|
130
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
131
|
+
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
132
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
133
|
+
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
data/lib/jtable-rails.rb
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
require 'rails/all'
|
2
|
+
require 'jtable-rails/active_record'
|
3
|
+
require 'jtable-rails/action_controller'
|
4
|
+
::ActiveRecord::Base.send(:include, JTable::ActiveRecord) if defined? ::ActiveRecord
|
5
|
+
::ActionController::Base.send(:include, JTable::ActionController) if defined? ::ActionController
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module JTable
|
2
|
+
module ActionController
|
3
|
+
def jtable_for_json(rel, jtable_params)
|
4
|
+
jtable_params = HashWithIndifferentAccess.new(jtable_params)
|
5
|
+
{:total_items => rel.count, :items => rel.jtable_paginate(jtable_params[:limit], jtable_params[:offset])}
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module JTable
|
2
|
+
module ActiveRecord
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
module ClassMethods
|
5
|
+
def jtable(*fields)
|
6
|
+
metaclass = class << self
|
7
|
+
self
|
8
|
+
end
|
9
|
+
fields.each do |field|
|
10
|
+
metaclass.instance_eval do
|
11
|
+
define_method "jtable_search_#{field}" do |term|
|
12
|
+
unless [:date].include? arel_table[field.to_sym].column.type
|
13
|
+
if [:integer, :boolean].include? arel_table[field.to_sym].column.type
|
14
|
+
arel_table[field.to_sym].eq(term.to_i)
|
15
|
+
else
|
16
|
+
arel_table[field.to_sym].matches("%#{term}%")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method "jtable_order_#{field}" do |direction|
|
22
|
+
"#{field} #{direction}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
scope :jtable_search, lambda { |jtable_params|
|
28
|
+
search_terms = jtable_params[:search]
|
29
|
+
unless search_terms.blank?
|
30
|
+
wheres = []
|
31
|
+
search_terms.split(" ").each do |term|
|
32
|
+
where_query = []
|
33
|
+
fields.each do |field|
|
34
|
+
next unless jtable_params[:searchable_columns].include?(field.to_s)
|
35
|
+
where_query << self.send("jtable_search_#{field}", term)
|
36
|
+
end
|
37
|
+
wheres << where(where_query.inject(&:or))
|
38
|
+
end
|
39
|
+
wheres.inject(&:&)
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
scope :jtable_single_search, lambda {|column, search_terms|
|
44
|
+
unless column.blank? or search_terms.blank?
|
45
|
+
wheres = []
|
46
|
+
search_terms.split(" ").each do |term|
|
47
|
+
wheres << where(self.send("jtable_search_#{column}", term))
|
48
|
+
end
|
49
|
+
wheres.inject(&:&)
|
50
|
+
end
|
51
|
+
}
|
52
|
+
|
53
|
+
scope :jtable_order, lambda {|column, direction|
|
54
|
+
if !column.blank? and !direction.blank? and %w(asc desc).include?(direction.downcase)
|
55
|
+
order(self.send("jtable_order_#{column}", direction))
|
56
|
+
end
|
57
|
+
}
|
58
|
+
|
59
|
+
scope :jtable_paginate, lambda {|per_page, page_start|
|
60
|
+
limit(per_page.to_i).offset(page_start.to_i)
|
61
|
+
}
|
62
|
+
|
63
|
+
scope :jtable_default, lambda {
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
scope :jtable_query, lambda { |jtable_params|
|
68
|
+
jtable_params = HashWithIndifferentAccess.new(jtable_params)
|
69
|
+
queries = []
|
70
|
+
queries << jtable_default()
|
71
|
+
queries << jtable_search(jtable_params)
|
72
|
+
unless jtable_params[:column_search].blank?
|
73
|
+
jtable_params[:column_search].each_pair do |column, search|
|
74
|
+
queries << jtable_single_search(column, search)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
queries << jtable_order(jtable_params[:sort_column], jtable_params[:sort_direction])
|
78
|
+
queries.inject(&:&)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "PeopleController" do
|
4
|
+
before(:each) do
|
5
|
+
@people_controller = PeopleController.new
|
6
|
+
|
7
|
+
10.times do |i|
|
8
|
+
Fabricate(:person)
|
9
|
+
end
|
10
|
+
|
11
|
+
@params = {
|
12
|
+
:searchable_columns => ["first_name", "last_name", "age", "date_of_birth", "gender"],
|
13
|
+
:column_search => {},
|
14
|
+
:limit => "5",
|
15
|
+
:offset => "0",
|
16
|
+
:search => "",
|
17
|
+
:sort_column => "",
|
18
|
+
:sort_direction => ""
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have the jtable_for_json method" do
|
23
|
+
@people_controller.respond_to?(:jtable_for_json).should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return the appropriate json" do
|
27
|
+
people = Person.jtable_query(@params)
|
28
|
+
@people_controller.jtable_for_json(people, @params).to_json.should eql({:total_items => people.count, :items => people.jtable_paginate(@params[:limit], @params[:offset])}.to_json)
|
29
|
+
end
|
30
|
+
end
|