fancygrid 1.1.0 → 2.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.
Files changed (95) hide show
  1. data/CHANGELOG +9 -2
  2. data/Gemfile +6 -9
  3. data/Gemfile.lock +88 -103
  4. data/README.md +226 -0
  5. data/ROADMAP +0 -1
  6. data/Rakefile +2 -2
  7. data/VERSION +1 -1
  8. data/app/views/fancygrid/controls.html.haml +34 -0
  9. data/app/views/fancygrid/fancygrid.html.haml +18 -0
  10. data/app/views/fancygrid/search.html.haml +24 -0
  11. data/app/views/fancygrid/sort.html.haml +8 -0
  12. data/app/views/fancygrid/table.html.haml +25 -0
  13. data/config/locales/fancygrid.de.yml +17 -19
  14. data/config/locales/fancygrid.en.yml +14 -17
  15. data/fancygrid.gemspec +48 -88
  16. data/lib/assets/javascripts/fancygrid.js +425 -0
  17. data/lib/assets/javascripts/fancygrid.min.js +15 -0
  18. data/lib/assets/stylesheets/fancygrid.css +177 -0
  19. data/lib/fancygrid.rb +63 -44
  20. data/lib/fancygrid/column.rb +165 -0
  21. data/lib/fancygrid/controller/helper.rb +46 -0
  22. data/lib/fancygrid/grid.rb +171 -317
  23. data/lib/fancygrid/node.rb +85 -490
  24. data/lib/fancygrid/object_wrapper.rb +24 -0
  25. data/lib/fancygrid/orm/active_record.rb +39 -0
  26. data/lib/fancygrid/orm/sql_generator.rb +127 -0
  27. data/lib/fancygrid/view/helper.rb +44 -0
  28. data/lib/fancygrid/view_state.rb +161 -0
  29. data/spec/column_spec.rb +29 -0
  30. data/spec/dummy/app/controllers/application_controller.rb +48 -0
  31. data/spec/dummy/app/views/application/index.html.haml +11 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  33. data/spec/dummy/config/application.rb +1 -1
  34. data/spec/dummy/config/environments/development.rb +2 -2
  35. data/spec/dummy/config/environments/test.rb +2 -2
  36. data/spec/dummy/config/routes.rb +3 -2
  37. data/spec/dummy/db/development.sqlite3 +0 -0
  38. data/spec/dummy/db/schema.rb +26 -0
  39. data/spec/dummy/public/javascripts/jquery-1.4.2.js +6240 -0
  40. data/spec/dummy/public/javascripts/jquery-fancygrid.js +425 -0
  41. data/spec/dummy/public/javascripts/jquery-ui.js +41 -0
  42. data/spec/dummy/public/stylesheets/fancygrid.css +183 -0
  43. data/spec/node_spec.rb +79 -301
  44. data/spec/spec_helper.rb +0 -29
  45. data/spec/view_state_spec.rb +91 -0
  46. metadata +124 -137
  47. data/.bundle/config +0 -2
  48. data/README.rdoc +0 -299
  49. data/app/views/fancygrid/_cells.html.haml +0 -13
  50. data/app/views/fancygrid/base/controls.html.haml +0 -40
  51. data/app/views/fancygrid/base/list_frame.html.haml +0 -37
  52. data/app/views/fancygrid/base/search.html.haml +0 -33
  53. data/app/views/fancygrid/base/sort.html.haml +0 -20
  54. data/app/views/fancygrid/base/table_frame.html.haml +0 -45
  55. data/config/initializers/fancygrid.rb +0 -67
  56. data/lib/fancygrid/helper.rb +0 -129
  57. data/lib/fancygrid/query_generator.rb +0 -340
  58. data/lib/fancygrid/view.rb +0 -148
  59. data/lib/generators/install_generator.rb +0 -61
  60. data/lib/generators/views_generator.rb +0 -25
  61. data/lib/version.rb +0 -0
  62. data/public/images/fancygrid/add.png +0 -0
  63. data/public/images/fancygrid/clear.png +0 -0
  64. data/public/images/fancygrid/ddn.png +0 -0
  65. data/public/images/fancygrid/dn.png +0 -0
  66. data/public/images/fancygrid/dots.png +0 -0
  67. data/public/images/fancygrid/loading.gif +0 -0
  68. data/public/images/fancygrid/magnifier.png +0 -0
  69. data/public/images/fancygrid/next.png +0 -0
  70. data/public/images/fancygrid/order.png +0 -0
  71. data/public/images/fancygrid/prev.png +0 -0
  72. data/public/images/fancygrid/reload.png +0 -0
  73. data/public/images/fancygrid/remove.png +0 -0
  74. data/public/images/fancygrid/spacer.gif +0 -0
  75. data/public/images/fancygrid/submit.png +0 -0
  76. data/public/images/fancygrid/th_bg.png +0 -0
  77. data/public/images/fancygrid/up.png +0 -0
  78. data/public/images/fancygrid/uup.png +0 -0
  79. data/public/javascripts/fancygrid.js +0 -477
  80. data/public/javascripts/fancygrid.min.js +0 -17
  81. data/public/stylesheets/fancygrid.css +0 -289
  82. data/public/stylesheets/fancygrid.scss +0 -302
  83. data/spec/dummy/log/development.log +0 -0
  84. data/spec/dummy/log/production.log +0 -0
  85. data/spec/dummy/log/server.log +0 -0
  86. data/spec/dummy/log/test.log +0 -1026
  87. data/spec/dummy/public/javascripts/application.js +0 -2
  88. data/spec/dummy/public/javascripts/controls.js +0 -965
  89. data/spec/dummy/public/javascripts/dragdrop.js +0 -974
  90. data/spec/dummy/public/javascripts/effects.js +0 -1123
  91. data/spec/dummy/public/javascripts/prototype.js +0 -6001
  92. data/spec/dummy/public/javascripts/rails.js +0 -175
  93. data/spec/grid_spec.rb +0 -15
  94. data/spec/integration/navigation_spec.rb +0 -9
  95. data/spec/query_generator_spec.rb +0 -358
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ 2.0.0 - Completely refactored version of fancygrid
2
+ - Better integration in to rails
3
+ - improved fancygrid setup process, less complicated
4
+ - added possibility to implement different ORMs
5
+ - added possibility to use builder and value formatter
6
+ - added "download" feature e.g. to download data in csv, json or xml format
7
+ - improved rails 3.2 asset pipeline compatibility
1
8
  1.0.0 - Added the "ajax_type" option so ajax callbacks are not restricted to GET requests only.
