fancygrid 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.bundle/config +2 -0
- data/.rspec +1 -0
- data/CHANGELOG +34 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +125 -0
- data/LICENSE +20 -0
- data/README.rdoc +299 -0
- data/ROADMAP +1 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/app/views/fancygrid/_cells.html.haml +13 -0
- data/app/views/fancygrid/base/controls.html.haml +40 -0
- data/app/views/fancygrid/base/list_frame.html.haml +37 -0
- data/app/views/fancygrid/base/search.html.haml +33 -0
- data/app/views/fancygrid/base/sort.html.haml +20 -0
- data/app/views/fancygrid/base/table_frame.html.haml +45 -0
- data/config/initializers/fancygrid.rb +67 -0
- data/config/locales/fancygrid.de.yml +41 -0
- data/config/locales/fancygrid.en.yml +42 -0
- data/fancygrid.gemspec +162 -0
- data/init.rb +1 -0
- data/lib/fancygrid.rb +73 -0
- data/lib/fancygrid/grid.rb +387 -0
- data/lib/fancygrid/helper.rb +129 -0
- data/lib/fancygrid/node.rb +533 -0
- data/lib/fancygrid/query_generator.rb +338 -0
- data/lib/fancygrid/view.rb +148 -0
- data/lib/generators/install_generator.rb +61 -0
- data/lib/generators/views_generator.rb +25 -0
- data/lib/version.rb +0 -0
- data/public/images/fancygrid/add.png +0 -0
- data/public/images/fancygrid/clear.png +0 -0
- data/public/images/fancygrid/ddn.png +0 -0
- data/public/images/fancygrid/dn.png +0 -0
- data/public/images/fancygrid/dots.png +0 -0
- data/public/images/fancygrid/loading.gif +0 -0
- data/public/images/fancygrid/magnifier.png +0 -0
- data/public/images/fancygrid/next.png +0 -0
- data/public/images/fancygrid/order.png +0 -0
- data/public/images/fancygrid/prev.png +0 -0
- data/public/images/fancygrid/reload.png +0 -0
- data/public/images/fancygrid/remove.png +0 -0
- data/public/images/fancygrid/spacer.gif +0 -0
- data/public/images/fancygrid/submit.png +0 -0
- data/public/images/fancygrid/th_bg.png +0 -0
- data/public/images/fancygrid/up.png +0 -0
- data/public/images/fancygrid/uup.png +0 -0
- data/public/javascripts/fancygrid.js +477 -0
- data/public/javascripts/fancygrid.min.js +17 -0
- data/public/stylesheets/fancygrid.css +289 -0
- data/public/stylesheets/fancygrid.scss +302 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/project.rb +3 -0
- data/spec/dummy/app/models/ticket.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/migrate/20110112183948_create_projects.rb +11 -0
- data/spec/dummy/db/migrate/20110112183956_create_tickets.rb +14 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/log/production.log +0 -0
- data/spec/dummy/log/server.log +0 -0
- data/spec/dummy/log/test.log +1026 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +175 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/grid_spec.rb +15 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/node_spec.rb +326 -0
- data/spec/query_generator_spec.rb +358 -0
- data/spec/spec_helper.rb +53 -0
- metadata +214 -0
data/.bundle/config
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
1.0.0 - Added the "ajax_type" option so ajax callbacks are not restricted to GET requests only.
|
2
|
+
- Fixed a js bug that removes the input field focus when doing a simple search
|
3
|
+
BREAKING CHANGES:
|
4
|
+
- Added the "enable_sort_window" option. Set it to true to display the sort button that opens the sort window. The button was previosly always visible.
|
5
|
+
1.0.0-pre - Full Feature implementation done.
|
6
|
+
- Fixed tests
|
7
|
+
- Added new style
|
8
|
+
- Every "js-" prefix in css classes is now "fg-" and stands for 'fancygrid'
|
9
|
+
0.6.2 - Drop down select box is now possible as a simple search input field
|
10
|
+
0.6.1 - Refactored js and improved column sorting
|
11
|
+
0.6.0 - Initial implemetation of column sorting feature
|
12
|
+
0.5.1 - Fixed the complex search and improved viewstate caching.
|
13
|
+
0.5.0 - Initial implementation of the complex search.
|
14
|
+
0.4.2 - Ability to define a block for print out a custom css class for each table row. Check out the 'css_proc' method
|
15
|
+
- Implemented flexible query generator. You dont have to clutter all your conditions into a single place anymore
|
16
|
+
0.4.1 - Added a dummy testapplication into spec folder.
|
17
|
+
- Added several tests testing the core functionality.
|
18
|
+
- Added more documentation.
|
19
|
+
- Fixed a bug where not all find options were passed to the final find call.
|
20
|
+
0.4.0 - Fancygrid is now a Rails Engine instead of a Railtie. This allows us to
|
21
|
+
use template names for rendering, instead of absolute pathes. This makes
|
22
|
+
it possible to use fancygrid in other rails engines.
|
23
|
+
- Dumping and loading a view state for a grid is now possible. You can
|
24
|
+
dump and save a viewstate when a user leaves a site and load that state
|
25
|
+
when the user comes back.
|
26
|
+
BREAKING CHANGES:
|
27
|
+
- The initializer variable names have changed. Check the new initializer
|
28
|
+
file and compare it to the one in your projects.
|
29
|
+
0.3.3 - Fixed pagination
|
30
|
+
0.3.2 - Flexible initilaization
|
31
|
+
0.3.1 - Raketask replaced with generators
|
32
|
+
0.3.0 - Grid rendering using blocks is now possible
|
33
|
+
0.2.0 - Revisited implementation
|
34
|
+
0.1.0 - Initial implementation
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,125 @@
|
|
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
|
+
capybara (0.4.1.1)
|
34
|
+
celerity (>= 0.7.9)
|
35
|
+
culerity (>= 0.2.4)
|
36
|
+
mime-types (>= 1.16)
|
37
|
+
nokogiri (>= 1.3.3)
|
38
|
+
rack (>= 1.0.0)
|
39
|
+
rack-test (>= 0.5.4)
|
40
|
+
selenium-webdriver (>= 0.0.27)
|
41
|
+
xpath (~> 0.1.3)
|
42
|
+
celerity (0.8.7)
|
43
|
+
childprocess (0.1.6)
|
44
|
+
ffi (~> 0.6.3)
|
45
|
+
culerity (0.2.15)
|
46
|
+
diff-lcs (1.1.2)
|
47
|
+
erubis (2.6.6)
|
48
|
+
abstract (>= 1.0.0)
|
49
|
+
ffi (0.6.3)
|
50
|
+
rake (>= 0.8.7)
|
51
|
+
git (1.2.5)
|
52
|
+
i18n (0.5.0)
|
53
|
+
jeweler (1.5.2)
|
54
|
+
bundler (~> 1.0.0)
|
55
|
+
git (>= 1.2.5)
|
56
|
+
rake
|
57
|
+
json_pure (1.5.1)
|
58
|
+
mail (2.2.15)
|
59
|
+
activesupport (>= 2.3.6)
|
60
|
+
i18n (>= 0.4.0)
|
61
|
+
mime-types (~> 1.16)
|
62
|
+
treetop (~> 1.4.8)
|
63
|
+
mime-types (1.16)
|
64
|
+
nokogiri (1.4.4)
|
65
|
+
polyglot (0.3.1)
|
66
|
+
rack (1.2.1)
|
67
|
+
rack-mount (0.6.13)
|
68
|
+
rack (>= 1.0.0)
|
69
|
+
rack-test (0.5.7)
|
70
|
+
rack (>= 1.0)
|
71
|
+
rails (3.0.3)
|
72
|
+
actionmailer (= 3.0.3)
|
73
|
+
actionpack (= 3.0.3)
|
74
|
+
activerecord (= 3.0.3)
|
75
|
+
activeresource (= 3.0.3)
|
76
|
+
activesupport (= 3.0.3)
|
77
|
+
bundler (~> 1.0)
|
78
|
+
railties (= 3.0.3)
|
79
|
+
railties (3.0.3)
|
80
|
+
actionpack (= 3.0.3)
|
81
|
+
activesupport (= 3.0.3)
|
82
|
+
rake (>= 0.8.7)
|
83
|
+
thor (~> 0.14.4)
|
84
|
+
rake (0.8.7)
|
85
|
+
rspec (2.5.0)
|
86
|
+
rspec-core (~> 2.5.0)
|
87
|
+
rspec-expectations (~> 2.5.0)
|
88
|
+
rspec-mocks (~> 2.5.0)
|
89
|
+
rspec-core (2.5.1)
|
90
|
+
rspec-expectations (2.5.0)
|
91
|
+
diff-lcs (~> 1.1.2)
|
92
|
+
rspec-mocks (2.5.0)
|
93
|
+
rspec-rails (2.5.0)
|
94
|
+
actionpack (~> 3.0)
|
95
|
+
activesupport (~> 3.0)
|
96
|
+
railties (~> 3.0)
|
97
|
+
rspec (~> 2.5.0)
|
98
|
+
rubyzip (0.9.4)
|
99
|
+
selenium-webdriver (0.1.2)
|
100
|
+
childprocess (~> 0.1.5)
|
101
|
+
ffi (~> 0.6.3)
|
102
|
+
json_pure
|
103
|
+
rubyzip
|
104
|
+
sqlite3 (1.3.3)
|
105
|
+
thor (0.14.6)
|
106
|
+
treetop (1.4.9)
|
107
|
+
polyglot (>= 0.3.1)
|
108
|
+
tzinfo (0.3.24)
|
109
|
+
webrat (0.7.3)
|
110
|
+
nokogiri (>= 1.2.0)
|
111
|
+
rack (>= 1.0)
|
112
|
+
rack-test (>= 0.5.3)
|
113
|
+
xpath (0.1.3)
|
114
|
+
nokogiri (~> 1.3)
|
115
|
+
|
116
|
+
PLATFORMS
|
117
|
+
ruby
|
118
|
+
|
119
|
+
DEPENDENCIES
|
120
|
+
capybara (>= 0.4.0)
|
121
|
+
jeweler
|
122
|
+
rails (>= 3.0.3)
|
123
|
+
rspec-rails (>= 2.0.0.beta)
|
124
|
+
sqlite3
|
125
|
+
webrat
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alexander Gräfenstein
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,299 @@
|
|
1
|
+
= Fancygrid
|
2
|
+
Fancygrid mades it easy to create and render tables for database records in rails.
|
3
|
+
== Features
|
4
|
+
* ActiveRecord and ActiveResource are supported
|
5
|
+
* Ajax data fetch
|
6
|
+
* Pagination
|
7
|
+
* Simple search with LIKE condition
|
8
|
+
* Complex search with 17 different conditions
|
9
|
+
* Frontend column sorting
|
10
|
+
* View state caching
|
11
|
+
* May be rendered anywhere, not restricted to the index action
|
12
|
+
* Column values may be attributes, methods or even custom blocks
|
13
|
+
* Custom templates for column formatting
|
14
|
+
|
15
|
+
= Requirements
|
16
|
+
* jQuery >= 1.4.2
|
17
|
+
* jQuery-ui (required if column sorting is wanted)
|
18
|
+
* Rails 3
|
19
|
+
* Haml
|
20
|
+
|
21
|
+
= Installation
|
22
|
+
In your gemfile
|
23
|
+
gem 'fancygrid', :git => 'git://github.com/giniedp/fancygrid.git'
|
24
|
+
|
25
|
+
or for specific tag
|
26
|
+
gem 'fancygrid', :git => 'git://github.com/giniedp/fancygrid.git', :tag => "1.0.0-pre"
|
27
|
+
|
28
|
+
Run
|
29
|
+
bundle install
|
30
|
+
|
31
|
+
and
|
32
|
+
rails g fancygrid:install
|
33
|
+
|
34
|
+
then follow the instructions
|
35
|
+
|
36
|
+
= Getting started
|
37
|
+
|
38
|
+
== Basic Setup
|
39
|
+
In any controller in any action you can define a fancygrid for a specific model.
|
40
|
+
A controller is the place where you define what data should be queried from
|
41
|
+
the database and what columns will be visible. For example you could define
|
42
|
+
a table for your users like this:
|
43
|
+
=== Example
|
44
|
+
# UsersController
|
45
|
+
def index
|
46
|
+
# setup fancygrid to display users
|
47
|
+
fancygrid_for :users do |user|
|
48
|
+
|
49
|
+
# specify attributes to display
|
50
|
+
user.attributes( :id, :username, :email )
|
51
|
+
|
52
|
+
# specify the callback url for ajax loading
|
53
|
+
user.url = users_path
|
54
|
+
|
55
|
+
# finally call find with some customized find options
|
56
|
+
user.find( :order => "users.created_at DESC" )
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
In your View you have to render the fancygrid. Use the name that you have used
|
62
|
+
in your controller
|
63
|
+
=== Example
|
64
|
+
# app/views/users/index.html.haml
|
65
|
+
= fancygrid :users
|
66
|
+
|
67
|
+
== Static tables
|
68
|
+
If you dont want to have an ajax table, you can set the data directly without
|
69
|
+
providing a callback url.
|
70
|
+
=== Example
|
71
|
+
def index
|
72
|
+
fancygrid_for :users do |user|
|
73
|
+
|
74
|
+
# ...
|
75
|
+
|
76
|
+
# dont set the url and find options like in the first example
|
77
|
+
# instead set the data directly
|
78
|
+
user.data= User.find(:all)
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
== Table names and model names
|
84
|
+
Usually fancygrid takes the passed name and tries to resolve the models class
|
85
|
+
and its database table name. If you need to use a name that is different
|
86
|
+
from your models name which is the case when you have namespaced models, you can
|
87
|
+
pass the models constant and its table name to fancygrid
|
88
|
+
=== Example
|
89
|
+
def index
|
90
|
+
fancygrid_for :user, Namespace::User, "users" do |user|
|
91
|
+
|
92
|
+
# ...
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
= Using methods on records
|
98
|
+
You are not limited to the models attributes to display in the fancygrid. You can
|
99
|
+
provide method names to display a models properties
|
100
|
+
=== Example
|
101
|
+
def index
|
102
|
+
fancygrid_for :users do |user|
|
103
|
+
|
104
|
+
# ...
|
105
|
+
|
106
|
+
# specify methods to call on each record
|
107
|
+
user.methods(:full_name, :some_other_method)
|
108
|
+
|
109
|
+
# ...
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
You can even pass a proc to a single column
|
115
|
+
=== Example
|
116
|
+
def index
|
117
|
+
fancygrid_for :users do |user|
|
118
|
+
|
119
|
+
# ...
|
120
|
+
|
121
|
+
user.proc( :roles ) do |record|
|
122
|
+
record.roles.map{ |r| r.name }.join(", ")
|
123
|
+
end
|
124
|
+
|
125
|
+
# ...
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
For more complex output you must have to render a column with custom template
|
131
|
+
|
132
|
+
== Rendering columns with templates
|
133
|
+
For custom cell rendering create a template at some place like *app/views/fancygrid/users.html.haml*
|
134
|
+
In your fancygrid definition do:
|
135
|
+
=== Example
|
136
|
+
def index
|
137
|
+
fancygrid_for :users do |user|
|
138
|
+
|
139
|
+
# ...
|
140
|
+
|
141
|
+
# specify cells that will be rendered with custom code
|
142
|
+
user.rendered(:actions)
|
143
|
+
|
144
|
+
# set the templates name
|
145
|
+
user.template = "fancygrid/users"
|
146
|
+
|
147
|
+
# ...
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
In your template you can use the following locals: <tt>table</tt>, <tt>column</tt>, <tt>record</tt> and <tt>value</tt>
|
153
|
+
so you can render your cell like this:
|
154
|
+
=== Example
|
155
|
+
- case table.name
|
156
|
+
- when :users
|
157
|
+
- case column.name
|
158
|
+
- when :actions
|
159
|
+
= link_to "Show", user_path(record)
|
160
|
+
= link_to "Edit", edit_user_path(record)
|
161
|
+
|
162
|
+
== Rendering columns with a haml block
|
163
|
+
In your view you can give a grid a block that should be used for rendering
|
164
|
+
=== Example
|
165
|
+
= fancygrid(:users) do |column, record, value|
|
166
|
+
- case column.name
|
167
|
+
- when :actions
|
168
|
+
= link_to "Show", user_path(record)
|
169
|
+
= link_to "Edit", edit_user_path(record)
|
170
|
+
|
171
|
+
== Display associated data (belongs_to or has_one)
|
172
|
+
To display an associated data you have to build the nodes for that data and
|
173
|
+
specify the include option for the find method
|
174
|
+
=== Example
|
175
|
+
def index
|
176
|
+
fancygrid_for :users do |user|
|
177
|
+
|
178
|
+
# ...
|
179
|
+
|
180
|
+
user.columns_for(:contact) do |contact|
|
181
|
+
contact.attributes( :first_name, :last_name )
|
182
|
+
end
|
183
|
+
|
184
|
+
# ...
|
185
|
+
|
186
|
+
user.find( :include => :contact )
|
187
|
+
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
If your association name is different from the models name pass the model
|
192
|
+
constant into the columns_for method.
|
193
|
+
=== Example
|
194
|
+
def index
|
195
|
+
fancygrid_for :users do |user|
|
196
|
+
|
197
|
+
# ...
|
198
|
+
|
199
|
+
user.columns_for(:work_address, Address) do |address|
|
200
|
+
address.attributes( :street, :zipcode, :city )
|
201
|
+
end
|
202
|
+
|
203
|
+
# ...
|
204
|
+
|
205
|
+
user.find( :include => :work_address )
|
206
|
+
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
== Display associated data (has_many or has_and_belongs_to_many)
|
211
|
+
Similar to the previous example you have to build the nodes for the associations
|
212
|
+
and specify the include option
|
213
|
+
=== Example
|
214
|
+
def index
|
215
|
+
fancygrid_for :users do |user|
|
216
|
+
|
217
|
+
# ...
|
218
|
+
|
219
|
+
user.columns_for(:roles) do |roles|
|
220
|
+
roles.attributes( :name )
|
221
|
+
end
|
222
|
+
|
223
|
+
# ...
|
224
|
+
|
225
|
+
user.find( :unclude => :roles )
|
226
|
+
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
However this would not work as expected. Its the same as calling <tt>user.roles.name</tt>
|
231
|
+
which would call <tt>name</tt> on a collection of roles.
|
232
|
+
|
233
|
+
Instead you should rather define a <tt>proc</tt> to return all role names or
|
234
|
+
render that cell with custom code.
|
235
|
+
=== Example
|
236
|
+
def index
|
237
|
+
fancygrid_for :users do |user|
|
238
|
+
|
239
|
+
# ...
|
240
|
+
|
241
|
+
user.proc( :roles ) do |record|
|
242
|
+
record.roles.map{ |r| r.name }.join(", ")
|
243
|
+
end
|
244
|
+
|
245
|
+
# ...
|
246
|
+
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
== Order your conditions
|
251
|
+
If you have a large condition to make or you want to use a condition that depends on a users role, for example when
|
252
|
+
some of your users are not allowed to see specific data, then you can give the find method a block and use the query generator
|
253
|
+
|
254
|
+
=== Example
|
255
|
+
fancygrid_for :users do |grid|
|
256
|
+
|
257
|
+
# ...
|
258
|
+
|
259
|
+
grid.find do |query|
|
260
|
+
# all the conditions are joined with an AND operator
|
261
|
+
query.conditions(["users.first_name = ?", "some name"])
|
262
|
+
query.conditions(["users.last_name = ?", "some name"])
|
263
|
+
|
264
|
+
# use other finder options as methods
|
265
|
+
query.select #...
|
266
|
+
query.order #...
|
267
|
+
# ...
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
== Caching the view state
|
272
|
+
To make your users life easier you can enable the view state caching. This way
|
273
|
+
the user can search for data, leave the site, come back and have his last
|
274
|
+
search back on screen. Here is an example of how to store the view in the users session:
|
275
|
+
=== Example
|
276
|
+
# ensure that there is a hash in the session
|
277
|
+
session[:users_table_view_state] ||= {}
|
278
|
+
|
279
|
+
fancygrid_for :users do |grid|
|
280
|
+
|
281
|
+
# ...
|
282
|
+
|
283
|
+
# specify a proc to load the view state
|
284
|
+
grid.load_view_proc do |grid_instance|
|
285
|
+
session["fancygrid_users"] || {}
|
286
|
+
end
|
287
|
+
|
288
|
+
# specify a proc to store the view state
|
289
|
+
grid.store_view_proc do |grid_instance, dump|
|
290
|
+
session["fancygrid_users"] = dump
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
Its up to your business logic where and how you store the dumped view state. If you have lots of tables
|
296
|
+
i would recommend to enable database session store.
|
297
|
+
|
298
|
+
= Copyright
|
299
|
+
Copyright (c) 2010 Alexander Graefenstein. See LICENSE for details.
|