datagrid 1.6.2 → 1.6.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Readme.markdown +4 -3
- data/lib/datagrid/column_names_attribute.rb +15 -16
- data/lib/datagrid/columns.rb +29 -29
- data/lib/datagrid/columns/column.rb +4 -0
- data/lib/datagrid/filters/composite_filters.rb +4 -4
- data/lib/datagrid/form_builder.rb +7 -5
- data/lib/datagrid/helper.rb +2 -2
- data/lib/datagrid/renderer.rb +1 -3
- data/lib/datagrid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5f1043a8a905be92c309d00b6c0b107ebec35939c89b5766f5d7c43dbe2c584
|
4
|
+
data.tar.gz: 8b4bd8b0130ef2fa83cebe7012386ffcdb4d9ba32d3e803080e4345d6eb74dee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c42259fe4c806e235d10610ab4b3681319d8f5712c73addc1d54f61d6e6cbd0447a967464f878464da2b54f60dc376acef5238cce1467a097d7cbf799beb51d
|
7
|
+
data.tar.gz: 1ac692930c8a269190bc36ecce7c50cf1c1696fe5b9b6dc0644adfa59eb15a2bab77f4dac70a29633693e707e53ef29ed874eda6f6c82533ed441afe72a5d304
|
data/CHANGELOG.md
CHANGED
data/Readme.markdown
CHANGED
@@ -23,10 +23,11 @@ Ruby library that helps you to build and represent table-like data with:
|
|
23
23
|
[Create an issue](https://github.com/bogdan/datagrid/issues/new) if you want more.
|
24
24
|
|
25
25
|
|
26
|
-
###
|
26
|
+
### Documentation
|
27
27
|
|
28
|
-
*
|
29
|
-
*
|
28
|
+
* [Readme](/Readme.markdown) - this read-me for basic information
|
29
|
+
* [Wiki](https://github.com/bogdan/datagrid/wiki) - general reference on how to use the gem
|
30
|
+
* [Rdoc](https://rdoc.info/github/bogdan/datagrid) - API reference
|
30
31
|
|
31
32
|
### Live Demo
|
32
33
|
|
@@ -23,23 +23,22 @@ module Datagrid
|
|
23
23
|
# Accepts same options as <tt>:enum</tt> filter
|
24
24
|
#
|
25
25
|
# Examples:
|
26
|
-
#
|
27
|
-
# column_names_filter(:
|
28
|
-
#
|
29
|
-
def column_names_filter(options
|
30
|
-
filter(
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
|
26
|
+
#
|
27
|
+
# column_names_filter(header: "Choose columns")
|
28
|
+
#
|
29
|
+
def column_names_filter(**options)
|
30
|
+
filter(
|
31
|
+
:column_names, :enum,
|
32
|
+
select: :optional_columns_select,
|
33
|
+
multiple: true,
|
34
|
+
dummy: true,
|
35
|
+
**options,
|
36
|
+
)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
def columns(*args) #:nodoc:
|
39
|
-
options
|
40
|
-
column_names = selected_column_names(*args)
|
41
|
-
column_names << options
|
42
|
-
super(*column_names)
|
40
|
+
def columns(*args, **options) #:nodoc:
|
41
|
+
super(*selected_column_names(*args), **options)
|
43
42
|
end
|
44
43
|
|
45
44
|
# Returns a list of enabled columns with <tt>:mandatory => true</tt> option
|
@@ -59,7 +58,7 @@ module Datagrid
|
|
59
58
|
optional_columns.map {|c| [c.header, c.name] }
|
60
59
|
end
|
61
60
|
|
62
|
-
def selected_column_names(*args)
|
61
|
+
def selected_column_names(*args)
|
63
62
|
if args.any?
|
64
63
|
args.compact!
|
65
64
|
args.map!(&:to_sym)
|
@@ -75,7 +74,7 @@ module Datagrid
|
|
75
74
|
|
76
75
|
def columns_visibility_enabled?
|
77
76
|
columns_array.any? do |column|
|
78
|
-
column.
|
77
|
+
column.mandatory_explicitly_set?
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
data/lib/datagrid/columns.rb
CHANGED
@@ -86,9 +86,10 @@ module Datagrid
|
|
86
86
|
#
|
87
87
|
# Supported options:
|
88
88
|
#
|
89
|
-
# * :data - if true returns only
|
90
|
-
|
91
|
-
|
89
|
+
# * :data - if true returns only columns with data representation. Default: false.
|
90
|
+
# * :html - if true returns only columns with html columns. Default: false.
|
91
|
+
def columns(*args, data: false, html: false)
|
92
|
+
filter_columns(columns_array, *args, data: data, html: html)
|
92
93
|
end
|
93
94
|
|
94
95
|
# Defines new datagrid column
|
@@ -122,7 +123,7 @@ module Datagrid
|
|
122
123
|
#
|
123
124
|
# See: https://github.com/bogdan/datagrid/wiki/Columns for examples
|
124
125
|
def column(name, query = nil, **options, &block)
|
125
|
-
define_column(columns_array, name, query, options, &block)
|
126
|
+
define_column(columns_array, name, query, **options, &block)
|
126
127
|
end
|
127
128
|
|
128
129
|
# Returns column definition with given name
|
@@ -184,14 +185,13 @@ module Datagrid
|
|
184
185
|
child_class.columns_array = self.columns_array.clone
|
185
186
|
end
|
186
187
|
|
187
|
-
def filter_columns(
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
(
|
194
|
-
(column.mandatory? || args.empty? || args.include?(column.name))
|
188
|
+
def filter_columns(columns_array, *names, data: false, html: false) #:nodoc:
|
189
|
+
names.compact!
|
190
|
+
names.map!(&:to_sym)
|
191
|
+
columns_array.select do |column|
|
192
|
+
(!data || column.data?) &&
|
193
|
+
(!html || column.html?) &&
|
194
|
+
(column.mandatory? || names.empty? || names.include?(column.name))
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -308,11 +308,13 @@ module Datagrid
|
|
308
308
|
# grid.to_csv
|
309
309
|
# grid.to_csv(:id, :name)
|
310
310
|
# grid.to_csv(:col_sep => ';')
|
311
|
-
def to_csv(*column_names)
|
311
|
+
def to_csv(*column_names, **options)
|
312
312
|
require "csv"
|
313
|
-
|
314
|
-
|
315
|
-
|
313
|
+
CSV.generate(
|
314
|
+
headers: self.header(*column_names),
|
315
|
+
write_headers: true,
|
316
|
+
**options
|
317
|
+
) do |csv|
|
316
318
|
each_with_batches do |asset|
|
317
319
|
csv << row_for(asset, *column_names)
|
318
320
|
end
|
@@ -328,24 +330,22 @@ module Datagrid
|
|
328
330
|
# grid = MyGrid.new(:column_names => [:id, :name])
|
329
331
|
# grid.columns # => id and name columns
|
330
332
|
# grid.columns(:id, :category) # => id and category column
|
331
|
-
def columns(*args)
|
332
|
-
self.class.filter_columns(
|
333
|
+
def columns(*args, data: false, html: false)
|
334
|
+
self.class.filter_columns(
|
335
|
+
columns_array, *args, data: data, html: html
|
336
|
+
).select do |column|
|
337
|
+
column.enabled?(self)
|
338
|
+
end
|
333
339
|
end
|
334
340
|
|
335
341
|
# Returns all columns that can be represented in plain data(non-html) way
|
336
|
-
def data_columns(*names)
|
337
|
-
options
|
338
|
-
options[:data] = true
|
339
|
-
names << options
|
340
|
-
self.columns(*names)
|
342
|
+
def data_columns(*names, **options)
|
343
|
+
self.columns(*names, **options, data: true)
|
341
344
|
end
|
342
345
|
|
343
346
|
# Returns all columns that can be represented in HTML table
|
344
|
-
def html_columns(*names)
|
345
|
-
options
|
346
|
-
options[:html] = true
|
347
|
-
names << options
|
348
|
-
self.columns(*names)
|
347
|
+
def html_columns(*names, **options)
|
348
|
+
self.columns(*names, **options, html: true)
|
349
349
|
end
|
350
350
|
|
351
351
|
# Finds a column definition by name
|
@@ -402,7 +402,7 @@ module Datagrid
|
|
402
402
|
#
|
403
403
|
# See Datagrid::Columns::ClassMethods#column for more info
|
404
404
|
def column(name, query = nil, **options, &block)
|
405
|
-
self.class.define_column(columns_array, name, query, options, &block)
|
405
|
+
self.class.define_column(columns_array, name, query, **options, &block)
|
406
406
|
end
|
407
407
|
|
408
408
|
def initialize(*) #:nodoc:
|
@@ -106,6 +106,10 @@ class Datagrid::Columns::Column
|
|
106
106
|
!! options[:mandatory]
|
107
107
|
end
|
108
108
|
|
109
|
+
def mandatory_explicitly_set?
|
110
|
+
options.key?(:mandatory)
|
111
|
+
end
|
112
|
+
|
109
113
|
def enabled?(grid)
|
110
114
|
::Datagrid::Utils.process_availability(grid, options[:if], options[:unless])
|
111
115
|
end
|
@@ -16,10 +16,10 @@ module Datagrid
|
|
16
16
|
from_options = normalize_composite_filter_options(from_options, field)
|
17
17
|
to_options = normalize_composite_filter_options(to_options, field)
|
18
18
|
|
19
|
-
filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :date, from_options) do |date, scope, grid|
|
19
|
+
filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :date, **from_options) do |date, scope, grid|
|
20
20
|
grid.driver.greater_equal(scope, field, date)
|
21
21
|
end
|
22
|
-
filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :date, to_options) do |date, scope, grid|
|
22
|
+
filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :date, **to_options) do |date, scope, grid|
|
23
23
|
grid.driver.less_equal(scope, field, date)
|
24
24
|
end
|
25
25
|
end
|
@@ -27,10 +27,10 @@ module Datagrid
|
|
27
27
|
def integer_range_filters(field, from_options = {}, to_options = {})
|
28
28
|
from_options = normalize_composite_filter_options(from_options, field)
|
29
29
|
to_options = normalize_composite_filter_options(to_options, field)
|
30
|
-
filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :integer, from_options) do |value, scope, grid|
|
30
|
+
filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :integer, **from_options) do |value, scope, grid|
|
31
31
|
grid.driver.greater_equal(scope, field, value)
|
32
32
|
end
|
33
|
-
filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :integer, to_options) do |value, scope, grid|
|
33
|
+
filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :integer, **to_options) do |value, scope, grid|
|
34
34
|
grid.driver.less_equal(scope, field, value)
|
35
35
|
end
|
36
36
|
end
|
@@ -4,11 +4,11 @@ module Datagrid
|
|
4
4
|
module FormBuilder
|
5
5
|
|
6
6
|
# Returns a form input html for the corresponding filter name
|
7
|
-
def datagrid_filter(filter_or_attribute,
|
7
|
+
def datagrid_filter(filter_or_attribute, options = {}, &block)
|
8
8
|
filter = datagrid_get_filter(filter_or_attribute)
|
9
9
|
options = {
|
10
10
|
**filter.input_options,
|
11
|
-
**add_html_classes(options, filter.name, datagrid_filter_html_class(filter))
|
11
|
+
**add_html_classes(options, filter.name, datagrid_filter_html_class(filter)),
|
12
12
|
}
|
13
13
|
# Prevent partials option from appearing in HTML attributes
|
14
14
|
options.delete(:partials) # Legacy option
|
@@ -70,9 +70,11 @@ module Datagrid
|
|
70
70
|
select(
|
71
71
|
filter.name,
|
72
72
|
object.select_options(filter) || [],
|
73
|
-
{
|
74
|
-
|
75
|
-
|
73
|
+
{
|
74
|
+
include_blank: filter.include_blank,
|
75
|
+
prompt: filter.prompt,
|
76
|
+
include_hidden: false
|
77
|
+
},
|
76
78
|
multiple: filter.multiple?,
|
77
79
|
**options,
|
78
80
|
&block
|
data/lib/datagrid/helper.rb
CHANGED
@@ -38,8 +38,8 @@ module Datagrid
|
|
38
38
|
# and needs different columns. Default: all defined columns.
|
39
39
|
# * <tt>:partials</tt> - Path for partials lookup.
|
40
40
|
# Default: 'datagrid'.
|
41
|
-
def datagrid_table(grid,
|
42
|
-
datagrid_renderer.table(grid,
|
41
|
+
def datagrid_table(grid, assets = grid.assets, **options)
|
42
|
+
datagrid_renderer.table(grid, assets, **options)
|
43
43
|
end
|
44
44
|
|
45
45
|
# Renders HTML table header for given grid instance using columns defined in it
|
data/lib/datagrid/renderer.rb
CHANGED
@@ -34,11 +34,9 @@ module Datagrid
|
|
34
34
|
_render_partial('form', options[:partials], {:grid => grid, :options => options})
|
35
35
|
end
|
36
36
|
|
37
|
-
def table(grid,
|
38
|
-
options = args.extract_options!
|
37
|
+
def table(grid, assets, **options)
|
39
38
|
options[:html] ||= {}
|
40
39
|
options[:html][:class] ||= "datagrid #{@template.dom_class(grid)}"
|
41
|
-
assets = args.any? ? args.shift : grid.assets
|
42
40
|
|
43
41
|
_render_partial('table', options[:partials],
|
44
42
|
{
|
data/lib/datagrid/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.2.
|
117
|
+
rubygems_version: 3.2.3
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Ruby gem to create datagrids
|