2
9
  - Fixed a js bug that removes the input field focus when doing a simple search
3
10
  BREAKING CHANGES:
@@ -7,8 +14,8 @@
7
14
  - Added new style
8
15
  - Every "js-" prefix in css classes is now "fg-" and stands for 'fancygrid'
9
16
  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
17
+ 0.6.1 - Refactored js and improved leaf sorting
18
+ 0.6.0 - Initial implemetation of leaf sorting feature
12
19
  0.5.1 - Fixed the complex search and improved viewstate caching.
13
20
  0.5.0 - Initial implementation of the complex search.
14
21
  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
data/Gemfile CHANGED
@@ -1,15 +1,12 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- group :development do
4
- gem "rails", ">=3.0.3"
5
- gem "jeweler"
6
- end
3
+ gem "rails"
4
+ gem "haml"
5
+
6
+ group :development, :test do
7
7
 
8
- group :test do
9
- gem "capybara", ">= 0.4.0"
10
- gem "webrat"
11
8
  gem "sqlite3"
12
- gem "rspec-rails", ">= 2.0.0.beta"
9
+ gem "rspec-rails"
10
+ gem "jeweler"
13
11
  end
14
12
 
15
-
data/Gemfile.lock CHANGED
@@ -1,125 +1,110 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
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)
4
+ actionmailer (3.2.0)
5
+ actionpack (= 3.2.0)
6
+ mail (~> 2.4.0)
7
+ actionpack (3.2.0)
8
+ activemodel (= 3.2.0)
9
+ activesupport (= 3.2.0)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.0)
13
+ rack (~> 1.4.0)
14
+ rack-cache (~> 1.1)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.1.2)
17
+ activemodel (3.2.0)
18
+ activesupport (= 3.2.0)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.0)
21
+ activemodel (= 3.2.0)
22
+ activesupport (= 3.2.0)
23
+ arel (~> 3.0.0)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.0)
26
+ activemodel (= 3.2.0)
27
+ activesupport (= 3.2.0)
28
+ activesupport (3.2.0)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.0)
33
+ diff-lcs (1.1.3)
34
+ erubis (2.7.0)
51
35
  git (1.2.5)
