datagrid 1.8.2 → 2.0.0.pre.alpha

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/{Readme.markdown → README.md} +44 -27
  4. data/app/assets/stylesheets/datagrid.css +145 -0
  5. data/app/views/datagrid/_enum_checkboxes.html.erb +5 -3
  6. data/app/views/datagrid/_form.html.erb +4 -4
  7. data/app/views/datagrid/_head.html.erb +26 -3
  8. data/app/views/datagrid/_range_filter.html.erb +5 -3
  9. data/app/views/datagrid/_row.html.erb +12 -1
  10. data/app/views/datagrid/_table.html.erb +4 -4
  11. data/datagrid.gemspec +6 -6
  12. data/lib/datagrid/active_model.rb +9 -17
  13. data/lib/datagrid/base.rb +39 -0
  14. data/lib/datagrid/column_names_attribute.rb +9 -11
  15. data/lib/datagrid/columns/column.rb +155 -133
  16. data/lib/datagrid/columns.rb +254 -45
  17. data/lib/datagrid/configuration.rb +23 -10
  18. data/lib/datagrid/core.rb +89 -54
  19. data/lib/datagrid/deprecated_object.rb +20 -0
  20. data/lib/datagrid/drivers/abstract_driver.rb +12 -23
  21. data/lib/datagrid/drivers/active_record.rb +24 -26
  22. data/lib/datagrid/drivers/array.rb +22 -14
  23. data/lib/datagrid/drivers/mongo_mapper.rb +15 -14
  24. data/lib/datagrid/drivers/mongoid.rb +15 -17
  25. data/lib/datagrid/drivers/sequel.rb +14 -19
  26. data/lib/datagrid/drivers.rb +2 -1
  27. data/lib/datagrid/engine.rb +11 -3
  28. data/lib/datagrid/filters/base_filter.rb +166 -142
  29. data/lib/datagrid/filters/boolean_filter.rb +19 -5
  30. data/lib/datagrid/filters/date_filter.rb +33 -35
  31. data/lib/datagrid/filters/date_time_filter.rb +24 -16
  32. data/lib/datagrid/filters/default_filter.rb +9 -3
  33. data/lib/datagrid/filters/dynamic_filter.rb +151 -105
  34. data/lib/datagrid/filters/enum_filter.rb +43 -19
  35. data/lib/datagrid/filters/extended_boolean_filter.rb +39 -30
  36. data/lib/datagrid/filters/float_filter.rb +16 -5
  37. data/lib/datagrid/filters/integer_filter.rb +21 -10
  38. data/lib/datagrid/filters/ranged_filter.rb +66 -45
  39. data/lib/datagrid/filters/select_options.rb +58 -49
  40. data/lib/datagrid/filters/string_filter.rb +9 -4
  41. data/lib/datagrid/filters.rb +190 -57
  42. data/lib/datagrid/form_builder.rb +116 -128
  43. data/lib/datagrid/generators/scaffold.rb +185 -0
  44. data/lib/datagrid/generators/views.rb +20 -0
  45. data/lib/datagrid/helper.rb +397 -22
  46. data/lib/datagrid/ordering.rb +26 -29
  47. data/lib/datagrid/rspec.rb +6 -10
  48. data/lib/datagrid/utils.rb +37 -30
  49. data/lib/datagrid/version.rb +3 -1
  50. data/lib/datagrid.rb +18 -28
  51. data/templates/base.rb.erb +6 -4
  52. data/templates/grid.rb.erb +1 -1
  53. metadata +15 -16
  54. data/app/assets/stylesheets/datagrid.sass +0 -134
  55. data/lib/datagrid/filters/composite_filters.rb +0 -49
  56. data/lib/datagrid/renderer.rb +0 -157
  57. data/lib/datagrid/scaffold.rb +0 -129
  58. data/lib/tasks/datagrid_tasks.rake +0 -15
  59. data/templates/controller.rb.erb +0 -6
  60. data/templates/index.html.erb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df8447e3bdc797a74cbbc4d7aac869bac6c0bcd57500d58bf14c1f3af5db7df9
