datagrid 1.8.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/CHANGELOG.md +11 -1
- data/{Readme.markdown → README.md} +44 -29
- data/app/assets/stylesheets/datagrid.css +145 -0
- data/app/views/datagrid/_enum_checkboxes.html.erb +5 -3
- data/app/views/datagrid/_form.html.erb +4 -4
- data/app/views/datagrid/_head.html.erb +26 -3
- data/app/views/datagrid/_range_filter.html.erb +5 -3
- data/app/views/datagrid/_row.html.erb +12 -1
- data/app/views/datagrid/_table.html.erb +4 -4
- data/datagrid.gemspec +8 -7
- data/lib/datagrid/active_model.rb +9 -17
- data/lib/datagrid/base.rb +39 -0
- data/lib/datagrid/column_names_attribute.rb +9 -11
- data/lib/datagrid/columns/column.rb +155 -133
- data/lib/datagrid/columns.rb +325 -115
- data/lib/datagrid/configuration.rb +33 -4
- data/lib/datagrid/core.rb +89 -54
- data/lib/datagrid/deprecated_object.rb +20 -0
- data/lib/datagrid/drivers/abstract_driver.rb +12 -23
- data/lib/datagrid/drivers/active_record.rb +24 -26
- data/lib/datagrid/drivers/array.rb +22 -14
- data/lib/datagrid/drivers/mongo_mapper.rb +15 -14
- data/lib/datagrid/drivers/mongoid.rb +15 -17
- data/lib/datagrid/drivers/sequel.rb +14 -19
- data/lib/datagrid/drivers.rb +2 -1
- data/lib/datagrid/engine.rb +11 -3
- data/lib/datagrid/filters/base_filter.rb +166 -143
- data/lib/datagrid/filters/boolean_filter.rb +19 -5
- data/lib/datagrid/filters/date_filter.rb +33 -35
- data/lib/datagrid/filters/date_time_filter.rb +24 -16
- data/lib/datagrid/filters/default_filter.rb +9 -3
- data/lib/datagrid/filters/dynamic_filter.rb +151 -105
- data/lib/datagrid/filters/enum_filter.rb +43 -19
- data/lib/datagrid/filters/extended_boolean_filter.rb +39 -31
- data/lib/datagrid/filters/float_filter.rb +15 -5
- data/lib/datagrid/filters/integer_filter.rb +21 -10
- data/lib/datagrid/filters/ranged_filter.rb +66 -45
- data/lib/datagrid/filters/select_options.rb +58 -49
- data/lib/datagrid/filters/string_filter.rb +9 -4
- data/lib/datagrid/filters.rb +204 -79
- data/lib/datagrid/form_builder.rb +116 -128
- data/lib/datagrid/generators/scaffold.rb +184 -0
- data/lib/datagrid/generators/views.rb +20 -0
- data/lib/datagrid/helper.rb +436 -69
- data/lib/datagrid/ordering.rb +26 -29
- data/lib/datagrid/rspec.rb +6 -10
- data/lib/datagrid/utils.rb +37 -30
- data/lib/datagrid/version.rb +3 -1
- data/lib/datagrid.rb +8 -28
- data/templates/base.rb.erb +6 -4
- data/templates/grid.rb.erb +1 -1
- metadata +17 -17
- data/app/assets/stylesheets/datagrid.sass +0 -134
- data/lib/datagrid/filters/composite_filters.rb +0 -49
- data/lib/datagrid/renderer.rb +0 -157
- data/lib/datagrid/scaffold.rb +0 -129
- data/lib/tasks/datagrid_tasks.rake +0 -15
- data/templates/controller.rb.erb +0 -6
- data/templates/index.html.erb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4f9903c41d2efb4c914ddf949db685228644e1ba071e8e2337491e0b91e0bbd
|
4
|
+
data.tar.gz: 937aea06689389c091b3be16aabaa36d8c828b8a8e97f220eaad403975371c6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3a5ef4923f03bd41bc54c2cc8ad6261f4a1e3302c4aad83a58868d539d69527a6cf838ee6efdf621fa0a47dabd023fa041773dde723f35f0feaf59e0b5effe6
|
7
|
+
data.tar.gz: 0a4c6aca85619ab3a71c125717d6f6f5209eafcb7a509df76afaac91e70790f199fea2ac796ebb9c05d088c8f4d40b42c16d6a49a28661ae1da7703c86c1ff92
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
##
|
3
|
+
## 2.0.0
|
4
|
+
|
5
|
+
Version 2 is a major update implementing a lot of major improvements
|
6
|
+
at the cost of backward compatibility.
|
7
|
+
|
8
|
+
[Changes and migration guide](./version-2)
|
9
|
+
|
10
|
+
## 1.8.3
|
11
|
+
|
12
|
+
* Fix rails hooking for version 7.1. [#327](https://github.com/bogdan/datagrid/issues/327)
|
13
|
+
* Fix formatting of value for `date` and `datetime-local` input types
|
4
14
|
|
5
15
|
## 1.8.2
|
6
16
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
# Datagrid
|
2
2
|
|
3
|
-
|
3
|
+
Datagrid Version 2.0.0 is here.
|
4
4
|
|
5
|
-
[
|
5
|
+
[Migration Guide](./version-2).
|
6
6
|
|
7
|
-
|
7
|
+
[![Build Status](https://github.com/bogdan/datagrid/actions/workflows/ci.yml/badge.svg)](https://github.com/bogdan/datagrid/actions/workflows/ci.yml)
|
8
|
+
|
9
|
+
A really mighty and flexible ruby library that generates reports
|
10
|
+
including admin panels, analytics and data browsers:
|
8
11
|
|
9
12
|
* Filtering
|
10
13
|
* Columns
|
@@ -12,37 +15,42 @@ A really mighty and flexible ruby library that generates reports including admin
|
|
12
15
|
* Localization
|
13
16
|
* Export to CSV
|
14
17
|
|
15
|
-
|
18
|
+
## ORM Support
|
16
19
|
|
17
20
|
* ActiveRecord
|
18
21
|
* Mongoid
|
19
22
|
* MongoMapper
|
20
23
|
* Sequel
|
21
|
-
* Array (
|
24
|
+
* Array (in-memory data of smaller scale)
|
25
|
+
|
26
|
+
## Datagrid Philosophy
|
22
27
|
|
23
|
-
|
28
|
+
1. Expressive DSL complements OOD instead of replacing it.
|
29
|
+
1. Extensible in every way while providing a lot of defaults.
|
30
|
+
1. If your ORM supports that, datagrid also supports that!
|
24
31
|
|
25
|
-
|
32
|
+
## Documentation
|
26
33
|
|
27
|
-
* [
|
28
|
-
* [
|
29
|
-
* [
|
34
|
+
* [Rdoc](https://rubydoc.info/gems/datagrid) - full API reference
|
35
|
+
* [Scope](https://rubydoc.info/gems/datagrid/Datagrid/Core) - working with datagrid scope
|
36
|
+
* [Columns](https://rubydoc.info/gems/datagrid/Datagrid/Columns) - definging datagrid columns
|
37
|
+
* [Filters](https://rubydoc.info/gems/datagrid/Datagrid/Filters) - defining datagrid filters
|
38
|
+
* [Frontend](https://rubydoc.info/gems/datagrid/Datagrid/Helper) - building a frontend
|
39
|
+
* [Configuration](https://rubydoc.info/gems/datagrid/Datagrid/Configuration) - configuring the gem
|
30
40
|
|
31
41
|
### Live Demo
|
32
42
|
|
33
43
|
[Datagrid DEMO application](http://datagrid.herokuapp.com) is available live!
|
34
44
|
[Demo source code](https://github.com/bogdan/datagrid-demo).
|
35
45
|
|
36
|
-
<img src="http://datagrid.herokuapp.com/datagrid_demo_screenshot.png" style="margin: 7px; border: 1px solid black">
|
46
|
+
<!-- <img src="http://datagrid.herokuapp.com/datagrid_demo_screenshot.png" style="margin: 7px; border: 1px solid black"> -->
|
37
47
|
|
38
48
|
### Example
|
39
49
|
|
40
50
|
In order to create a grid:
|
41
51
|
|
42
52
|
``` ruby
|
43
|
-
class UsersGrid
|
44
|
-
|
45
|
-
include Datagrid
|
53
|
+
class UsersGrid < Datagrid::Base
|
46
54
|
|
47
55
|
scope do
|
48
56
|
User.includes(:group)
|
@@ -71,7 +79,7 @@ Basic grid api:
|
|
71
79
|
|
72
80
|
``` ruby
|
73
81
|
report = UsersGrid.new(
|
74
|
-
group_id: [1,2],
|
82
|
+
group_id: [1,2],
|
75
83
|
logins_count: [1, nil],
|
76
84
|
category: "first",
|
77
85
|
order: :group,
|
@@ -79,7 +87,10 @@ report = UsersGrid.new(
|
|
79
87
|
)
|
80
88
|
|
81
89
|
report.assets # => Array of User instances:
|
82
|
-
# SELECT * FROM users WHERE users.group_id in (1,2) AND
|
90
|
+
# SELECT * FROM users WHERE users.group_id in (1,2) AND
|
91
|
+
# users.logins_count >= 1 AND
|
92
|
+
# users.category = 'first'
|
93
|
+
# ORDER BY groups.name DESC
|
83
94
|
|
84
95
|
report.header # => ["Name", "Group", "Activated"]
|
85
96
|
report.rows # => [
|
@@ -103,7 +114,8 @@ In order to create a report, you need to define:
|
|
103
114
|
### Scope
|
104
115
|
|
105
116
|
Default scope of objects to filter and display.
|
106
|
-
In common case it is `ActiveRecord::Base` (or any other supported ORM)
|
117
|
+
In common case it is `ActiveRecord::Base` (or any other supported ORM)
|
118
|
+
subclass with some generic scopes like:
|
107
119
|
|
108
120
|
``` ruby
|
109
121
|
scope do
|
@@ -111,7 +123,7 @@ scope do
|
|
111
123
|
end
|
112
124
|
```
|
113
125
|
|
114
|
-
[More about scope](https://
|
126
|
+
[More about scope](https://rubydoc.info/gems/datagrid/Datagrid/Core)
|
115
127
|
|
116
128
|
### Filters
|
117
129
|
|
@@ -133,9 +145,9 @@ Datagrid supports different type of filters including:
|
|
133
145
|
* xboolean - the select of "yes", "no" and any
|
134
146
|
* enum - selection of the given values
|
135
147
|
* string
|
136
|
-
* dynamic - build dynamic SQL condition
|
148
|
+
* dynamic - build dynamic SQL condition
|
137
149
|
|
138
|
-
[More about filters](https://
|
150
|
+
[More about filters](https://rubydoc.info/gems/datagrid/Datagrid/Filters)
|
139
151
|
|
140
152
|
### Columns
|
141
153
|
|
@@ -150,11 +162,11 @@ end
|
|
150
162
|
Some formatting options are also available.
|
151
163
|
Each column is sortable.
|
152
164
|
|
153
|
-
[More about columns](https://
|
165
|
+
[More about columns](https://rubydoc.info/gems/datagrid/Datagrid/Columns)
|
154
166
|
|
155
167
|
### Front end
|
156
168
|
|
157
|
-
|
169
|
+
#### Using Generator
|
158
170
|
|
159
171
|
Datagrid has a builtin generator:
|
160
172
|
|
@@ -172,27 +184,29 @@ route resources :skills
|
|
172
184
|
insert app/assets/stylesheet/application.css
|
173
185
|
```
|
174
186
|
|
175
|
-
|
187
|
+
#### Customize Built-in views
|
176
188
|
|
177
|
-
In order to get a control on datagrid built-in
|
189
|
+
In order to get a control on datagrid built-in views run:
|
178
190
|
|
179
191
|
``` sh
|
180
|
-
|
192
|
+
rails g datagrid::views
|
181
193
|
```
|
182
194
|
|
183
|
-
|
195
|
+
#### Advanced frontend
|
184
196
|
|
185
197
|
All advanced frontend things are described in:
|
186
198
|
|
187
|
-
[Frontend section on wiki](https://
|
199
|
+
[Frontend section on wiki](https://rubydoc.info/gems/datagrid/Datagrid/Helper)
|
188
200
|
|
189
201
|
## Questions & Issues
|
190
202
|
|
191
|
-
If you have a question of any kind, just make an issue and
|
203
|
+
If you have a question of any kind, just make an issue and
|
204
|
+
describe your problem in details.
|
192
205
|
|
193
206
|
## Contribution
|
194
207
|
|
195
|
-
If you are interested in contributing to this project,
|
208
|
+
If you are interested in contributing to this project,
|
209
|
+
please follow the [instructions here](CONTRIBUTING.md).
|
196
210
|
|
197
211
|
## Self-Promotion
|
198
212
|
|
@@ -203,4 +217,5 @@ Follow the repository on [GitHub](https://github.com/bogdan/datagrid).
|
|
203
217
|
Read [author blog](http://gusiev.com).
|
204
218
|
|
205
219
|
## License
|
220
|
+
|
206
221
|
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid?ref=badge_large)
|
@@ -0,0 +1,145 @@
|
|
1
|
+
/* Table */
|
2
|
+
|
3
|
+
table.datagrid-table {
|
4
|
+
background-color: transparent;
|
5
|
+
border-collapse: collapse;
|
6
|
+
max-width: 100%;
|
7
|
+
}
|
8
|
+
|
9
|
+
table.datagrid-table th {
|
10
|
+
background-color: #eee;
|
11
|
+
text-align: left;
|
12
|
+
vertical-align: top;
|
13
|
+
}
|
14
|
+
|
15
|
+
table.datagrid-table td,
|
16
|
+
table.datagrid-table th {
|
17
|
+
border: 1px solid #d6d6d6;
|
18
|
+
padding: 5px 10px;
|
19
|
+
}
|
20
|
+
|
21
|
+
.datagrid-order-control-asc,
|
22
|
+
.datagrid-order-control-desc {
|
23
|
+
text-decoration: none;
|
24
|
+
font-weight: normal;
|
25
|
+
}
|
26
|
+
|
27
|
+
.datagrid-order-active-asc,
|
28
|
+
.datagrid-order-active-desc {
|
29
|
+
background-color: #fff7d5;
|
30
|
+
}
|
31
|
+
|
32
|
+
.datagrid-order-active-asc a.datagrid-order-control-asc,
|
33
|
+
.datagrid-order-active-desc a.datagrid-order-control-desc {
|
34
|
+
font-weight: bold;
|
35
|
+
color: #d00;
|
36
|
+
}
|
37
|
+
|
38
|
+
.datagrid-no-results {
|
39
|
+
text-align: center;
|
40
|
+
}
|
41
|
+
|
42
|
+
/* Form */
|
43
|
+
|
44
|
+
.datagrid-form {
|
45
|
+
background-color: #f0f0f0;
|
46
|
+
border-radius: 5px;
|
47
|
+
padding: 20px;
|
48
|
+
}
|
49
|
+
|
50
|
+
.datagrid-filter {
|
51
|
+
margin: 10px;
|
52
|
+
}
|
53
|
+
|
54
|
+
.datagrid-filter label {
|
55
|
+
width: 150px;
|
56
|
+
display: inline-block;
|
57
|
+
}
|
58
|
+
|
59
|
+
.datagrid-filter input, .datagrid-filter select {
|
60
|
+
border: 2px solid #ccc;
|
61
|
+
border-radius: 4px;
|
62
|
+
display: inline-block;
|
63
|
+
padding: 5px 12px;
|
64
|
+
width: 300px;
|
65
|
+
}
|
66
|
+
|
67
|
+
input.datagrid-range-from, input.datagrid-range-to {
|
68
|
+
width: 138px;
|
69
|
+
}
|
70
|
+
|
71
|
+
.datagrid-filter select[multiple] {
|
72
|
+
border: 2px solid #ccc;
|
73
|
+
border-radius: 5px;
|
74
|
+
height: 100px;
|
75
|
+
}
|
76
|
+
|
77
|
+
select.datagrid-dynamic-field {
|
78
|
+
width: 228px
|
79
|
+
}
|
80
|
+
|
81
|
+
select.datagrid-dynamic-operation {
|
82
|
+
margin-left: 7px;
|
83
|
+
width: 60px;
|
84
|
+
}
|
85
|
+
|
86
|
+
.datagrid-dynamic-value {
|
87
|
+
margin: 10px 0 0 154px;
|
88
|
+
}
|
89
|
+
|
90
|
+
.datagrid-range-separator {
|
91
|
+
display: inline-block;
|
92
|
+
margin: 6px 4px 0;
|
93
|
+
}
|
94
|
+
|
95
|
+
.datagrid-enum-checkboxes {
|
96
|
+
display: inline-block;
|
97
|
+
}
|
98
|
+
|
99
|
+
.datagrid-enum-checkboxes input {
|
100
|
+
margin: 7px;
|
101
|
+
width: auto;
|
102
|
+
}
|
103
|
+
|
104
|
+
.datagrid-enum-checkboxes label {
|
105
|
+
display: block;
|
106
|
+
width: 100%;
|
107
|
+
}
|
108
|
+
|
109
|
+
.datagrid-actions {
|
110
|
+
padding-left: calc(150px + 10px);
|
111
|
+
}
|
112
|
+
|
113
|
+
.datagrid-submit {
|
114
|
+
background-color: #555;
|
115
|
+
border: none;
|
116
|
+
border-radius: 5px;
|
117
|
+
color: white;
|
118
|
+
cursor: pointer;
|
119
|
+
font-size: 14px;
|
120
|
+
font-weight: bold;
|
121
|
+
line-height: normal;
|
122
|
+
padding: 7px 15px;
|
123
|
+
vertical-align: middle;
|
124
|
+
display: inline-block;
|
125
|
+
zoom: 1;
|
126
|
+
*display: inline;
|
127
|
+
}
|
128
|
+
|
129
|
+
.datagrid-submit:hover,
|
130
|
+
.datagrid-submit:focus {
|
131
|
+
background-color: #333;
|
132
|
+
}
|
133
|
+
|
134
|
+
.datagrid-submit:active {
|
135
|
+
background-color: #000;
|
136
|
+
}
|
137
|
+
|
138
|
+
.datagrid-reset {
|
139
|
+
font-size: 14px;
|
140
|
+
padding: 7px 15px;
|
141
|
+
vertical-align: middle;
|
142
|
+
display: inline-block;
|
143
|
+
zoom: 1;
|
144
|
+
*display: inline;
|
145
|
+
}
|
@@ -2,10 +2,12 @@
|
|
2
2
|
Indent in this file may cause extra space to appear.
|
3
3
|
You can add indent if whitespace doesn't matter for you
|
4
4
|
%>
|
5
|
-
|
5
|
+
<div class="datagrid-enum-checkboxes">
|
6
|
+
<%- choices.each do |value, text| -%>
|
6
7
|
<%- id = [form.object_name, filter.name, value].join('_').underscore -%>
|
7
|
-
<%= form.
|
8
|
-
<%= form.
|
8
|
+
<%= form.datagrid_label(filter.name, for: id, **options) do -%>
|
9
|
+
<%= form.datagrid_filter_input(filter.name, id: id, value: value) -%>
|
9
10
|
<%= text -%>
|
10
11
|
<%- end -%>
|
11
12
|
<%- end -%>
|
13
|
+
</div>
|
@@ -1,12 +1,12 @@
|
|
1
|
-
<%=
|
1
|
+
<%= form_with model: grid, html: {class: 'datagrid-form'}, scope: grid.param_name, method: :get, **options do |f| %>
|
2
2
|
<% grid.filters.each do |filter| %>
|
3
|
-
<div class="datagrid-filter filter">
|
3
|
+
<div class="datagrid-filter" data-filter="<%= filter.name %>" data-type="<%= filter.type %>">
|
4
4
|
<%= f.datagrid_label filter %>
|
5
5
|
<%= f.datagrid_filter filter %>
|
6
6
|
</div>
|
7
7
|
<% end %>
|
8
8
|
<div class="datagrid-actions">
|
9
|
-
<%= f.submit I18n.t("datagrid.form.search")
|
10
|
-
<%= link_to I18n.t('datagrid.form.reset')
|
9
|
+
<%= f.submit I18n.t("datagrid.form.search"), class: "datagrid-submit" %>
|
10
|
+
<%= link_to I18n.t('datagrid.form.reset'), url_for(grid.to_param => {}), class: "datagrid-reset" %>
|
11
11
|
</div>
|
12
12
|
<% end -%>
|
@@ -1,8 +1,31 @@
|
|
1
1
|
<tr>
|
2
2
|
<% grid.html_columns(*options[:columns]).each do |column| %>
|
3
|
-
|
3
|
+
<%= tag.th(
|
4
|
+
# Consider maintaining consistency with datagrid/rows partial
|
5
|
+
"data-column": column.name,
|
6
|
+
**column.tag_options,
|
7
|
+
class: [
|
8
|
+
column.tag_options[:class],
|
9
|
+
# Adding HTML classes based on condition
|
10
|
+
"datagrid-order-active-asc": grid.ordered_by?(column, false),
|
11
|
+
"datagrid-order-active-desc": grid.ordered_by?(column, true),
|
12
|
+
]
|
13
|
+
) do %>
|
4
14
|
<%= column.header %>
|
5
|
-
|
6
|
-
|
15
|
+
<% if column.supports_order? && options[:order] -%>
|
16
|
+
<div class="datagrid-order">
|
17
|
+
<%= link_to(
|
18
|
+
I18n.t("datagrid.table.order.asc"),
|
19
|
+
datagrid_order_path(grid, column, false),
|
20
|
+
class: "datagrid-order-control-asc"
|
21
|
+
) %>
|
22
|
+
<%= link_to(
|
23
|
+
I18n.t("datagrid.table.order.desc"),
|
24
|
+
datagrid_order_path(grid, column, true),
|
25
|
+
class: "datagrid-order-control-desc"
|
26
|
+
) %>
|
27
|
+
</div>
|
28
|
+
<% end -%>
|
29
|
+
<% end -%>
|
7
30
|
<% end %>
|
8
31
|
</tr>
|
@@ -1,3 +1,5 @@
|
|
1
|
-
<%= form.datagrid_filter_input(filter, **from_options) %>
|
2
|
-
<span class="separator
|
3
|
-
|
1
|
+
<%= form.datagrid_filter_input(filter, class: 'datagrid-range-from', **from_options) %>
|
2
|
+
<span class="datagrid-range-separator"><%= I18n.t('datagrid.filters.range.separator') %></span>
|
3
|
+
<%# Generating id only for "from" input to make sure -%>
|
4
|
+
<%# there is no duplicate id in DOM and click on label focuses the first input -%>
|
5
|
+
<%= form.datagrid_filter_input(filter, class: 'datagrid-range-to', **to_options, id: nil) %>
|
@@ -1,5 +1,16 @@
|
|
1
1
|
<tr>
|
2
2
|
<% grid.html_columns(*options[:columns]).each do |column| %>
|
3
|
-
|
3
|
+
<%= tag.td(
|
4
|
+
datagrid_value(grid, column, asset),
|
5
|
+
# Consider maintaining consistency with datagrid/rows partial
|
6
|
+
"data-column": column.name,
|
7
|
+
**column.tag_options,
|
8
|
+
class: [
|
9
|
+
column.tag_options[:class],
|
10
|
+
# Adding HTML classes based on condition
|
11
|
+
"datagrid-order-active-asc": grid.ordered_by?(column, false),
|
12
|
+
"datagrid-order-active-desc": grid.ordered_by?(column, true),
|
13
|
+
]
|
14
|
+
) %>
|
4
15
|
<% end %>
|
5
16
|
</tr>
|
@@ -5,18 +5,18 @@ Local variables:
|
|
5
5
|
* options - passed options Hash
|
6
6
|
%>
|
7
7
|
<% if grid.html_columns(*options[:columns]).any? %>
|
8
|
-
<%=
|
8
|
+
<%= tag.table class: 'datagrid-table', **options.fetch(:html, {}) do %>
|
9
9
|
<thead>
|
10
|
-
<%= datagrid_header(grid, options) %>
|
10
|
+
<%= datagrid_header(grid, **options) %>
|
11
11
|
</thead>
|
12
12
|
<tbody>
|
13
13
|
<% if assets.any? %>
|
14
14
|
<%= datagrid_rows(grid, assets, **options) %>
|
15
15
|
<% else %>
|
16
|
-
<tr><td class="
|
16
|
+
<tr><td class="datagrid-no-results" colspan="100%"><%= I18n.t('datagrid.no_results') %></td></tr>
|
17
17
|
<% end %>
|
18
18
|
</tbody>
|
19
19
|
<% end %>
|
20
20
|
<% else -%>
|
21
|
-
<%= I18n.t("datagrid.table.no_columns")
|
21
|
+
<%= I18n.t("datagrid.table.no_columns") %>
|
22
22
|
<% end %>
|
data/datagrid.gemspec
CHANGED
@@ -12,26 +12,27 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = "agresso@gmail.com"
|
13
13
|
s.extra_rdoc_files = [
|
14
14
|
"LICENSE.txt",
|
15
|
-
"
|
15
|
+
"README.md",
|
16
16
|
]
|
17
17
|
s.files = [
|
18
18
|
"LICENSE.txt",
|
19
19
|
"CHANGELOG.md",
|
20
|
-
"
|
20
|
+
"README.md",
|
21
21
|
"datagrid.gemspec",
|
22
|
+
".yardopts",
|
22
23
|
]
|
23
24
|
s.files += `git ls-files | grep -E '^(app|lib|templates)'`.split("\n")
|
24
25
|
s.homepage = "https://github.com/bogdan/datagrid"
|
25
26
|
s.licenses = ["MIT"]
|
26
|
-
s.required_ruby_version = Gem::Requirement.new(">=
|
27
|
+
s.required_ruby_version = Gem::Requirement.new(">= 3.0")
|
27
28
|
s.metadata = {
|
28
29
|
"homepage_uri" => s.homepage,
|
29
30
|
"bug_tracker_uri" => "#{s.homepage}/issues",
|
30
|
-
"documentation_uri" => "
|
31
|
-
"changelog_uri" => "#{s.homepage}/blob/
|
31
|
+
"documentation_uri" => "https://rubydoc.info/gems/datagrid",
|
32
|
+
"changelog_uri" => "#{s.homepage}/blob/main/CHANGELOG.md",
|
32
33
|
"source_code_uri" => s.homepage,
|
34
|
+
"rubygems_mfa_required" => "true",
|
33
35
|
}
|
34
36
|
|
35
|
-
s.add_dependency "railties", ">=
|
37
|
+
s.add_dependency "railties", ">= 7.0"
|
36
38
|
end
|
37
|
-
|
@@ -1,27 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Datagrid
|
2
4
|
# Required to be ActiveModel compatible
|
3
5
|
module ActiveModel
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
require 'active_model/naming'
|
10
|
-
extend ::ActiveModel::Naming
|
11
|
-
rescue LoadError
|
12
|
-
end
|
13
|
-
begin
|
14
|
-
require 'active_model/attributes_assignment'
|
15
|
-
extend ::ActiveModel::AttributesAssignment
|
16
|
-
rescue LoadError
|
17
|
-
end
|
18
|
-
end
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
require "active_model/naming"
|
10
|
+
extend ::ActiveModel::Naming
|
19
11
|
end
|
20
12
|
|
21
13
|
module ClassMethods
|
22
14
|
# @return [String] URL query parameter name of the grid class
|
23
15
|
def param_name
|
24
|
-
|
16
|
+
to_s.underscore.tr("/", "_")
|
25
17
|
end
|
26
18
|
end
|
27
19
|
|
@@ -48,7 +40,7 @@ module Datagrid
|
|
48
40
|
end
|
49
41
|
|
50
42
|
def to_param
|
51
|
-
|
43
|
+
param_name
|
52
44
|
end
|
53
45
|
end
|
54
46
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Datagrid
|
4
|
+
extend ActiveSupport::Autoload
|
5
|
+
|
6
|
+
autoload :Core
|
7
|
+
autoload :ActiveModel
|
8
|
+
autoload :Filters
|
9
|
+
autoload :Columns
|
10
|
+
autoload :ColumnNamesAttribute
|
11
|
+
autoload :Ordering
|
12
|
+
autoload :Configuration
|
13
|
+
|
14
|
+
autoload :Helper
|
15
|
+
autoload :FormBuilder
|
16
|
+
|
17
|
+
autoload :Engine
|
18
|
+
|
19
|
+
# Main datagrid class allowing to define columns and filters on your objects
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# class UsersGrid < Datagrid::Base
|
23
|
+
# scope { User }
|
24
|
+
#
|
25
|
+
# filter(:id, :integer)
|
26
|
+
# filter(:name, :string)
|
27
|
+
#
|
28
|
+
# column(:id)
|
29
|
+
# column(:name)
|
30
|
+
# end
|
31
|
+
class Base
|
32
|
+
include ::Datagrid::Core
|
33
|
+
include ::Datagrid::ActiveModel
|
34
|
+
include ::Datagrid::Filters
|
35
|
+
include ::Datagrid::Columns
|
36
|
+
include ::Datagrid::ColumnNamesAttribute
|
37
|
+
include ::Datagrid::Ordering
|
38
|
+
end
|
39
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Datagrid
|
2
4
|
module ColumnNamesAttribute
|
3
5
|
extend ActiveSupport::Concern
|
@@ -21,6 +23,7 @@ module Datagrid
|
|
21
23
|
# will always present in the grid table and won't be listed
|
22
24
|
# in column names selection
|
23
25
|
# Accepts same options as <tt>:enum</tt> filter
|
26
|
+
# @return [Datagrid::Filters::BaseFilter] Defined filter object
|
24
27
|
# @example
|
25
28
|
# column_names_filter(header: "Choose columns")
|
26
29
|
# @see Datagrid::Filters::ClassMethods#filter
|
@@ -44,7 +47,7 @@ module Datagrid
|
|
44
47
|
# If no mandatory columns specified than all of them considered mandatory
|
45
48
|
# @return [Array<Datagrid::Columns::Column>]
|
46
49
|
def mandatory_columns
|
47
|
-
available_columns.select
|
50
|
+
available_columns.select(&:mandatory?)
|
48
51
|
end
|
49
52
|
|
50
53
|
# Returns a list of enabled columns without <tt>mandatory: true</tt> option
|
@@ -57,7 +60,7 @@ module Datagrid
|
|
57
60
|
protected
|
58
61
|
|
59
62
|
def optional_columns_select
|
60
|
-
optional_columns.map {|c| [c.header, c.name] }
|
63
|
+
optional_columns.map { |c| [c.header, c.name] }
|
61
64
|
end
|
62
65
|
|
63
66
|
def selected_column_names(*args)
|
@@ -67,19 +70,15 @@ module Datagrid
|
|
67
70
|
column.is_a?(Datagrid::Columns::Column) ? column.name : column.to_sym
|
68
71
|
end
|
69
72
|
args
|
73
|
+
elsif column_names&.any?
|
74
|
+
column_names + mandatory_columns.map(&:name)
|
70
75
|
else
|
71
|
-
|
72
|
-
column_names + mandatory_columns.map(&:name)
|
73
|
-
else
|
74
|
-
columns_enabled_by_default.map(&:name)
|
75
|
-
end
|
76
|
+
columns_enabled_by_default.map(&:name)
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
80
|
def columns_visibility_enabled?
|
80
|
-
columns_array.any?
|
81
|
-
column.mandatory_explicitly_set?
|
82
|
-
end
|
81
|
+
columns_array.any?(&:mandatory_explicitly_set?)
|
83
82
|
end
|
84
83
|
|
85
84
|
def columns_enabled_by_default
|
@@ -87,4 +86,3 @@ module Datagrid
|
|
87
86
|
end
|
88
87
|
end
|
89
88
|
end
|
90
|
-
|