52
- i18n (0.5.0)
53
- jeweler (1.5.2)
54
- bundler (~> 1.0.0)
36
+ haml (3.1.4)
37
+ hike (1.2.1)
38
+ i18n (0.6.0)
39
+ jeweler (1.6.4)
40
+ bundler (~> 1.0)
55
41
  git (>= 1.2.5)
56
42
  rake
57
- json_pure (1.5.1)
58
- mail (2.2.15)
59
- activesupport (>= 2.3.6)
43
+ journey (1.0.3)
44
+ json (1.6.5)
45
+ mail (2.4.1)
60
46
  i18n (>= 0.4.0)
61
47
  mime-types (~> 1.16)
62
48
  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)
49
+ mime-types (1.17.2)
50
+ multi_json (1.1.0)
51
+ polyglot (0.3.3)
52
+ rack (1.4.1)
53
+ rack-cache (1.1)
54
+ rack (>= 0.4)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.1)
70
58
  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)
59
+ rails (3.2.0)
60
+ actionmailer (= 3.2.0)
61
+ actionpack (= 3.2.0)
62
+ activerecord (= 3.2.0)
63
+ activeresource (= 3.2.0)
64
+ activesupport (= 3.2.0)
77
65
  bundler (~> 1.0)
78
- railties (= 3.0.3)
79
- railties (3.0.3)
80
- actionpack (= 3.0.3)
81
- activesupport (= 3.0.3)
66
+ railties (= 3.2.0)
67
+ railties (3.2.0)
68
+ actionpack (= 3.2.0)
69
+ activesupport (= 3.2.0)
70
+ rack-ssl (~> 1.3.2)
82
71
  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)
72
+ rdoc (~> 3.4)
73
+ thor (~> 0.14.6)
74
+ rake (0.9.2.2)
75
+ rdoc (3.12)
76
+ json (~> 1.4)
77
+ rspec (2.8.0)
78
+ rspec-core (~> 2.8.0)
79
+ rspec-expectations (~> 2.8.0)
80
+ rspec-mocks (~> 2.8.0)
81
+ rspec-core (2.8.0)
82
+ rspec-expectations (2.8.0)
91
83
  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)
84
+ rspec-mocks (2.8.0)
85
+ rspec-rails (2.8.1)
86
+ actionpack (>= 3.0)
87
+ activesupport (>= 3.0)
88
+ railties (>= 3.0)
89
+ rspec (~> 2.8.0)
90
+ sprockets (2.1.2)
91
+ hike (~> 1.2)
92
+ rack (~> 1.0)
93
+ tilt (~> 1.1, != 1.3.0)
94
+ sqlite3 (1.3.5)
105
95
  thor (0.14.6)
106
- treetop (1.4.9)
96
+ tilt (1.3.3)
97
+ treetop (1.4.10)
98
+ polyglot
107
99
  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)
100
+ tzinfo (0.3.31)
115
101
 
116
102
  PLATFORMS