4
- data.tar.gz: aa0c1a716ad3a7054db53f7605222d1386b73a8378c0eaf3087fd60477361bd3
3
+ metadata.gz: 37409811e25a50a023aa095fb8854424fea3867e137b8d212d619ba191307abe
4
+ data.tar.gz: 2485f8f3a8cf9d196011a584e680c345d147430ef3d263b151569ae10fc3ef69
5
5
  SHA512:
6
- metadata.gz: 9bffeed51b8a4d994136931096f5c7438243ad73c2c46540c7f20a2a542e25c6644b970ddc1e2fc10673de94b1d1f6a0d1892caf7cdc4fec38bde67324767508
7
- data.tar.gz: d3ccf6646f9b8c21f0b8c2a81853294c9e8069c5a17644617c57d1de675be8bb380237aafb9f5b12e21ac49c909376bbf53d0d4e30e50a96387c070c8919fc59
6
+ metadata.gz: 2974b76d03c7a3c014a3b853570ae0a11e2c137f0e4faea6be0dfcff45b49e4c64037298337e0f9e3028ecd64d938747770903469888339e6a43bbcc03330a59
7
+ data.tar.gz: 52d188d5c0e6a41a3f44061274695b5eee22f7c669c1814f26ae38cfeee364b66c8437ca85c55fa3a73d8fe3333e6c9820fda9b1e2ccee770d48bcba7d72bfe3
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## master
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
- [![Build Status](https://github.com/bogdan/datagrid/workflows/CI/badge.svg?branch=master)](https://github.com/bogdan/datagrid/actions)
3
+ Datagrid Version 2.0.0 is here.
4
4
 
5
- [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fbogdan%2Fdatagrid?ref=badge_shield)
5
+ [Migration Guide](./version-2).
6
6
 
7
- A really mighty and flexible ruby library that generates reports including admin panels, analytics and data representation:
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,44 @@ A really mighty and flexible ruby library that generates reports including admin
12
15
  * Localization
13
16
  * Export to CSV
14
17
 
15
- ### ORM Support
18
+ ## ORM Support
16
19
 
17
20
  * ActiveRecord
18
21
  * Mongoid
19
22
  * MongoMapper
20
23
  * Sequel
21
- * Array (slow but possible)
24
+ * Array (in-memory data of smaller scale)
22
25
 
23
26
  [Create an issue](https://github.com/bogdan/datagrid/issues/new) if you want more.
24
27
 
25
- ### Documentation
28
+ ## Datagrid Philosophy
29
+
30
+ 1. Expressive DSL complements OOD instead of replacing it.
31
+ 1. Extensible in every way while providing a lot of defaults.
32
+ 1. If your ORM supports that, datagrid also supports that!
33
+
34
+ ## Documentation
26
35
 
27
- * [Readme](/Readme.markdown) - this read-me for basic information
28
- * [Wiki](https://github.com/bogdan/datagrid/wiki) - general reference on how to use the gem
29
- * [Rdoc](https://rubydoc.info/gems/datagrid) - API reference
36
+ * [Rdoc](https://rubydoc.info/gems/datagrid) - full API reference
37
+ * [Scope](https://rubydoc.info/gems/datagrid/Datagrid/Core) - working with datagrid scope
38
+ * [Columns](https://rubydoc.info/gems/datagrid/Datagrid/Columns) - definging datagrid columns
39
+ * [Filters](https://rubydoc.info/gems/datagrid/Datagrid/Filters) - defining datagrid filters
40
+ * [Frontend](https://rubydoc.info/gems/datagrid/Datagrid/Helper) - building a frontend
41
+ * [Configuration](https://rubydoc.info/gems/datagrid/Datagrid/Configuration) - configuring the gem
30
42
 
31
43
  ### Live Demo
32
44
 
33
45
  [Datagrid DEMO application](http://datagrid.herokuapp.com) is available live!
34
46
  [Demo source code](https://github.com/bogdan/datagrid-demo).
35
47
 
36
- <img src="http://datagrid.herokuapp.com/datagrid_demo_screenshot.png" style="margin: 7px; border: 1px solid black">
48
+ <!-- <img src="http://datagrid.herokuapp.com/datagrid_demo_screenshot.png" style="margin: 7px; border: 1px solid black"> -->
37
49
 
38
50
  ### Example
39
51
 
40
52
  In order to create a grid:
41
53
 
42
54
  ``` ruby
43
- class UsersGrid
44
-
45
- include Datagrid
55
+ class UsersGrid < Datagrid::Base
46
56
 
47
57
  scope do
48
58
  User.includes(:group)
@@ -71,7 +81,7 @@ Basic grid api:
71
81
 
72
82
  ``` ruby
73
83
  report = UsersGrid.new(
74
- group_id: [1,2],
84
+ group_id: [1,2],
75
85
  logins_count: [1, nil],
76
86
  category: "first",
77
87
  order: :group,
@@ -79,7 +89,10 @@ report = UsersGrid.new(
79
89
  )
80
90
 
81
91
  report.assets # => Array of User instances:
82
- # SELECT * FROM users WHERE users.group_id in (1,2) AND users.logins_count >= 1 AND users.category = 'first' ORDER BY groups.name DESC
92
+ # SELECT * FROM users WHERE users.group_id in (1,2) AND
93
+ # users.logins_count >= 1 AND
94
+ # users.category = 'first'
95
+ # ORDER BY groups.name DESC
83
96
 
84
97
  report.header # => ["Name", "Group", "Activated"]
85
98
  report.rows # => [
@@ -103,7 +116,8 @@ In order to create a report, you need to define:
103
116
  ### Scope
104
117
 
105
118
  Default scope of objects to filter and display.
106
- In common case it is `ActiveRecord::Base` (or any other supported ORM) subclass with some generic scopes like:
119
+ In common case it is `ActiveRecord::Base` (or any other supported ORM)
120
+ subclass with some generic scopes like:
107
121
 
108
122
  ``` ruby
109
123
  scope do
@@ -111,7 +125,7 @@ scope do
111
125
  end
112
126
  ```
113
127
 
114
- [More about scope](https://github.com/bogdan/datagrid/wiki/Scope)
128
+ [More about scope](https://rubydoc.info/gems/datagrid/Datagrid/Core)
115
129
 
116
130
  ### Filters
117
131
 
@@ -133,9 +147,9 @@ Datagrid supports different type of filters including:
133
147
  * xboolean - the select of "yes", "no" and any
134
148
  * enum - selection of the given values
135
149
  * string
136
- * dynamic - build dynamic SQL condition
150
+ * dynamic - build dynamic SQL condition
137
151
 
138
- [More about filters](https://github.com/bogdan/datagrid/wiki/Filters)
152
+ [More about filters](https://rubydoc.info/gems/datagrid/Datagrid/Filters)
139
153
 
140
154
  ### Columns
141
155
 
@@ -154,7 +168,7 @@ Each column is sortable.
154
168
 
155
169
  ### Front end
156
170
 
157
- ### Using Generator
171
+ #### Using Generator
158
172
 
159
173
  Datagrid has a builtin generator:
160
174
 
@@ -172,27 +186,29 @@ route resources :skills
172
186
  insert app/assets/stylesheet/application.css
173
187
  ```
174
188
 
175
- ### Customize Built-in partials
189
+ #### Customize Built-in views
176
190
 
177
- In order to get a control on datagrid built-in partials run:
191
+ In order to get a control on datagrid built-in views run:
178
192
 
179
193
  ``` sh
180
- rake datagrid:copy_partials
194
+ rails g datagrid::views
181
195
  ```
182
196
 
183
- ### Advanced frontend
197
+ #### Advanced frontend
184
198
 
185
199
  All advanced frontend things are described in:
186
200
 
187
- [Frontend section on wiki](https://github.com/bogdan/datagrid/wiki/Frontend)
201
+ [Frontend section on wiki](https://rubydoc.info/gems/datagrid/Datagrid/Helper)
188
202
 
189
203
  ## Questions & Issues
190
204
 
191
- If you have a question of any kind, just make an issue and describe your problem in details.
205
+ If you have a question of any kind, just make an issue and
206
+ describe your problem in details.
192
207
 
193
208
  ## Contribution
194
209
 
195
- If you are interested in contributing to this project, please follow the [instructions here](CONTRIBUTING.md).
210
+ If you are interested in contributing to this project,
211
+ please follow the [instructions here](CONTRIBUTING.md).
196
212
 
197
213
  ## Self-Promotion
198
214
 
@@ -203,4 +219,5 @@ Follow the repository on [GitHub](https://github.com/bogdan/datagrid).
203
219
  Read [author blog](http://gusiev.com).
204
220
 
205
221
  ## License
222
+
206
223
  [![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
- <%- elements.each do |value, text, checked| -%>
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.label filter.name, options.merge(for: id) do -%>
8
- <%= form.check_box(filter.name, {multiple: true, id: id, checked: checked, include_hidden: false}, value.to_s, nil) -%>
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
- <%= form_for grid, options do |f| -%>
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").html_safe, class: "datagrid-submit" %>
10
- <%= link_to I18n.t('datagrid.form.reset').html_safe, url_for(grid.to_param => {}), class: "datagrid-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
- <th class="<%= datagrid_column_classes(grid, column) %>">
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
- <%= datagrid_order_for(grid, column, options) if column.supports_order? && options[:order]%>
6
- </th>
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 <%= filter.type %>"><%= I18n.t('datagrid.filters.range.separator') %></span>
3
- <%= form.datagrid_filter_input(filter, **to_options) %>
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
- <td class="<%= datagrid_column_classes(grid, column) %>"><%= datagrid_value(grid, column, asset) %></td>
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
- <%= content_tag :table, options[:html] do %>
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="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
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").html_safe %>
21
+ <%= I18n.t("datagrid.table.no_columns") %>
22
22
  <% end %>
data/datagrid.gemspec CHANGED
@@ -12,26 +12,26 @@ Gem::Specification.new do |s|
12
12
  s.email = "agresso@gmail.com"
13
13
  s.extra_rdoc_files = [
14
14
  "LICENSE.txt",
15
- "Readme.markdown"
15
+ "README.md",
16
16
  ]
17
17
  s.files = [
18
18
  "LICENSE.txt",
19
19
  "CHANGELOG.md",
20
- "Readme.markdown",
20
+ "README.md",
21
21
  "datagrid.gemspec",
22
22
  ]
23
23
  s.files += `git ls-files | grep -E '^(app|lib|templates)'`.split("\n")
24
24
  s.homepage = "https://github.com/bogdan/datagrid"
25
25
  s.licenses = ["MIT"]
26
- s.required_ruby_version = Gem::Requirement.new(">= 2.7")
26
+ s.required_ruby_version = Gem::Requirement.new(">= 3.0")
27
27
  s.metadata = {
28
28
  "homepage_uri" => s.homepage,
29
29
  "bug_tracker_uri" => "#{s.homepage}/issues",
30
30
  "documentation_uri" => "#{s.homepage}/wiki",
31
- "changelog_uri" => "#{s.homepage}/blob/master/CHANGELOG.md",
31
+ "changelog_uri" => "#{s.homepage}/blob/main/CHANGELOG.md",
32
32
  "source_code_uri" => s.homepage,
33
+ "rubygems_mfa_required" => "true",
33
34
  }
34
35
 
35
- s.add_dependency "railties", ">= 6.1"
36
+ s.add_dependency "railties", ">= 7.0"
36
37
  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
- # @!visibility private
5
- def self.included(base)
6
- base.extend ClassMethods
7
- base.class_eval do
8
- begin
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
- self.to_s.underscore.tr('/', '_')
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
- self.param_name
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 {|c| c.mandatory? }
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
- if column_names && column_names.any?
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? do |column|
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
-