wice_grid 3.2.0.pre1 → 3.2.0.pre2
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/README.rdoc +28 -38
- data/RELEASE_NOTES_3.2.pre2.rdoc +6 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/app/views/kaminari/wice_grid/_gap.html.haml +2 -0
- data/app/views/kaminari/wice_grid/_next_page.html.haml +9 -0
- data/app/views/kaminari/wice_grid/_page.html.haml +10 -0
- data/app/views/kaminari/wice_grid/_paginator.html.haml +17 -0
- data/app/views/kaminari/wice_grid/_prev_page.html.haml +9 -0
- data/lib/grid_output_buffer.rb +1 -13
- data/lib/grid_renderer.rb +8 -8
- data/lib/helpers/wice_grid_misc_view_helpers.rb +2 -1
- data/lib/helpers/wice_grid_view_helpers.rb +110 -99
- data/lib/kaminari_monkey_patching.rb +13 -0
- data/lib/view_columns/action_view_column.rb +1 -1
- data/lib/view_columns/view_column_custom_dropdown.rb +2 -3
- data/lib/wice_grid.rb +23 -12
- data/lib/wice_grid_core_ext.rb +91 -118
- data/wice_grid.gemspec +12 -6
- metadata +13 -7
- data/lib/will_paginate_paginator.rb +0 -31
data/README.rdoc
CHANGED
@@ -994,30 +994,33 @@ If you need to disable the default export icon in the grid, add
|
|
994
994
|
|
995
995
|
=== Detached Filters
|
996
996
|
|
997
|
-
|
998
|
-
To do so, use parameter <tt>:detach_with_id</tt> for a column whose filter needs to
|
999
|
-
be detached, with an arbitrary string or a symbol value which will be used
|
1000
|
-
later to identify the filter. As soon as there is one column with
|
1001
|
-
<tt>:detach_with_id</tt>, the behavior of the +grid+ helper changes - it
|
1002
|
-
becomes an <i>initializer</i> of the grid and doesn't output any HTML code.
|
1003
|
-
To render the grid, use <tt>grid</tt> for the second time without the block.
|
1004
|
-
To render a detached output filter, use helper <tt>grid_filter(grid_object, detached_filter_key)</tt>:
|
1005
|
-
|
1006
|
-
<%= grid(@tasks_grid, :show_filters => :always) do |g|
|
1007
|
-
|
1008
|
-
g.column :name => 'Title', :attribute => 'title', :detach_with_id => :title_filter do |task|
|
1009
|
-
link_to('Edit', edit_task_path(task.title))
|
1010
|
-
end
|
997
|
+
Filters can also be detached from the grid table and placed anywhere on page.
|
1011
998
|
|
1012
|
-
|
1013
|
-
task.archived? ? 'Yes' : 'No'
|
1014
|
-
end
|
999
|
+
This is a 3-step process.
|
1015
1000
|
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1001
|
+
First, define the grid with helper +define_grid+ instead of +grid+.
|
1002
|
+
Everything should be done the same way as with +grid+, but every column which will have an external filter,
|
1003
|
+
add <tt>:detach_with_id => :some_filter_name+</tt> in the column definition. The value of +:detach_with_id+ is an arbitrary string
|
1004
|
+
or a symbol value which will be used later to identify the filter.
|
1005
|
+
|
1006
|
+
<%= define_grid(@tasks_grid, :show_filters => :always) do |g|
|
1007
|
+
|
1008
|
+
g.column :name => 'Title', :attribute => 'title', :detach_with_id => :title_filter do |task|
|
1009
|
+
link_to('Edit', edit_task_path(task.title))
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
g.column :name => 'Archived', :attribute => 'archived', :detach_with_id => :archived_filter do |task|
|
1013
|
+
task.archived? ? 'Yes' : 'No'
|
1014
|
+
end
|
1019
1015
|
|
1020
|
-
|
1016
|
+
g.column :name => 'Added', :attribute => 'created_at', :detach_with_id => :created_at_filter do |task|
|
1017
|
+
task.created_at.to_s(:short)
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
end -%>
|
1021
|
+
|
1022
|
+
|
1023
|
+
Then, use <tt>grid_filter(grid, :some_filter_name)</tt> to render filters:
|
1021
1024
|
|
1022
1025
|
<% # rendering filter with key :title_filter %>
|
1023
1026
|
<%= grid_filter @tasks_grid, :title_filter %>
|
@@ -1031,34 +1034,21 @@ end -%>
|
|
1031
1034
|
<% # Rendering the grid body %>
|
1032
1035
|
<%= grid(@tasks_grid) %>
|
1033
1036
|
|
1034
|
-
|
1035
|
-
|
1037
|
+
|
1038
|
+
Finally, use <tt>render_grid(@grid)</tt> to actually output the grid table .
|
1039
|
+
|
1036
1040
|
|
1037
1041
|
Using custom submit and reset buttons together with <tt>:hide_submit_button => true</tt>
|
1038
|
-
|
1042
|
+
and <tt>:hide_reset_button => true</tt>
|
1039
1043
|
allows to completely get rid
|
1040
1044
|
of the default filter row and the default icons (see section 'Submit/Reset Buttons').
|
1041
1045
|
|
1042
|
-
For CSV export will continue functioning, just make sure the first call to +grid+
|
1043
|
-
is still in the template of its own and
|
1044
|
-
is inside of <tt><%= %></tt>, because when CSV is requested, the first +grid+ works
|
1045
|
-
in the old fashioned way producing CSV formatted output.
|
1046
1046
|
|
1047
1047
|
If a column was declared with <tt>:detach_with_id</tt>, but never output with +grid_filter+,
|
1048
1048
|
filtering the grid in development mode will result
|
1049
1049
|
in an warning javascript message and the missing filter will be ignored.
|
1050
1050
|
There is no such message in production.
|
1051
1051
|
|
1052
|
-
<tt>grid</tt> parameter <tt>:show_filter</tt> must not be set to <tt>:no</tt> for detached filters to work.
|
1053
|
-
|
1054
|
-
==== How Does It Work? (For the interested)
|
1055
|
-
|
1056
|
-
When there is at least one column with <tt>:detach_with_id</tt>, the generated HTML code is
|
1057
|
-
stored in a buffer, code for detached filters is stored
|
1058
|
-
in buffers of their own identified by the given IDs, and nothing is returned to the view.
|
1059
|
-
When the helper is called for the second time, the buffer outputs its content.
|
1060
|
-
In a similar fashion, the +grid_filter+ helper outputs buffers for filters.
|
1061
|
-
|
1062
1052
|
|
1063
1053
|
|
1064
1054
|
=== Access to Records From Outside The Grid
|
@@ -0,0 +1,6 @@
|
|
1
|
+
1. +will_paginate+ is replaced by +kaminari+.
|
2
|
+
2. The detached filter API has changed. No more magical invocation of the +grid+ helper two times.
|
3
|
+
First, +define_grid+ is used in the same way as +grid+, then +grid_filter+,
|
4
|
+
and then <tt>render_grid(@grid)</tt> to actually output the grid table .
|
5
|
+
3. No more polluting core Ruby classes like Hash and Array with methods. All such methods
|
6
|
+
are now private to the plugin.
|
data/Rakefile
CHANGED
@@ -34,7 +34,7 @@ begin
|
|
34
34
|
gem.email = "yuri.leikind@gmail.com"
|
35
35
|
gem.homepage = "http://github.com/lekind/wice_grid"
|
36
36
|
gem.authors = ["Yuri Leikind"]
|
37
|
-
gem.
|
37
|
+
gem.add_dependency "kaminari", ">= 0.13.0"
|
38
38
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
39
39
|
end
|
40
40
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.2.0.
|
1
|
+
3.2.0.pre2
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "Next" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the next page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%li
|
9
|
+
= link_to_unless current_page.last?, ::Wice::NlMessage['next_label'], url, :rel => 'next', :remote => remote
|
@@ -0,0 +1,10 @@
|
|
1
|
+
-# Link showing page number
|
2
|
+
-# available local variables
|
3
|
+
-# page: a page object for "this" page
|
4
|
+
-# url: url to this page
|
5
|
+
-# current_page: a page object for the currently displayed page
|
6
|
+
-# total_pages: total number of pages
|
7
|
+
-# per_page: number of items to fetch per page
|
8
|
+
-# remote: data-remote
|
9
|
+
%li{:class => page.current? ? 'active' : nil}
|
10
|
+
= link_to page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
-# The container tag
|
2
|
+
-# available local variables
|
3
|
+
-# current_page: a page object for the currently displayed page
|
4
|
+
-# total_pages: total number of pages
|
5
|
+
-# per_page: number of items to fetch per page
|
6
|
+
-# remote: data-remote
|
7
|
+
-# paginator: the paginator that renders the pagination tags inside
|
8
|
+
= paginator.render do
|
9
|
+
.pagination
|
10
|
+
%ul
|
11
|
+
= prev_page_tag unless current_page.first?
|
12
|
+
- each_page do |page|
|
13
|
+
- if page.left_outer? || page.right_outer? || page.inside_window?
|
14
|
+
= page_tag page
|
15
|
+
- elsif !page.was_truncated?
|
16
|
+
= gap_tag
|
17
|
+
= next_page_tag unless current_page.last?
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-# Link to the "Previous" page
|
2
|
+
-# available local variables
|
3
|
+
-# url: url to the previous page
|
4
|
+
-# current_page: a page object for the currently displayed page
|
5
|
+
-# total_pages: total number of pages
|
6
|
+
-# per_page: number of items to fetch per page
|
7
|
+
-# remote: data-remote
|
8
|
+
%li
|
9
|
+
= link_to_unless current_page.first?, ::Wice::NlMessage['previous_label'], url, :rel => 'prev', :remote => remote
|
data/lib/grid_output_buffer.rb
CHANGED
@@ -3,27 +3,15 @@ module Wice
|
|
3
3
|
|
4
4
|
class GridOutputBuffer < String #:nodoc:
|
5
5
|
|
6
|
-
attr_reader :stubborn_output_mode
|
7
6
|
attr_accessor :return_empty_strings_for_nonexistent_filters
|
8
7
|
|
9
|
-
def stubborn_output_mode=(m)
|
10
|
-
@stubborn_output_mode = m
|
11
|
-
end
|
12
|
-
|
13
8
|
def initialize(*attrs)
|
14
9
|
super(*attrs)
|
15
10
|
@filters = HashWithIndifferentAccess.new
|
16
|
-
@first_output = false
|
17
|
-
@stubborn_output_mode = false
|
18
11
|
end
|
19
12
|
|
20
13
|
def to_s
|
21
|
-
|
22
|
-
super.html_safe_if_necessary
|
23
|
-
else
|
24
|
-
@first_output = true
|
25
|
-
''
|
26
|
-
end
|
14
|
+
super.html_safe
|
27
15
|
end
|
28
16
|
|
29
17
|
def add_filter(detach_with_id, filter_code)
|
data/lib/grid_renderer.rb
CHANGED
@@ -296,7 +296,7 @@ module Wice
|
|
296
296
|
end
|
297
297
|
|
298
298
|
if options[:class]
|
299
|
-
options[:html]
|
299
|
+
Wice::WgHash.add_or_append_class_value!(options[:html], options[:class])
|
300
300
|
options.delete(:class)
|
301
301
|
end
|
302
302
|
|
@@ -333,13 +333,13 @@ module Wice
|
|
333
333
|
elsif options[:custom_filter].class == Array
|
334
334
|
if options[:custom_filter].empty?
|
335
335
|
[]
|
336
|
-
elsif options[:custom_filter]
|
336
|
+
elsif Wice::WgEnumerable.all_items_are_of_class(options[:custom_filter], Symbol)
|
337
337
|
lambda{ @grid.distinct_values_for_column_in_resultset(options[:custom_filter]) }
|
338
338
|
|
339
|
-
elsif options[:custom_filter]
|
339
|
+
elsif Wice::WgEnumerable.all_items_are_of_class(options[:custom_filter], String) || WgEnumerable.all_items_are_of_class(options[:custom_filter], Numeric)
|
340
340
|
options[:custom_filter].map{|i| [i,i]}
|
341
341
|
|
342
|
-
elsif options[:custom_filter]
|
342
|
+
elsif Wice::WgEnumerable.all_items_are_of_class(options[:custom_filter], Array)
|
343
343
|
options[:custom_filter]
|
344
344
|
else
|
345
345
|
raise WiceGridArgumentError.new(
|
@@ -436,7 +436,7 @@ module Wice
|
|
436
436
|
end
|
437
437
|
|
438
438
|
def base_link_for_filter(controller, extra_parameters = {}) #:nodoc:
|
439
|
-
new_params = controller.params
|
439
|
+
new_params = Wice::WgHash.deep_clone controller.params
|
440
440
|
new_params.merge!(extra_parameters)
|
441
441
|
|
442
442
|
if new_params[@grid.name]
|
@@ -458,7 +458,7 @@ module Wice
|
|
458
458
|
|
459
459
|
|
460
460
|
def link_for_export(controller, format, extra_parameters = {}) #:nodoc:
|
461
|
-
new_params = controller.params
|
461
|
+
new_params = Wice::WgHash.deep_clone controller.params
|
462
462
|
new_params.merge!(extra_parameters)
|
463
463
|
|
464
464
|
new_params[@grid.name] = {} unless new_params[@grid.name]
|
@@ -482,14 +482,14 @@ module Wice
|
|
482
482
|
@@order_direction_parameter_name => direction
|
483
483
|
}}
|
484
484
|
|
485
|
-
cleaned_params = params
|
485
|
+
cleaned_params = Wice::WgHash.deep_clone params
|
486
486
|
cleaned_params.merge!(extra_parameters)
|
487
487
|
|
488
488
|
cleaned_params.delete(:controller)
|
489
489
|
cleaned_params.delete(:action)
|
490
490
|
|
491
491
|
|
492
|
-
query_params =
|
492
|
+
query_params = Wice::WgHash.rec_merge(cleaned_params, query_params)
|
493
493
|
|
494
494
|
'?' + query_params.to_query
|
495
495
|
end
|
@@ -14,7 +14,8 @@ module Wice
|
|
14
14
|
|
15
15
|
grid.get_state_as_parameter_value_pairs(true).collect{|param_name, value|
|
16
16
|
hidden_field_tag(param_name, value, :id => "hidden-#{param_name.gsub(/[\[\]]/, '-')}")
|
17
|
-
}.join("\n").
|
17
|
+
}.join("\n").html_safe
|
18
|
+
|
18
19
|
end
|
19
20
|
|
20
21
|
def dump_state(grid) #:nodoc:
|
@@ -70,20 +70,23 @@ module Wice
|
|
70
70
|
# Pease read documentation about the +column+ method to achieve the enlightenment.
|
71
71
|
|
72
72
|
def grid(grid, opts = {}, &block)
|
73
|
+
raise WiceGridArgumentError.new('Missing block for the grid helper.' +
|
74
|
+
' For detached filters use first define_grid with the same API as grid, ' +
|
75
|
+
'then grid_filter to add filters, and then render_grid to actually show the grid' ) if block.nil?
|
76
|
+
define_grid(grid, opts, &block)
|
77
|
+
render_grid(grid)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Has the same parameters as <tt>grid</tt> but does not output the grid. After <tt>define_grid</tt>
|
81
|
+
# <tt>render_grid</tt> can be used to output the grid HTML code.
|
82
|
+
# Usually used with detached filters: first <tt>define_grid</tt>, then <tt>grid_filter</tt>s, and then
|
83
|
+
# <tt>render_grid</tt>
|
84
|
+
def define_grid(grid, opts = {}, &block)
|
73
85
|
# strip the method from HTML stuff
|
74
86
|
unless grid.class == WiceGrid
|
75
87
|
raise WiceGridArgumentError.new("The first argument for the grid helper must be an instance of the WiceGrid class")
|
76
88
|
end
|
77
89
|
|
78
|
-
if grid.output_buffer
|
79
|
-
if grid.output_buffer == true
|
80
|
-
raise WiceGridException.new("Second occurence of grid helper with the same grid object. " +
|
81
|
-
"Did you intend to use detached filters and forget to define them?")
|
82
|
-
else
|
83
|
-
return grid.output_buffer
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
90
|
options = {
|
88
91
|
:allow_showing_all_records => Defaults::ALLOW_SHOWING_ALL_QUERIES,
|
89
92
|
:class => nil,
|
@@ -114,25 +117,39 @@ module Wice
|
|
114
117
|
Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS && rendering.last_column_for_html.capable_of_hosting_filter_related_icons?
|
115
118
|
|
116
119
|
if grid.output_csv?
|
117
|
-
|
120
|
+
grid_csv(grid, rendering)
|
118
121
|
else
|
119
122
|
# If blank_slate is defined we don't show any grid at all
|
120
123
|
if rendering.blank_slate_handler && grid.resultset.size == 0 && ! grid.filtering_on?
|
121
|
-
|
122
|
-
|
124
|
+
generate_blank_slate(grid, rendering)
|
125
|
+
else
|
126
|
+
grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons)
|
123
127
|
end
|
124
|
-
|
125
|
-
content = grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons)
|
126
128
|
end
|
127
129
|
|
128
130
|
grid.view_helper_finished = true
|
129
|
-
|
131
|
+
|
132
|
+
grid.csv_tempfile ? grid.csv_tempfile.path : nil
|
133
|
+
end
|
134
|
+
|
135
|
+
# Used after <tt>define_grid</tt> to actually output the grid HTML code.
|
136
|
+
# Usually used with detached filters: first <tt>define_grid</tt>, then <tt>grid_filter</tt>s, and then
|
137
|
+
# <tt>render_grid</tt>
|
138
|
+
def render_grid(grid)
|
139
|
+
if grid.output_buffer
|
140
|
+
grid.output_buffer
|
141
|
+
elsif grid.csv_tempfile
|
142
|
+
grid.csv_tempfile.path
|
143
|
+
else
|
144
|
+
raise WiceGridException.new("Attempt to use 'render_grid' without 'define_grid' before.")
|
145
|
+
end
|
130
146
|
end
|
131
147
|
|
148
|
+
|
132
149
|
def generate_blank_slate(grid, rendering) #:nodoc:
|
133
|
-
|
150
|
+
grid.output_buffer = GridOutputBuffer.new
|
134
151
|
|
135
|
-
|
152
|
+
grid.output_buffer << if rendering.blank_slate_handler.is_a?(Proc)
|
136
153
|
call_block(rendering.blank_slate_handler, nil)
|
137
154
|
elsif rendering.blank_slate_handler.is_a?(Hash)
|
138
155
|
render(rendering.blank_slate_handler)
|
@@ -141,11 +158,8 @@ module Wice
|
|
141
158
|
end
|
142
159
|
|
143
160
|
if rendering.find_one_for(:in_html){|column| column.detach_with_id}
|
144
|
-
|
145
|
-
buff.return_empty_strings_for_nonexistent_filters = true
|
146
|
-
grid.output_buffer = buff
|
161
|
+
grid.output_buffer.return_empty_strings_for_nonexistent_filters = true
|
147
162
|
end
|
148
|
-
buff
|
149
163
|
end
|
150
164
|
|
151
165
|
def call_block(block, ar, extra_argument = nil) #:nodoc:
|
@@ -157,32 +171,31 @@ module Wice
|
|
157
171
|
|
158
172
|
table_html_attrs, header_tr_html = options[:html], options[:header_tr_html]
|
159
173
|
|
160
|
-
|
174
|
+
Wice::WgHash.add_or_append_class_value!(table_html_attrs, 'wice-grid', true)
|
161
175
|
|
162
176
|
if Array === Defaults::DEFAULT_TABLE_CLASSES
|
163
177
|
Defaults::DEFAULT_TABLE_CLASSES.each do |default_class|
|
164
|
-
|
178
|
+
Wice::WgHash.add_or_append_class_value!(table_html_attrs, default_class, true)
|
165
179
|
end
|
166
180
|
end
|
167
181
|
|
168
182
|
if options[:class]
|
169
|
-
|
183
|
+
Wice::WgHash.add_or_append_class_value!(table_html_attrs, options[:class])
|
170
184
|
options.delete(:class)
|
171
185
|
end
|
172
186
|
|
173
|
-
|
174
|
-
|
175
187
|
cycle_class = nil
|
176
188
|
sorting_dependant_row_cycling = options[:sorting_dependant_row_cycling]
|
177
189
|
|
178
|
-
|
190
|
+
grid.output_buffer = GridOutputBuffer.new
|
191
|
+
|
179
192
|
# Ruby 1.9.x
|
180
|
-
|
193
|
+
grid.output_buffer.force_encoding('UTF-8') if grid.output_buffer.respond_to?(:force_encoding)
|
181
194
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
195
|
+
grid.output_buffer << %!<div class="wice-grid-container" id="#{grid.name}"><div id="#{grid.name}_title">!
|
196
|
+
grid.output_buffer << content_tag(:h3, grid.saved_query.name) if grid.saved_query
|
197
|
+
grid.output_buffer << "</div><table #{tag_options(table_html_attrs, true)}>"
|
198
|
+
grid.output_buffer << "<thead>"
|
186
199
|
|
187
200
|
no_filters_at_all = (options[:show_filters] == :no || rendering.no_filter_needed?) ? true: false
|
188
201
|
|
@@ -201,7 +214,7 @@ module Wice
|
|
201
214
|
|
202
215
|
pagination_panel_content_html, pagination_panel_content_js = nil, nil
|
203
216
|
if options[:upper_pagination_panel]
|
204
|
-
|
217
|
+
grid.output_buffer << rendering.pagination_panel(number_of_columns, options[:hide_csv_button]) do
|
205
218
|
pagination_panel_content_html =
|
206
219
|
pagination_panel_content(grid, options[:extra_request_parameters], options[:allow_showing_all_records])
|
207
220
|
pagination_panel_content_html
|
@@ -209,9 +222,9 @@ module Wice
|
|
209
222
|
end
|
210
223
|
|
211
224
|
title_row_attrs = header_tr_html.clone
|
212
|
-
|
225
|
+
Wice::WgHash.add_or_append_class_value!(title_row_attrs, 'wice-grid-title-row', true)
|
213
226
|
|
214
|
-
|
227
|
+
grid.output_buffer << %!<tr #{tag_options(title_row_attrs, true)}>!
|
215
228
|
|
216
229
|
filter_row_id = grid.name + '_filter_row'
|
217
230
|
|
@@ -243,86 +256,82 @@ module Wice
|
|
243
256
|
column_name,
|
244
257
|
rendering.column_link(column, direction, params, options[:extra_request_parameters]),
|
245
258
|
:class => link_style)
|
246
|
-
|
259
|
+
grid.output_buffer << content_tag(:th, col_link, Wice::WgHash.make_hash(:class, css_class))
|
247
260
|
column.css_class = css_class
|
248
261
|
else
|
249
262
|
if reuse_last_column_for_filter_buttons && last
|
250
|
-
|
263
|
+
grid.output_buffer << content_tag(:th,
|
251
264
|
hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering)
|
252
265
|
)
|
253
266
|
else
|
254
|
-
|
267
|
+
grid.output_buffer << content_tag(:th, column_name)
|
255
268
|
end
|
256
269
|
end
|
257
270
|
end
|
258
271
|
|
259
|
-
|
272
|
+
grid.output_buffer << content_tag(:th,
|
260
273
|
hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering)
|
261
274
|
) unless no_rightmost_column
|
262
275
|
|
263
|
-
|
276
|
+
grid.output_buffer << '</tr>'
|
264
277
|
# rendering first row end
|
265
278
|
|
266
279
|
|
267
280
|
unless no_filters_at_all # there are filters, we don't know where, in the table or detached
|
268
281
|
if no_filter_row # they are all detached
|
269
|
-
content.stubborn_output_mode = true
|
270
282
|
rendering.each_column(:in_html) do |column|
|
271
283
|
if column.filter_shown?
|
272
|
-
filter_html_code = column.render_filter
|
273
|
-
|
274
|
-
content.add_filter(column.detach_with_id, filter_html_code)
|
284
|
+
filter_html_code = column.render_filter.html_safe
|
285
|
+
grid.output_buffer.add_filter(column.detach_with_id, filter_html_code)
|
275
286
|
end
|
276
287
|
end
|
277
288
|
|
278
289
|
else # some filters are present in the table
|
279
290
|
|
280
291
|
filter_row_attrs = header_tr_html.clone
|
281
|
-
|
292
|
+
Wice::WgHash.add_or_append_class_value!(filter_row_attrs, 'wg-filter-row', true)
|
282
293
|
filter_row_attrs['id'] = filter_row_id
|
283
294
|
|
284
|
-
|
285
|
-
|
286
|
-
|
295
|
+
grid.output_buffer << %!<tr #{tag_options(filter_row_attrs, true)} !
|
296
|
+
grid.output_buffer << 'style="display:none"' unless filter_shown
|
297
|
+
grid.output_buffer << '>'
|
287
298
|
|
288
299
|
rendering.each_column_aware_of_one_last_one(:in_html) do |column, last|
|
289
300
|
if column.filter_shown?
|
290
301
|
|
291
|
-
filter_html_code = column.render_filter
|
292
|
-
filter_html_code = filter_html_code.html_safe_if_necessary
|
302
|
+
filter_html_code = column.render_filter.html_safe
|
293
303
|
if column.detach_with_id
|
294
|
-
|
295
|
-
|
296
|
-
content.add_filter(column.detach_with_id, filter_html_code)
|
304
|
+
grid.output_buffer << content_tag(:th, '', Wice::WgHash.make_hash(:class, column.css_class))
|
305
|
+
grid.output_buffer.add_filter(column.detach_with_id, filter_html_code)
|
297
306
|
else
|
298
|
-
|
307
|
+
grid.output_buffer << content_tag(:th, filter_html_code, Wice::WgHash.make_hash(:class, column.css_class))
|
299
308
|
end
|
300
309
|
else
|
301
310
|
if reuse_last_column_for_filter_buttons && last
|
302
|
-
|
311
|
+
grid.output_buffer << content_tag(:th,
|
303
312
|
reset_submit_buttons(options, grid, rendering),
|
304
|
-
|
313
|
+
Wice::WgHash.add_or_append_class_value!(Wice::WgHash.make_hash(:class, column.css_class), 'filter_icons')
|
305
314
|
)
|
306
315
|
else
|
307
|
-
|
316
|
+
grid.output_buffer << content_tag(:th, '', Wice::WgHash.make_hash(:class, column.css_class))
|
308
317
|
end
|
309
318
|
end
|
310
319
|
end
|
311
320
|
unless no_rightmost_column
|
312
|
-
|
321
|
+
grid.output_buffer << content_tag(:th, reset_submit_buttons(options, grid, rendering), :class => 'filter_icons' )
|
313
322
|
end
|
314
|
-
|
323
|
+
grid.output_buffer << '</tr>'
|
315
324
|
end
|
316
325
|
end
|
317
326
|
|
318
327
|
rendering.each_column(:in_html) do |column|
|
319
328
|
unless column.css_class.blank?
|
320
|
-
|
329
|
+
Wice::WgHash.add_or_append_class_value!(column.html, column.css_class)
|
321
330
|
end
|
322
331
|
end
|
323
332
|
|
324
|
-
|
325
|
-
|
333
|
+
grid.output_buffer << '</thead><tfoot>'
|
334
|
+
grid.output_buffer << rendering.pagination_panel(number_of_columns, options[:hide_csv_button]) do
|
326
335
|
if pagination_panel_content_html
|
327
336
|
pagination_panel_content_html
|
328
337
|
else
|
@@ -332,7 +341,7 @@ module Wice
|
|
332
341
|
end
|
333
342
|
end
|
334
343
|
|
335
|
-
|
344
|
+
grid.output_buffer << '</tfoot><tbody>'
|
336
345
|
|
337
346
|
|
338
347
|
# rendering rows
|
@@ -388,7 +397,7 @@ module Wice
|
|
388
397
|
additional_opts.delete('class')
|
389
398
|
end
|
390
399
|
opts.merge!(additional_opts)
|
391
|
-
|
400
|
+
Wice::WgHash.add_or_append_class_value!(opts, additional_css_class) unless additional_css_class.blank?
|
392
401
|
end
|
393
402
|
|
394
403
|
if sorting_dependant_row_cycling && column.attribute && grid.ordered_by?(column)
|
@@ -406,13 +415,13 @@ module Wice
|
|
406
415
|
cycle_class = cycle('odd', 'even', :name => grid.name)
|
407
416
|
end
|
408
417
|
|
409
|
-
|
418
|
+
Wice::WgHash.add_or_append_class_value!(row_attributes, cycle_class)
|
410
419
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
420
|
+
grid.output_buffer << before_row_output if before_row_output
|
421
|
+
grid.output_buffer << "<tr #{tag_options(row_attributes)}>#{row_content}"
|
422
|
+
grid.output_buffer << content_tag(:td, '') unless no_rightmost_column
|
423
|
+
grid.output_buffer << '</tr>'
|
424
|
+
grid.output_buffer << after_row_output if after_row_output
|
416
425
|
end
|
417
426
|
|
418
427
|
last_row_output = if rendering.last_row_handler
|
@@ -421,9 +430,9 @@ module Wice
|
|
421
430
|
nil
|
422
431
|
end
|
423
432
|
|
424
|
-
|
433
|
+
grid.output_buffer << last_row_output if last_row_output
|
425
434
|
|
426
|
-
|
435
|
+
grid.output_buffer << '</tbody></table>'
|
427
436
|
|
428
437
|
base_link_for_filter, base_link_for_show_all_records = rendering.base_link_for_filter(controller, options[:extra_request_parameters])
|
429
438
|
|
@@ -451,12 +460,12 @@ module Wice
|
|
451
460
|
|
452
461
|
wg_data['data-foc'] = grid.status['foc'] if grid.status['foc']
|
453
462
|
|
454
|
-
|
463
|
+
grid.output_buffer << content_tag(:div, '', wg_data)
|
455
464
|
|
456
|
-
|
465
|
+
grid.output_buffer << '</div>'
|
457
466
|
|
458
467
|
if Rails.env == 'development'
|
459
|
-
|
468
|
+
grid.output_buffer << javascript_tag(%/ $(document).ready(function(){ \n/ +
|
460
469
|
%$ if (typeof(WiceGridProcessor) == "undefined"){\n$ +
|
461
470
|
%$ alert("wice_grid.js not loaded, WiceGrid cannot proceed!\\n" +\n$ +
|
462
471
|
%$ "Make sure that you have loaded wice_grid.js.\\n" +\n$ +
|
@@ -466,14 +475,7 @@ module Wice
|
|
466
475
|
%$ }) $)
|
467
476
|
end
|
468
477
|
|
469
|
-
|
470
|
-
grid.output_buffer = content
|
471
|
-
else
|
472
|
-
# this will serve as a flag that the grid helper has already processed the grid but in a normal mode,
|
473
|
-
# not in the mode with detached filters.
|
474
|
-
grid.output_buffer = true
|
475
|
-
end
|
476
|
-
return content
|
478
|
+
grid.output_buffer
|
477
479
|
end
|
478
480
|
|
479
481
|
def hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, show_filters, rendering) #:nodoc:
|
@@ -504,7 +506,7 @@ module Wice
|
|
504
506
|
end
|
505
507
|
|
506
508
|
def reset_submit_buttons(options, grid, rendering) #:nodoc:
|
507
|
-
|
509
|
+
if options[:hide_submit_button]
|
508
510
|
''
|
509
511
|
else
|
510
512
|
content_tag(:div, '',
|
@@ -512,7 +514,7 @@ module Wice
|
|
512
514
|
:id => grid.name + '_submit_grid_icon',
|
513
515
|
:class => 'submit clickable'
|
514
516
|
)
|
515
|
-
end + ' ' +
|
517
|
+
end.html_safe + ' ' +
|
516
518
|
if options[:hide_reset_button]
|
517
519
|
''
|
518
520
|
else
|
@@ -522,7 +524,7 @@ module Wice
|
|
522
524
|
:id => grid.name + '_reset_grid_icon',
|
523
525
|
:class => 'reset clickable'
|
524
526
|
)
|
525
|
-
end
|
527
|
+
end.html_safe
|
526
528
|
end
|
527
529
|
|
528
530
|
# Renders a detached filter. The parameters are:
|
@@ -572,7 +574,6 @@ module Wice
|
|
572
574
|
spreadsheet << row
|
573
575
|
end
|
574
576
|
grid.csv_tempfile = spreadsheet.tempfile
|
575
|
-
return grid.csv_tempfile.path
|
576
577
|
end
|
577
578
|
|
578
579
|
def pagination_panel_content(grid, extra_request_parameters, allow_showing_all_records) #:nodoc:
|
@@ -583,13 +584,13 @@ module Wice
|
|
583
584
|
|
584
585
|
html = pagination_info(grid, allow_showing_all_records)
|
585
586
|
|
586
|
-
|
587
|
-
:
|
588
|
-
:
|
589
|
-
:
|
590
|
-
:
|
591
|
-
|
592
|
-
(' <div class="pagination_status">' + html + '</div>').
|
587
|
+
paginate(grid.resultset,
|
588
|
+
:theme => 'wice_grid',
|
589
|
+
:param_name => "#{grid.name}[page]",
|
590
|
+
:inner_window => 4,
|
591
|
+
:outer_window => 2
|
592
|
+
) +
|
593
|
+
(' <div class="pagination_status">' + html + '</div>').html_safe
|
593
594
|
end
|
594
595
|
|
595
596
|
|
@@ -622,19 +623,29 @@ module Wice
|
|
622
623
|
end
|
623
624
|
|
624
625
|
def pagination_info(grid, allow_showing_all_records) #:nodoc:
|
626
|
+
|
627
|
+
|
625
628
|
collection = grid.resultset
|
626
629
|
|
627
|
-
collection_total_entries = collection.
|
628
|
-
|
630
|
+
collection_total_entries = collection.total_count
|
631
|
+
|
632
|
+
|
633
|
+
current_page = grid.ar_options[:page].to_i
|
634
|
+
per_page = grid.ar_options[:per_page].to_i
|
635
|
+
|
636
|
+
first = collection.offset_value + 1
|
637
|
+
last = collection.last_page? ? collection.total_count : collection.offset_value + collection.limit_value
|
638
|
+
|
639
|
+
|
629
640
|
parameters = grid.get_state_as_parameter_value_pairs
|
630
641
|
|
631
642
|
js = ''
|
632
|
-
html = if (collection.
|
643
|
+
html = if (collection.num_pages < 2 && collection.length == 0)
|
633
644
|
'0'
|
634
645
|
else
|
635
|
-
parameters << ["#{grid.name}[pp]",
|
646
|
+
parameters << ["#{grid.name}[pp]", collection_total_entries]
|
636
647
|
|
637
|
-
"#{
|
648
|
+
"#{first}-#{last} / #{collection_total_entries} " +
|
638
649
|
if (! allow_showing_all_records) || collection_total_entries <= collection.length
|
639
650
|
''
|
640
651
|
else
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# It is here only until this pull request is pulled: https://github.com/amatsuda/kaminari/pull/267
|
3
|
+
module Kaminari
|
4
|
+
module Helpers
|
5
|
+
class Tag
|
6
|
+
def page_url_for(page)
|
7
|
+
current_page_params_as_query_string = @param_name.to_s + '=' + (page <= 1 ? nil : page).to_s
|
8
|
+
current_page_params_as_hash = Rack::Utils.parse_nested_query(current_page_params_as_query_string)
|
9
|
+
@template.url_for Wice::WgHash.rec_merge(@params, current_page_params_as_hash).symbolize_keys
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -7,7 +7,7 @@ module Wice
|
|
7
7
|
@select_all_buttons = select_all_buttons
|
8
8
|
self.grid = grid_obj
|
9
9
|
self.html = html
|
10
|
-
|
10
|
+
Wice::WgHash.add_or_append_class_value!(self.html, 'sel')
|
11
11
|
grid_name = self.grid.name
|
12
12
|
@param_name = param_name
|
13
13
|
@cell_rendering_block = lambda do |object, params|
|
@@ -55,11 +55,10 @@ module Wice
|
|
55
55
|
|
56
56
|
params_for_select = (params.is_a?(Hash) && params.empty?) ? [nil] : params
|
57
57
|
|
58
|
-
'<div class="custom-dropdown-container">'.
|
58
|
+
'<div class="custom-dropdown-container">'.html_safe +
|
59
59
|
content_tag(:select,
|
60
60
|
options_for_select(@custom_filter, params_for_select),
|
61
|
-
select_options) +
|
62
|
-
select_toggle.html_safe_if_necessary + '</div>'.html_safe_if_necessary
|
61
|
+
select_options) + select_toggle.html_safe + '</div>'.html_safe
|
63
62
|
end
|
64
63
|
|
65
64
|
|
data/lib/wice_grid.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'will_paginate.rb'
|
4
3
|
require 'wice_grid_misc.rb'
|
5
4
|
require 'wice_grid_core_ext.rb'
|
6
5
|
require 'grid_renderer.rb'
|
@@ -16,7 +15,7 @@ require 'wice_grid_spreadsheet.rb'
|
|
16
15
|
require 'wice_grid_serialized_queries_controller.rb'
|
17
16
|
require 'view_columns/column_processor_index.rb'
|
18
17
|
require 'view_columns.rb'
|
19
|
-
|
18
|
+
require 'kaminari.rb'
|
20
19
|
|
21
20
|
|
22
21
|
ActionController::Base.send(:helper_method, :wice_grid_custom_filter_params)
|
@@ -45,15 +44,13 @@ module Wice
|
|
45
44
|
JsCalendarHelpers.send(:include, m)
|
46
45
|
end
|
47
46
|
|
48
|
-
Wice::GridRenderer.send(:include, ::WillPaginate::ViewHelpers)
|
49
47
|
ViewColumn.load_column_processors
|
50
48
|
require 'wice_grid_serialized_query.rb'
|
51
|
-
end
|
52
|
-
|
53
|
-
require 'will_paginate_paginator.rb'
|
54
49
|
|
50
|
+
# It is here only until this pull request is pulled: https://github.com/amatsuda/kaminari/pull/267
|
51
|
+
require 'kaminari_monkey_patching.rb'
|
52
|
+
end
|
55
53
|
end
|
56
|
-
|
57
54
|
end
|
58
55
|
|
59
56
|
class WiceGrid
|
@@ -110,7 +107,6 @@ module Wice
|
|
110
107
|
:page => 1,
|
111
108
|
:per_page => Defaults::PER_PAGE,
|
112
109
|
:saved_query => nil,
|
113
|
-
:select => nil,
|
114
110
|
:total_entries => nil,
|
115
111
|
:with_paginated_resultset => nil,
|
116
112
|
:with_resultset => nil
|
@@ -281,16 +277,31 @@ module Wice
|
|
281
277
|
@ar_options[:joins] = @options[:joins]
|
282
278
|
@ar_options[:include] = @options[:include]
|
283
279
|
@ar_options[:group] = @options[:group]
|
284
|
-
@ar_options[:select] = @options[:select]
|
285
280
|
end
|
286
281
|
|
282
|
+
|
283
|
+
# TO DO: what to do with other @ar_options values?
|
287
284
|
def read #:nodoc:
|
288
285
|
form_ar_options
|
289
286
|
@klass.unscoped do
|
290
287
|
@resultset = if self.output_csv?
|
291
|
-
@relation.find(:all, @ar_options)
|
288
|
+
# @relation.find(:all, @ar_options)
|
289
|
+
@relation.
|
290
|
+
includes(@ar_options[:include]).
|
291
|
+
joins( @ar_options[:joins]).
|
292
|
+
order( @ar_options[:order]).
|
293
|
+
where( @ar_options[:conditions])
|
294
|
+
|
292
295
|
else
|
293
|
-
@
|
296
|
+
# p @ar_options
|
297
|
+
@relation.
|
298
|
+
page( @ar_options[:page]).
|
299
|
+
per( @ar_options[:per_page]).
|
300
|
+
includes(@ar_options[:include]).
|
301
|
+
joins( @ar_options[:joins]).
|
302
|
+
order( @ar_options[:order]).
|
303
|
+
where( @ar_options[:conditions])
|
304
|
+
|
294
305
|
end
|
295
306
|
end
|
296
307
|
invoke_resultset_callbacks
|
@@ -355,7 +366,7 @@ module Wice
|
|
355
366
|
def get_state_as_parameter_value_pairs(including_saved_query_request = false) #:nodoc:
|
356
367
|
res = []
|
357
368
|
unless status[:f].blank?
|
358
|
-
status[:f]
|
369
|
+
Wice::WgHash.parameter_names_and_values(status[:f], [name, 'f']).collect do |param_name, value|
|
359
370
|
if value.is_a?(Array)
|
360
371
|
param_name_ar = param_name + '[]'
|
361
372
|
value.each do |v|
|
data/lib/wice_grid_core_ext.rb
CHANGED
@@ -1,112 +1,121 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
module WGHashExtensions #:nodoc:
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
module Wice
|
4
|
+
module WgHash
|
5
|
+
class << self
|
6
|
+
|
7
|
+
# if there's a hash of hashes, the original structure and the
|
8
|
+
# returned structure should not contain any shared deep hashes
|
9
|
+
def deep_clone(hash) #:nodoc:
|
10
|
+
cloned = hash.clone
|
11
|
+
cloned.keys.each do |k|
|
12
|
+
if cloned[k].kind_of?(Hash)
|
13
|
+
cloned[k] = Wice::WgHash.deep_clone cloned[k]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
cloned
|
16
17
|
end
|
17
|
-
end
|
18
|
-
cloned
|
19
|
-
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
# Used to modify options submitted to view helpers. If there is no :klass option,
|
20
|
+
# it will be added, if there is, the css class name will be appended to the existing
|
21
|
+
# class name(s)
|
22
|
+
def add_or_append_class_value!(hash, klass_value, prepend = false) #:nodoc:
|
23
|
+
if hash.has_key?('class')
|
24
|
+
hash[:class] = hash['class']
|
25
|
+
hash.delete('class')
|
26
|
+
end
|
27
|
+
|
28
|
+
hash[:class] = if hash.has_key?(:class)
|
29
|
+
if prepend
|
30
|
+
"#{klass_value} #{hash[:class]}"
|
31
|
+
else
|
32
|
+
"#{hash[:class]} #{klass_value}"
|
33
|
+
end
|
34
|
+
else
|
35
|
+
klass_value
|
36
|
+
end
|
37
|
+
|
38
|
+
hash
|
39
|
+
end
|
29
40
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
# Used mostly for submitting options to view helpers, that is, like this:
|
42
|
+
# content_tag(:th, col_link, Wice::WgHash.make_hash(:class, css_class))
|
43
|
+
# In some it is important that if the value is empty, no option
|
44
|
+
# is submitted at all. Thus, there's a check for an empty value
|
45
|
+
def make_hash(key, value) #:nodoc:
|
46
|
+
value.blank? ? {} : {key => value}
|
35
47
|
end
|
36
|
-
else
|
37
|
-
klass_value
|
38
|
-
end
|
39
48
|
|
40
|
-
return self
|
41
|
-
end
|
42
49
|
|
50
|
+
# A deep merge of two hashes.
|
51
|
+
# That is, if both hashes have the same key and the values are hashes, these two hashes should also be merged.
|
52
|
+
# Used for merging two sets of params.
|
53
|
+
def rec_merge(hash, other) #:nodoc:
|
54
|
+
res = hash.clone
|
55
|
+
other.each do |key, other_value|
|
56
|
+
value = res[key]
|
57
|
+
if value.is_a?(Hash) && other_value.is_a?(Hash)
|
58
|
+
res[key] = rec_merge value, other_value
|
59
|
+
else
|
60
|
+
res[key] = other_value
|
61
|
+
end
|
62
|
+
end
|
63
|
+
res
|
64
|
+
end
|
43
65
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
66
|
+
# Used to transform a traditional params hash
|
67
|
+
# into an array of two element arrays where element zero is a parameter name as it appears in HTTP requests,
|
68
|
+
# and the first element is the value:
|
69
|
+
# { :a => { :b => 3, :c => 4, :d => { :e => 5 }} }.parameter_names_and_values #=> [["a[d][e]", 5], ["a[b]", 3], ["a[c]", 4]]
|
70
|
+
# The parameter is an optional array of parameter names to prepend:
|
71
|
+
# { :a => { :b => 3, :c => 4, :d => { :e => 5 }} }.parameter_names_and_values(['foo', 'baz']) #=>
|
72
|
+
# [["foo[baz][a][d][e]", 5], ["foo[baz][a][b]", 3], ["foo[baz][a][c]", 4]]
|
73
|
+
def parameter_names_and_values(hash, initial = []) #:nodoc:
|
74
|
+
res = []
|
75
|
+
recursively_gather_finite_non_hash_values_with_key_path(hash, res, [])
|
76
|
+
res.collect do |parameter_struct|
|
77
|
+
parameter_struct[0] = initial + parameter_struct[0]
|
78
|
+
[Wice::WgArray.to_parameter_name(parameter_struct[0]), parameter_struct[1]]
|
79
|
+
end
|
80
|
+
end
|
59
81
|
|
82
|
+
protected
|
60
83
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
res[key] = value.rec_merge other_value
|
70
|
-
else
|
71
|
-
res[key] = other_value
|
84
|
+
def recursively_gather_finite_non_hash_values_with_key_path(hash, res, stack = []) #:nodoc:
|
85
|
+
hash.each do |key, value|
|
86
|
+
if value.kind_of?(Hash)
|
87
|
+
recursively_gather_finite_non_hash_values_with_key_path(value, res, stack + [key])
|
88
|
+
else
|
89
|
+
res << [stack + [key], value]
|
90
|
+
end
|
91
|
+
end
|
72
92
|
end
|
93
|
+
|
73
94
|
end
|
74
|
-
res
|
75
95
|
end
|
76
96
|
|
77
97
|
|
78
|
-
module
|
98
|
+
module WgEnumerable #:nodoc:
|
79
99
|
|
80
|
-
# Used
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
def make_hash(key, value) #:nodoc:
|
85
|
-
value.blank? ? {} : {key => value}
|
100
|
+
# Used to check the validity of :custom_filter parameter of column
|
101
|
+
def self.all_items_are_of_class(enumerable, klass) #:nodoc:
|
102
|
+
return false if enumerable.empty?
|
103
|
+
enumerable.inject(true){|memo, o| (o.is_a? klass) && memo}
|
86
104
|
end
|
87
105
|
|
88
|
-
|
89
106
|
end
|
90
107
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
self.
|
95
|
-
|
96
|
-
value.recursively_gather_finite_non_hash_values_with_key_path(res, stack + [key])
|
97
|
-
else
|
98
|
-
res << [stack + [key], value]
|
99
|
-
end
|
108
|
+
module WgArray
|
109
|
+
# Only used by Hash#parameter_names_and_values
|
110
|
+
# Transforms ['foo', 'bar', 'baz'] to 'foo[bar][baz]'
|
111
|
+
def self.to_parameter_name(array) #:nodoc:
|
112
|
+
array[0].to_s + (array[1..-1] || []).collect{|k| '[' + k.to_s + ']'}.join('')
|
100
113
|
end
|
101
114
|
end
|
102
115
|
|
103
116
|
end
|
104
117
|
|
105
118
|
|
106
|
-
class Hash #:nodoc:
|
107
|
-
include WGHashExtensions
|
108
|
-
end
|
109
|
-
|
110
119
|
# tag_options is a Rails views private method that takes a hash op options for
|
111
120
|
# an HTM hash and produces a string ready to be added to the tag.
|
112
121
|
# Here we are changing its visibility in order to be able to use it.
|
@@ -119,17 +128,6 @@ module ActionView #:nodoc:
|
|
119
128
|
end
|
120
129
|
|
121
130
|
|
122
|
-
|
123
|
-
module Enumerable #:nodoc:
|
124
|
-
|
125
|
-
# Used to check the validity of :custom_filter parameter of column
|
126
|
-
def all_items_are_of_class(klass) #:nodoc:
|
127
|
-
return false if self.empty?
|
128
|
-
self.inject(true){|memo, o| (o.is_a? klass) && memo}
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
131
|
module WGObjectExtensions #:nodoc:
|
134
132
|
|
135
133
|
# takes a list of messages, sends message 1 to self, then message 2 is sent to the result of the first message, ans so on
|
@@ -152,28 +150,3 @@ class Object #:nodoc:
|
|
152
150
|
include WGObjectExtensions
|
153
151
|
end
|
154
152
|
|
155
|
-
module WGArrayExtensions #:nodoc:
|
156
|
-
# Only used by Hash#parameter_names_and_values
|
157
|
-
# Transforms ['foo', 'bar', 'baz'] to 'foo[bar][baz]'
|
158
|
-
def to_parameter_name #:nodoc:
|
159
|
-
self[0].to_s + (self[1..-1] || []).collect{|k| '[' + k.to_s + ']'}.join('')
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
class Array #:nodoc:
|
164
|
-
include WGArrayExtensions
|
165
|
-
end
|
166
|
-
|
167
|
-
module StringExt #:nodoc:
|
168
|
-
def html_safe_if_necessary #:nodoc:
|
169
|
-
if respond_to?(:html_safe)
|
170
|
-
html_safe
|
171
|
-
else
|
172
|
-
self
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
class String #:nodoc:
|
178
|
-
include StringExt
|
179
|
-
end
|
data/wice_grid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "wice_grid"
|
8
|
-
s.version = "3.2.0.
|
8
|
+
s.version = "3.2.0.pre2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Yuri Leikind"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-08-04"
|
13
13
|
s.description = "A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters "
|
14
14
|
s.email = "yuri.leikind@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -20,9 +20,15 @@ Gem::Specification.new do |s|
|
|
20
20
|
"MIT-LICENSE",
|
21
21
|
"README.rdoc",
|
22
22
|
"RELEASE_NOTES_3.2.pre1.rdoc",
|
23
|
+
"RELEASE_NOTES_3.2.pre2.rdoc",
|
23
24
|
"Rakefile",
|
24
25
|
"SAVED_QUERIES_HOWTO.rdoc",
|
25
26
|
"VERSION",
|
27
|
+
"app/views/kaminari/wice_grid/_gap.html.haml",
|
28
|
+
"app/views/kaminari/wice_grid/_next_page.html.haml",
|
29
|
+
"app/views/kaminari/wice_grid/_page.html.haml",
|
30
|
+
"app/views/kaminari/wice_grid/_paginator.html.haml",
|
31
|
+
"app/views/kaminari/wice_grid/_prev_page.html.haml",
|
26
32
|
"lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb",
|
27
33
|
"lib/generators/wice_grid/install_generator.rb",
|
28
34
|
"lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb",
|
@@ -35,6 +41,7 @@ Gem::Specification.new do |s|
|
|
35
41
|
"lib/helpers/wice_grid_misc_view_helpers.rb",
|
36
42
|
"lib/helpers/wice_grid_serialized_queries_view_helpers.rb",
|
37
43
|
"lib/helpers/wice_grid_view_helpers.rb",
|
44
|
+
"lib/kaminari_monkey_patching.rb",
|
38
45
|
"lib/table_column_matrix.rb",
|
39
46
|
"lib/view_columns.rb",
|
40
47
|
"lib/view_columns/action_view_column.rb",
|
@@ -53,7 +60,6 @@ Gem::Specification.new do |s|
|
|
53
60
|
"lib/wice_grid_serialized_queries_controller.rb",
|
54
61
|
"lib/wice_grid_serialized_query.rb",
|
55
62
|
"lib/wice_grid_spreadsheet.rb",
|
56
|
-
"lib/will_paginate_paginator.rb",
|
57
63
|
"test/readme.txt",
|
58
64
|
"vendor/assets/images/icons/grid/arrow_down.gif",
|
59
65
|
"vendor/assets/images/icons/grid/arrow_up.gif",
|
@@ -82,12 +88,12 @@ Gem::Specification.new do |s|
|
|
82
88
|
s.specification_version = 3
|
83
89
|
|
84
90
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
85
|
-
s.
|
91
|
+
s.add_runtime_dependency(%q<kaminari>, [">= 0.13.0"])
|
86
92
|
else
|
87
|
-
s.add_dependency(%q<
|
93
|
+
s.add_dependency(%q<kaminari>, [">= 0.13.0"])
|
88
94
|
end
|
89
95
|
else
|
90
|
-
s.add_dependency(%q<
|
96
|
+
s.add_dependency(%q<kaminari>, [">= 0.13.0"])
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wice_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.0.
|
4
|
+
version: 3.2.0.pre2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: kaminari
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
-
type: :
|
21
|
+
version: 0.13.0
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.13.0
|
30
30
|
description: ! 'A Rails grid plugin to create grids with sorting, pagination, and
|
31
31
|
(automatically generated) filters '
|
32
32
|
email: yuri.leikind@gmail.com
|
@@ -39,9 +39,15 @@ files:
|
|
39
39
|
- MIT-LICENSE
|
40
40
|
- README.rdoc
|
41
41
|
- RELEASE_NOTES_3.2.pre1.rdoc
|
42
|
+
- RELEASE_NOTES_3.2.pre2.rdoc
|
42
43
|
- Rakefile
|
43
44
|
- SAVED_QUERIES_HOWTO.rdoc
|
44
45
|
- VERSION
|
46
|
+
- app/views/kaminari/wice_grid/_gap.html.haml
|
47
|
+
- app/views/kaminari/wice_grid/_next_page.html.haml
|
48
|
+
- app/views/kaminari/wice_grid/_page.html.haml
|
49
|
+
- app/views/kaminari/wice_grid/_paginator.html.haml
|
50
|
+
- app/views/kaminari/wice_grid/_prev_page.html.haml
|
45
51
|
- lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb
|
46
52
|
- lib/generators/wice_grid/install_generator.rb
|
47
53
|
- lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb
|
@@ -54,6 +60,7 @@ files:
|
|
54
60
|
- lib/helpers/wice_grid_misc_view_helpers.rb
|
55
61
|
- lib/helpers/wice_grid_serialized_queries_view_helpers.rb
|
56
62
|
- lib/helpers/wice_grid_view_helpers.rb
|
63
|
+
- lib/kaminari_monkey_patching.rb
|
57
64
|
- lib/table_column_matrix.rb
|
58
65
|
- lib/view_columns.rb
|
59
66
|
- lib/view_columns/action_view_column.rb
|
@@ -72,7 +79,6 @@ files:
|
|
72
79
|
- lib/wice_grid_serialized_queries_controller.rb
|
73
80
|
- lib/wice_grid_serialized_query.rb
|
74
81
|
- lib/wice_grid_spreadsheet.rb
|
75
|
-
- lib/will_paginate_paginator.rb
|
76
82
|
- test/readme.txt
|
77
83
|
- vendor/assets/images/icons/grid/arrow_down.gif
|
78
84
|
- vendor/assets/images/icons/grid/arrow_up.gif
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module Wice
|
2
|
-
class WillPaginatePaginator < ::WillPaginate::ActionView::LinkRenderer
|
3
|
-
def html_container(html)
|
4
|
-
tag(:div,
|
5
|
-
tag(:ul, html),
|
6
|
-
container_attributes
|
7
|
-
)
|
8
|
-
end
|
9
|
-
|
10
|
-
def page_number(page)
|
11
|
-
if page == current_page
|
12
|
-
tag(:li, link(page, page, :rel => rel_value(page)), :class => 'active')
|
13
|
-
else
|
14
|
-
tag(:li, link(page, page, :rel => rel_value(page)))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def previous_or_next_page(page, text, classname)
|
19
|
-
if page
|
20
|
-
tag(:li, link(text, page))
|
21
|
-
else
|
22
|
-
tag(:li, link(text, page), :class => 'disabled')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def gap
|
27
|
-
'<li class="disabled"><a href="#">...</a></li>'
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|