wice_grid 3.0.0 → 3.0.1
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/CHANGELOG +9 -0
- data/README.rdoc +18 -2
- data/VERSION +1 -1
- data/lib/wice_grid.rb +13 -11
- data/lib/wice_grid_controller.rb +2 -2
- data/wice_grid.gemspec +2 -2
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
3.0.1
|
2
|
+
|
3
|
+
Fixed the "Cannot modify SafeBuffer in place" problem and thus Rails 3.0.8 and 3.0.9
|
4
|
+
Support for ActiveRecord::Relation
|
5
|
+
|
6
|
+
3.0.0
|
7
|
+
|
8
|
+
Rails 3 support
|
9
|
+
|
1
10
|
0.6
|
2
11
|
|
3
12
|
wice_grid_custom_filter_params used to be a view helper, not it is also accessible from the controller, to be used in cases like redirect_to(my_resource_path(wice_grid_custom_filter_params(...)))
|
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= WiceGrid
|
2
2
|
|
3
|
-
Version:: 3.0.
|
3
|
+
Version:: 3.0.1
|
4
4
|
Author:: Yuri Leikind
|
5
5
|
Homepage:: http://leikind.org/pages/wicegrid
|
6
6
|
Examples online:: http://grid.leikind.org
|
@@ -65,7 +65,7 @@ Rails version 3.0 or newer.
|
|
65
65
|
|
66
66
|
Add the following to your Gemfile:
|
67
67
|
|
68
|
-
gem "wice_grid", '3.0.
|
68
|
+
gem "wice_grid", '3.0.1'
|
69
69
|
|
70
70
|
and run the <tt>bundle</tt> command.
|
71
71
|
|
@@ -128,6 +128,10 @@ Controller:
|
|
128
128
|
|
129
129
|
@tasks_grid = initialize_grid(Task)
|
130
130
|
|
131
|
+
It is also possible to use an ActiveRecord::Relation instance as the first argument:
|
132
|
+
|
133
|
+
@tasks_grid = initialize_grid(Task.where(:active => true))
|
134
|
+
|
131
135
|
View:
|
132
136
|
|
133
137
|
<%= grid(@tasks_grid) do |g|
|
@@ -160,6 +164,8 @@ The return value of the block is the table cell content.
|
|
160
164
|
In the above view code five columns were defined, all without names, no sorting or filtering is available. Still, pagination becomes active if
|
161
165
|
the number of all extracted records exceeds the default number of rows per page.
|
162
166
|
|
167
|
+
|
168
|
+
|
163
169
|
Column names are defined with parameter <tt>:column_name</tt>:
|
164
170
|
|
165
171
|
<%= grid(@tasks_grid) do |g|
|
@@ -324,6 +330,16 @@ with WiceGrid code:
|
|
324
330
|
|
325
331
|
@user_groups_grid = initialize_grid(UserGroup, :conditions => ['portal_application_id = ?', @portal_application])
|
326
332
|
|
333
|
+
Alternatively, instead of a Class object as the first parameter, you can use ActiveRecord::Relation:
|
334
|
+
|
335
|
+
|
336
|
+
@tasks_grid = initialize_grid(Task.
|
337
|
+
where(:archived => false, :projects => {:active => true}).
|
338
|
+
joins(:project)
|
339
|
+
)
|
340
|
+
|
341
|
+
|
342
|
+
Task
|
327
343
|
|
328
344
|
=== Queries with join tables
|
329
345
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.
|
1
|
+
3.0.1
|
data/lib/wice_grid.rb
CHANGED
@@ -62,11 +62,15 @@ module Wice
|
|
62
62
|
|
63
63
|
# core workflow methods START
|
64
64
|
|
65
|
-
def initialize(
|
65
|
+
def initialize(klass_or_relation, controller, opts = {}) #:nodoc:
|
66
66
|
@controller = controller
|
67
67
|
|
68
|
+
@relation = klass_or_relation
|
69
|
+
@klass = klass_or_relation.is_a?(ActiveRecord::Relation) ?
|
70
|
+
klass_or_relation.klass :
|
71
|
+
klass_or_relation
|
68
72
|
|
69
|
-
unless klass.kind_of?(Class) && klass.ancestors.index(ActiveRecord::Base)
|
73
|
+
unless @klass.kind_of?(Class) && @klass.ancestors.index(ActiveRecord::Base)
|
70
74
|
raise WiceGridArgumentError.new("ActiveRecord model class (second argument) must be a Class derived from ActiveRecord::Base")
|
71
75
|
end
|
72
76
|
|
@@ -124,8 +128,6 @@ module Wice
|
|
124
128
|
end
|
125
129
|
raise WiceGridArgumentError.new("name of the grid can only contain alphanumeruc characters") unless @name =~ /^[a-zA-Z\d_]*$/
|
126
130
|
|
127
|
-
@klass = klass
|
128
|
-
|
129
131
|
@table_column_matrix = TableColumnMatrix.new
|
130
132
|
@table_column_matrix.default_model_class = @klass
|
131
133
|
|
@@ -151,7 +153,7 @@ module Wice
|
|
151
153
|
|
152
154
|
@ar_options_formed = false
|
153
155
|
|
154
|
-
@method_scoping = @
|
156
|
+
@method_scoping = @relation.send(:scoped_methods)[-1]
|
155
157
|
end
|
156
158
|
|
157
159
|
# A block executed from within the plugin to process records of the current page.
|
@@ -281,7 +283,7 @@ module Wice
|
|
281
283
|
def read #:nodoc:
|
282
284
|
form_ar_options
|
283
285
|
with_exclusive_scope do
|
284
|
-
@resultset = self.output_csv? ? @
|
286
|
+
@resultset = self.output_csv? ? @relation.find(:all, @ar_options) : @relation.paginate(@ar_options)
|
285
287
|
end
|
286
288
|
invoke_resultset_callbacks
|
287
289
|
end
|
@@ -372,7 +374,7 @@ module Wice
|
|
372
374
|
|
373
375
|
def count #:nodoc:
|
374
376
|
form_ar_options(:skip_ordering => true, :forget_generated_options => true)
|
375
|
-
@
|
377
|
+
@relation.count(:conditions => @ar_options[:conditions], :joins => @ar_options[:joins], :include => @ar_options[:include], :group => @ar_options[:group])
|
376
378
|
end
|
377
379
|
|
378
380
|
alias_method :size, :count
|
@@ -464,7 +466,7 @@ module Wice
|
|
464
466
|
|
465
467
|
def with_exclusive_scope #:nodoc:
|
466
468
|
if @method_scoping
|
467
|
-
@
|
469
|
+
@relation.send(:with_exclusive_scope, @method_scoping) do
|
468
470
|
yield
|
469
471
|
end
|
470
472
|
else
|
@@ -521,7 +523,7 @@ module Wice
|
|
521
523
|
def resultset_without_paging_without_user_filters #:nodoc:
|
522
524
|
form_ar_options
|
523
525
|
with_exclusive_scope do
|
524
|
-
@
|
526
|
+
@relation.find(:all, :joins => @ar_options[:joins],
|
525
527
|
:include => @ar_options[:include],
|
526
528
|
:group => @ar_options[:group],
|
527
529
|
:conditions => @options[:conditions])
|
@@ -531,7 +533,7 @@ module Wice
|
|
531
533
|
def count_resultset_without_paging_without_user_filters #:nodoc:
|
532
534
|
form_ar_options
|
533
535
|
with_exclusive_scope do
|
534
|
-
@
|
536
|
+
@relation.count(
|
535
537
|
:joins => @ar_options[:joins],
|
536
538
|
:include => @ar_options[:include],
|
537
539
|
:group => @ar_options[:group],
|
@@ -544,7 +546,7 @@ module Wice
|
|
544
546
|
def resultset_without_paging_with_user_filters #:nodoc:
|
545
547
|
form_ar_options
|
546
548
|
with_exclusive_scope do
|
547
|
-
@
|
549
|
+
@relation.find(:all, :joins => @ar_options[:joins],
|
548
550
|
:include => @ar_options[:include],
|
549
551
|
:group => @ar_options[:group],
|
550
552
|
:conditions => @ar_options[:conditions],
|
data/lib/wice_grid_controller.rb
CHANGED
@@ -23,7 +23,7 @@ module Wice
|
|
23
23
|
# if in other parameters a column name is mentioned without the name of the table, this table is implied.
|
24
24
|
# Just like in an ordinary ActiveRecord <tt>find</tt> you can use <tt>:joins</tt>, <tt>:include</tt>, and <tt>:conditions</tt>.
|
25
25
|
#
|
26
|
-
# The first parameter is an ActiveRecord class name. The generated ActiveRecord call will use it as the
|
26
|
+
# The first parameter is an ActiveRecord class name or an ActiveRecord::Relation instance. The generated ActiveRecord call will use it as the
|
27
27
|
# receiver of the <tt>paginate</tt> method: <tt>klass.paginate(...)</tt>
|
28
28
|
#
|
29
29
|
# The second parameters is a hash of parameters:
|
@@ -114,7 +114,7 @@ module Wice
|
|
114
114
|
template_name = opts[grid.name] || opts[grid.name.intern]
|
115
115
|
template_name ||= grid.name + '_grid'
|
116
116
|
temp_filename = render_to_string(:partial => template_name)
|
117
|
-
temp_filename.strip
|
117
|
+
temp_filename = temp_filename.strip
|
118
118
|
filename = (grid.csv_file_name || grid.name ) + '.csv'
|
119
119
|
grid.csv_tempfile.close
|
120
120
|
send_file_rails2 temp_filename, :filename => filename, :type => 'text/csv'
|
data/wice_grid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{wice_grid}
|
8
|
-
s.version = "3.0.
|
8
|
+
s.version = "3.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Yuri Leikind"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-03}
|
13
13
|
s.description = %q{A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters }
|
14
14
|
s.email = %q{yuri.leikind@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wice_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.
|
9
|
+
- 1
|
10
|
+
version: 3.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Yuri Leikind
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-03 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|