datagrid 1.6.3 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/Readme.markdown +2 -2
- data/datagrid.gemspec +10 -14
- data/lib/datagrid/active_model.rb +25 -29
- data/lib/datagrid/column_names_attribute.rb +9 -7
- data/lib/datagrid/columns/column.rb +3 -1
- data/lib/datagrid/columns.rb +139 -171
- data/lib/datagrid/configuration.rb +6 -1
- data/lib/datagrid/core.rb +43 -22
- data/lib/datagrid/drivers/abstract_driver.rb +2 -1
- data/lib/datagrid/drivers/active_record.rb +2 -1
- data/lib/datagrid/drivers/array.rb +2 -1
- data/lib/datagrid/drivers/mongo_mapper.rb +2 -1
- data/lib/datagrid/drivers/mongoid.rb +3 -2
- data/lib/datagrid/drivers/sequel.rb +2 -1
- data/lib/datagrid/drivers.rb +2 -1
- data/lib/datagrid/engine.rb +3 -2
- data/lib/datagrid/filters/base_filter.rb +5 -2
- data/lib/datagrid/filters/boolean_enum_filter.rb +5 -3
- data/lib/datagrid/filters/boolean_filter.rb +2 -1
- data/lib/datagrid/filters/composite_filters.rb +5 -11
- data/lib/datagrid/filters/extended_boolean_filter.rb +2 -1
- data/lib/datagrid/filters/select_options.rb +34 -1
- data/lib/datagrid/filters.rb +38 -15
- data/lib/datagrid/form_builder.rb +10 -3
- data/lib/datagrid/helper.rb +47 -21
- data/lib/datagrid/ordering.rb +14 -14
- data/lib/datagrid/renderer.rb +2 -1
- data/lib/datagrid/scaffold.rb +1 -1
- data/lib/datagrid/utils.rb +1 -0
- data/lib/datagrid/version.rb +1 -1
- data/lib/datagrid.rb +2 -1
- metadata +8 -8
data/lib/datagrid/helper.rb
CHANGED
@@ -4,30 +4,28 @@ require "action_view"
|
|
4
4
|
module Datagrid
|
5
5
|
module Helper
|
6
6
|
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
7
|
+
# @param grid [Datagrid] grid object
|
8
|
+
# @param column [Datagrid::Columns::Column, String, Symbol] column name
|
9
|
+
# @param model [Object] an object from grid scope
|
10
|
+
# @return [Object] individual cell value from the given grid, column name and model
|
11
|
+
# @example
|
10
12
|
# <ul>
|
11
13
|
# <% @grid.columns.each do |column|
|
12
14
|
# <li><%= column.header %>: <%= datagrid_value(@grid, column.name, @resource %></li>
|
13
15
|
# <% end %>
|
14
16
|
# </ul>
|
15
|
-
|
16
|
-
|
17
|
-
datagrid_renderer.format_value(grid, column_name, model)
|
17
|
+
def datagrid_value(grid, column, model)
|
18
|
+
datagrid_renderer.format_value(grid, column, model)
|
18
19
|
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
# @!visibility private
|
22
|
+
def datagrid_format_value(grid, column, model)
|
23
|
+
datagrid_value(grid, column, model)
|
22
24
|
end
|
23
25
|
|
24
26
|
# Renders html table with columns defined in grid class.
|
25
27
|
# In the most common used you need to pass paginated collection
|
26
28
|
# to datagrid table because datagrid do not have pagination compatibilities:
|
27
|
-
#
|
28
|
-
# assets = grid.assets.page(params[:page])
|
29
|
-
# datagrid_table(grid, assets, options)
|
30
|
-
#
|
31
29
|
# Supported options:
|
32
30
|
#
|
33
31
|
# * <tt>:html</tt> - hash of attributes for <table> tag
|
@@ -38,6 +36,12 @@ module Datagrid
|
|
38
36
|
# and needs different columns. Default: all defined columns.
|
39
37
|
# * <tt>:partials</tt> - Path for partials lookup.
|
40
38
|
# Default: 'datagrid'.
|
39
|
+
# @param grid [Datagrid] grid object
|
40
|
+
# @param assets [Array] objects from grid scope
|
41
|
+
# @return [String] table tag HTML markup
|
42
|
+
# @example
|
43
|
+
# assets = grid.assets.page(params[:page])
|
44
|
+
# datagrid_table(grid, assets, options)
|
41
45
|
def datagrid_table(grid, assets = grid.assets, **options)
|
42
46
|
datagrid_renderer.table(grid, assets, **options)
|
43
47
|
end
|
@@ -50,6 +54,8 @@ module Datagrid
|
|
50
54
|
# Default: true
|
51
55
|
# * <tt>:partials</tt> - Path for partials lookup.
|
52
56
|
# Default: 'datagrid'.
|
57
|
+
# @param grid [Datagrid] grid object
|
58
|
+
# @return [String] HTML table header tag markup
|
53
59
|
def datagrid_header(grid, options = {})
|
54
60
|
datagrid_renderer.header(grid, options)
|
55
61
|
end
|
@@ -66,6 +72,7 @@ module Datagrid
|
|
66
72
|
# * <tt>:partials</tt> - Path for partials lookup.
|
67
73
|
# Default: 'datagrid'.
|
68
74
|
#
|
75
|
+
# @example
|
69
76
|
# = datagrid_rows(grid) # Generic table rows Layout
|
70
77
|
#
|
71
78
|
# = datagrid_rows(grid) do |row| # Custom Layout
|
@@ -93,21 +100,30 @@ module Datagrid
|
|
93
100
|
# * <tt>:partials</tt> - Path for form partial lookup.
|
94
101
|
# Default: 'datagrid'.
|
95
102
|
# * All options supported by Rails <tt>form_for</tt> helper
|
103
|
+
# @param grid [Datagrid] grid object
|
104
|
+
# @return [String] form HTML tag markup
|
96
105
|
def datagrid_form_for(grid, options = {})
|
97
106
|
datagrid_renderer.form_for(grid, options)
|
98
107
|
end
|
99
108
|
|
100
109
|
# Provides access to datagrid columns data.
|
101
|
-
#
|
102
|
-
#
|
110
|
+
# Used in case you want to build html table completelly manually
|
111
|
+
# @param grid [Datagrid] grid object
|
112
|
+
# @param asset [Object] object from grid scope
|
113
|
+
# @param block [Proc] block with Datagrid::Helper::HtmlRow as an argument returning a HTML markup as a String
|
114
|
+
# @return [Datagrid::Helper::HtmlRow, String] captured HTML markup if block given otherwise row object
|
115
|
+
# @example
|
116
|
+
# # Suppose that grid has first_name and last_name columns
|
103
117
|
# <%= datagrid_row(grid, user) do |row| %>
|
104
118
|
# <tr>
|
105
119
|
# <td><%= row.first_name %></td>
|
106
120
|
# <td><%= row.last_name %></td>
|
107
121
|
# </tr>
|
108
122
|
# <% end %>
|
109
|
-
#
|
110
|
-
#
|
123
|
+
# @example
|
124
|
+
# <% row = datagrid_row(grid, user) %>
|
125
|
+
# First Name: <%= row.first_name %>
|
126
|
+
# Last Name: <%= row.last_name %>
|
111
127
|
def datagrid_row(grid, asset, &block)
|
112
128
|
HtmlRow.new(self, grid, asset).tap do |row|
|
113
129
|
if block_given?
|
@@ -117,37 +133,47 @@ module Datagrid
|
|
117
133
|
end
|
118
134
|
|
119
135
|
# Generates an ascending or descending order url for the given column
|
136
|
+
# @param grid [Datagrid] grid object
|
137
|
+
# @param column [Datagrid::Columns::Column, String, Symbol] column name
|
138
|
+
# @param descending [Boolean] specifies order direction. Ascending if false, otherwise descending.
|
139
|
+
# @return [String] order layout HTML markup
|
120
140
|
def datagrid_order_path(grid, column, descending)
|
121
141
|
datagrid_renderer.order_path(grid, column, descending, request)
|
122
142
|
end
|
123
143
|
|
124
144
|
# Represents a datagrid row that provides access to column values for the given asset
|
125
|
-
#
|
145
|
+
# @example
|
126
146
|
# row = datagrid_row(grid, user)
|
147
|
+
# row.class # => Datagrid::Helper::HtmlRow
|
127
148
|
# row.first_name # => "<strong>Bogdan</strong>"
|
128
149
|
# row.grid # => Grid object
|
129
150
|
# row.asset # => User object
|
151
|
+
# row.each do |value|
|
152
|
+
# puts value
|
153
|
+
# end
|
130
154
|
class HtmlRow
|
131
155
|
|
132
156
|
include Enumerable
|
133
157
|
|
134
158
|
attr_reader :grid, :asset
|
135
159
|
|
136
|
-
|
160
|
+
# @!visibility private
|
161
|
+
def initialize(context, grid, asset)
|
137
162
|
@context = context
|
138
163
|
@grid = grid
|
139
164
|
@asset = asset
|
140
165
|
end
|
141
166
|
|
142
|
-
#
|
167
|
+
# @return [Object] a column value for given column name
|
143
168
|
def get(column)
|
144
169
|
@context.datagrid_value(@grid, column, @asset)
|
145
170
|
end
|
146
171
|
|
147
172
|
# Iterates over all column values that are available in the row
|
148
|
-
|
173
|
+
# param block [Proc] column value iterator
|
174
|
+
def each(&block)
|
149
175
|
@grid.columns.each do |column|
|
150
|
-
|
176
|
+
block.call(get(column))
|
151
177
|
end
|
152
178
|
end
|
153
179
|
|
data/lib/datagrid/ordering.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
require "datagrid/columns"
|
2
2
|
|
3
3
|
module Datagrid
|
4
|
+
# Raised when grid order value is incorrect
|
4
5
|
class OrderUnsupported < StandardError
|
5
6
|
end
|
6
7
|
module Ordering
|
7
8
|
|
9
|
+
# @!visibility private
|
8
10
|
def self.included(base)
|
9
11
|
base.extend ClassMethods
|
10
12
|
base.class_eval do
|
@@ -26,38 +28,37 @@ module Datagrid
|
|
26
28
|
|
27
29
|
end
|
28
30
|
base.send :include, InstanceMethods
|
29
|
-
end
|
31
|
+
end
|
30
32
|
|
33
|
+
# @!visibility private
|
31
34
|
module ClassMethods
|
32
|
-
|
33
35
|
def order_unsupported(name, reason)
|
34
36
|
raise Datagrid::OrderUnsupported, "Can not sort #{self.inspect} by ##{name}: #{reason}"
|
35
37
|
end
|
36
|
-
|
37
|
-
end # ClassMethods
|
38
|
+
end
|
38
39
|
|
39
40
|
module InstanceMethods
|
40
41
|
|
41
|
-
|
42
|
+
# @!visibility private
|
43
|
+
def assets
|
42
44
|
check_order_valid!
|
43
45
|
apply_order(super)
|
44
46
|
end
|
45
47
|
|
46
|
-
#
|
47
|
-
#
|
48
|
+
# @return [Datagrid::Columns::Column, nil] a column definition that is currently used to order assets
|
49
|
+
# @example
|
48
50
|
# class MyGrid
|
49
51
|
# scope { Model }
|
50
52
|
# column(:id)
|
51
53
|
# column(:name)
|
52
54
|
# end
|
53
|
-
# MyGrid.new(:
|
54
|
-
#
|
55
|
+
# MyGrid.new(order: "name").order_column # => #<Column name: "name", ...>
|
55
56
|
def order_column
|
56
|
-
order
|
57
|
+
order ? column_by_name(order) : nil
|
57
58
|
end
|
58
59
|
|
59
|
-
#
|
60
|
-
#
|
60
|
+
# @param column [String, Datagrid::Columns::Column]
|
61
|
+
# @return [Boolean] true if given grid is ordered by given column.
|
61
62
|
def ordered_by?(column)
|
62
63
|
order_column == column_by_name(column)
|
63
64
|
end
|
@@ -127,7 +128,6 @@ module Datagrid
|
|
127
128
|
self.class.order_unsupported(order_column.name, "Order option proc can not handle more than one argument")
|
128
129
|
end
|
129
130
|
end
|
130
|
-
end
|
131
|
-
|
131
|
+
end
|
132
132
|
end
|
133
133
|
end
|
data/lib/datagrid/renderer.rb
CHANGED
data/lib/datagrid/scaffold.rb
CHANGED
data/lib/datagrid/utils.rb
CHANGED
data/lib/datagrid/version.rb
CHANGED
data/lib/datagrid.rb
CHANGED
@@ -23,6 +23,7 @@ module Datagrid
|
|
23
23
|
|
24
24
|
autoload :Engine
|
25
25
|
|
26
|
+
# @!visibility private
|
26
27
|
def self.included(base)
|
27
28
|
base.class_eval do
|
28
29
|
|
@@ -34,7 +35,7 @@ module Datagrid
|
|
34
35
|
include ::Datagrid::Ordering
|
35
36
|
|
36
37
|
end
|
37
|
-
end
|
38
|
+
end
|
38
39
|
|
39
40
|
class ConfigurationError < StandardError; end
|
40
41
|
class ArgumentError < ::ArgumentError; end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
description: This allows you to easily build datagrid aka data tables with sortable
|
28
28
|
columns and filters
|
29
29
|
email: agresso@gmail.com
|
@@ -90,7 +90,7 @@ files:
|
|
90
90
|
- templates/controller.rb.erb
|
91
91
|
- templates/grid.rb.erb
|
92
92
|
- templates/index.html.erb
|
93
|
-
homepage:
|
93
|
+
homepage: https://github.com/bogdan/datagrid
|
94
94
|
licenses:
|
95
95
|
- MIT
|
96
96
|
metadata:
|
@@ -107,14 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2.
|
110
|
+
version: '2.7'
|
111
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
112
|
requirements:
|
113
113
|
- - ">="
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
117
|
+
rubygems_version: 3.3.7
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Ruby gem to create datagrids
|