117
103
  ruby
118
104
 
119
105
  DEPENDENCIES
120
- capybara (>= 0.4.0)
106
+ haml
121
107
  jeweler
122
- rails (>= 3.0.3)
123
- rspec-rails (>= 2.0.0.beta)
108
+ rails
109
+ rspec-rails
124
110
  sqlite3
125
- webrat
data/README.md ADDED
@@ -0,0 +1,226 @@
1
+ ## Fancygrid
2
+ Fancygrid mades it easy to create and render tables for database records in rails.
3
+ ### Features
4
+ * Ajax data fetch
5
+ * Pagination
6
+ * Simple search
7
+ * Complex search with 17 different conditions
8
+ * Column sorting
9
+ * View state caching
10
+ * ActiveRecord supported. MongoDB coming (some day).
11
+ * Column values from attributes, methods, method chains or even custom blocks
12
+
13
+ ### Requirements
14
+ * jQuery >= 1.4.2
15
+ * jQuery-ui (required if column sorting is wanted)
16
+ * Rails 3
17
+ * Haml
18
+
19
+ ### Installation
20
+ In your gemfile
21
+ ```ruby
22
+ gem 'fancygrid'
23
+ ```
24
+ Run
25
+ ```console
26
+ bundle install
27
+ ```
28
+
29
+ If you use Rails3 with asset pipeline enabled, you can just require the javascript and css
30
+ ```
31
+ // = require fancygrid
32
+ ```
33
+ If your asset pipeline is disabled, you have to copy the assets from the gems lib directory. There is no generator for this task.
34
+
35
+ ## Getting started
36
+
37
+ ### Basic Setup
38
+ In any controller in any action you can define a fancygrid for a specific model.
39
+ Here is an example for a simple table for the Users model:
40
+ ```ruby
41
+ # UsersController
42
+ def index
43
+
44
+ fancygrid_for :users do |g|
45
+ # specify attributes to display
46
+ g.attributes :id, :username, :email
47
+ # specify the callback url for ajax loading
48
+ g.ajax_url = users_path
49
+ # finally call find to query the data
50
+ g.find
51
+ end
52
+ end
53
+ ```
54
+
55
+ To render the fancygrid in the view, use the same name that you passed in the setup
56
+ ```haml
57
+ # app/views/users/index.html.haml
58
+ = fancygrid :users
59
+ ```
60
+
61
+ ### Static tables
62
+ If you dont want to have an ajax table, dont specify the ajax_url. The data will be
63
+ queried and the table will be rendered without pagination.
64
+ ```ruby
65
+ def index
66
+ fancygrid_for :users do |g|
67
+ # ...
68
+ g.attributes :id, :username, :email
69
+ # don't set the ajax_url and just call find
70
+ g.find
71
+ end
72
+ end
73
+ ```
74
+
75
+ ### Table names and model names
76
+ Usually fancygrid tries to resolve the models class and table name from given
77
+ name. If you happen to use namespaced models, you must pass the class as an option.
78
+ ```ruby
79
+ def index
80
+ fancygrid_for :user, :class => Namespace::User do |g|
81
+ # ...
82
+ end
83
+ end
84
+ ```
85
+
86
+ Optionally you can also pass a specific table name. However, if the class responds
87
+ to #table_name, this is not necessary.
88
+ ```ruby
89
+ def index
90
+ fancygrid_for :user, :class => Namespace::User, :table_name => "users" do |g|
91
+ # ...
92
+ end
93
+ end
94
+ ```
95
+
96
+ ## Define columns
97
+ To display attributes as columns use the #attributes method for setup like this:
98
+ ```ruby
99
+ def index
100
+ fancygrid_for :users do |g|
101
+ # ...
102
+ g.attributes :id, :email, :created_at
103
+ # ...
104
+ end
105
+ end
106
+ ```
107
+
108
+ For everything else use the #columns method. You can have method names,
109
+ method chains and procs to resolve column values.
110
+ ```ruby
111
+ def index
112
+ fancygrid_for :users do |g|
113
+ # ...
114
+ # methods
115
+ g.columns :full_name, :some_other_method
116
+ # method chains
117
+ g.columns "orders.count"
118
+ # procs
119
+ g.columns :roles do |record|
120
+ record.roles.map(&:name).join(", ")
121
+ end
122
+ # ...
123
+ end
124
+ end
125
+ ```
126
+ For more complex output you have to format the cell value in the view or a formatter method.
127
+
128
+ ## Columns formatting
129
+ Add a block to the fancygrid call in the view. In there you can use a switch condition
130
+ on the columns name to determine what to render. Do not forget to add the else case to
131
+ render all unformatted values.
132
+ ```haml
133
+ = fancygrid :users do |column, record, value|
134
+ - case column.name
135
+ - when :actions
136
+ = link_to "Show", user_path(record)
137
+ = link_to "Edit", edit_user_path(record)
138
+ - else
139
+ / this else case is important
140
+ = value
141
+ ```
142
+
143
+ ## belongs_to or has_one associations
144
+ To define columns for associations, use the #columns_for method.
145
+ ```ruby
146
+ def index
147
+ fancygrid_for :users do |g|
148
+ # ...
149
+ g.columns_for :contact do |contact|
150
+ contact.attributes :first_name, :last_name
151
+ end
152
+ # ...
153
+ g.find do |query|
154
+ # eager loading of the association
155
+ query.select :contact_id
156
+ query.includes :contact
157
+ end
158
+ end
159
+ end
160
+ ```
161
+ Mention that in the query block the contact_id is selected. This is required, since fancygrid
162
+ tries to use optimized sql queries by default. Therefore it will select only those attributes
163
+ that have been used during the fancygrid setup. If the contact_id is missing, it will not be
164
+ possible to include the contact association.
165
+
166
+ If your association name is different from the models name, pass the model
167
+ class as option.
168
+ ```ruby
169
+ def index
170
+ fancygrid_for :users do |g|
171
+ # ...
172
+ g.columns_for :invoice_address, :class => Address do |adr|
173
+ adr.attributes :street, :zipcode, :city
174
+ end
175
+ # ...
176
+ end
177
+ end
178
+ ```
179
+
180
+ ## has_many or has_and_belongs_to_many associations
181
+ If you have Users that has_many Orders, you should rather define a fancygrid
182
+ for the Orders than for Users. However, if it must be a Users table and
183
+ you want to search on the associations attributes, you can do that:
184
+
185
+ ```ruby
186
+ def index
187
+ fancygrid_for :users do |g|
188
+ # ...
189
+ g.columns_for :roles do |roles|
190
+ roles.attributes :name
191
+ end
192
+ # ...
193
+ end
194
+ end
195
+ ```
196
+
197
+ The definition is valid, and you can already search for users with a specific
198
+ role. But nothing is going to be rendered in the roles.name column. This is
199
+ because roles is a collection of records, and not a single record. You can now
200
+ format the column in the view like this
201
+
202
+ ```haml
203
+ = fancygrid :users do |column, record, value|
204
+ - case column.identifier
205
+ - when "roles.name"
206
+ = record.roles.map(&:name).join("|")
207
+ - else
208
+ = value
209
+ ```
210
+
211
+ Here the column identifier is used to identify the column. This is useful
212
+ if you have more columns that are named the same.
213
+
214
+ ## Caching the view state
215
+ To make your users life easier you can enable the view state caching. This way
216
+ the user can search for data, leave the site, come back and have his last
217
+ search back on screen.
218
+ ```ruby
219
+ def index
220
+ fancygrid_for :users, :persist => true do |grid|
221
+ # ...
222
+ end
223
+ end
224
+ ```
225
+ ## Copyright
226
+ Copyright (c) 2010 Alexander Graefenstein. See LICENSE for details.