datagrid 1.8.1 → 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 +31 -7
  3. data/{Readme.markdown → README.md} +46 -29
  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 -5
  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 +8 -8
  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 +12 -12
  15. data/lib/datagrid/columns/column.rb +155 -133
  16. data/lib/datagrid/columns.rb +495 -282
  17. data/lib/datagrid/configuration.rb +23 -10
  18. data/lib/datagrid/core.rb +184 -150
  19. data/lib/datagrid/deprecated_object.rb +20 -0
  20. data/lib/datagrid/drivers/abstract_driver.rb +13 -25
  21. data/lib/datagrid/drivers/active_record.rb +24 -26
  22. data/lib/datagrid/drivers/array.rb +26 -17
  23. data/lib/datagrid/drivers/mongo_mapper.rb +15 -14
  24. data/lib/datagrid/drivers/mongoid.rb +16 -18
  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 -27
  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 +234 -106
  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 +81 -87
  47. data/lib/datagrid/rspec.rb +8 -12
  48. data/lib/datagrid/utils.rb +42 -38
  49. data/lib/datagrid/version.rb +3 -1
  50. data/lib/datagrid.rb +18 -28
  51. data/templates/base.rb.erb +33 -7
  52. data/templates/grid.rb.erb +1 -1
  53. metadata +18 -19
  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: 701bbc42a7501aa45a10d3899b92c9d1f745dae75b0a7eb219db1c339c182cb8
4
- data.tar.gz: cb309f1b9f08b3c1455c1b8650cf222867ba68721a9eb344b310bc5d7d5712e4
3
+ metadata.gz: 37409811e25a50a023aa095fb8854424fea3867e137b8d212d619ba191307abe
4
+ data.tar.gz: 2485f8f3a8cf9d196011a584e680c345d147430ef3d263b151569ae10fc3ef69
5
5
  SHA512:
6
- metadata.gz: 6bac4684420163514873a8a31bd06d182d216c8fff27f61d57368d605165838021a33d8603596ee04aee02e2b97a130308553bf36a8b6db0717f363b4c5ad472
7
- data.tar.gz: 4f6190ffaadbf77d0bc39ca632de5df1bcd2ef716bff40a5074b48f710d8b2257e0a95759fe8465a756819deb5e9202abb92a64783eae2bd3804d6c5ddf02e8a
6
+ metadata.gz: 2974b76d03c7a3c014a3b853570ae0a11e2c137f0e4faea6be0dfcff45b49e4c64037298337e0f9e3028ecd64d938747770903469888339e6a43bbcc03330a59
7
+ data.tar.gz: 52d188d5c0e6a41a3f44061274695b5eee22f7c669c1814f26ae38cfeee364b66c8437ca85c55fa3a73d8fe3333e6c9820fda9b1e2ccee770d48bcba7d72bfe3
data/CHANGELOG.md CHANGED
@@ -1,4 +1,24 @@
1
- ## master
1
+ # Changelog
2
+
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
14
+
15
+ ## 1.8.2
16
+
17
+ * Treat true/false as YES/NO when assigned as strings for xboolean filter.
18
+ * Support infinite ranges for date, datetime and integer filters.
19
+ * Treat `ActiveRecord::Result` class as `Array` driver.
20
+ * Add `Datagrid#reset` method to reset a column cache.
21
+ * Drop support of Rails 6.0 [#326](https://github.com/bogdan/datagrid/pull/326)
2
22
 
3
23
  ## 1.8.1
4
24
 
@@ -9,16 +29,20 @@
9
29
  * Support `input_options: {type: "textarea"}` as `<textarea/>` tag
10
30
  * Remove deprecated `eboolean` filter
11
31
  * Fixed scope wrapping to be universal
12
- * Deprecated `integer_range_filters` and `date_range_filters`. Use `filter(name, type, range: true)` instead.
13
- * Add `original_scope` method that returns scope as it was defined without any wrapping [#313](https://github.com/bogdan/datagrid/pull/313)
14
- * Add ability to specify `columns` option for `datagrid_row`. [#314](https://github.com/bogdan/datagrid/pull/314)
32
+ * Deprecated `integer_range_filters` and `date_range_filters`.
33
+ Use `filter(name, type, range: true)` instead.
34
+ * Add `original_scope` method that returns scope
35
+ as it was defined without any wrapping
36
+ [#313](https://github.com/bogdan/datagrid/pull/313)
37
+ * Add ability to specify `columns` option for `datagrid_row`.
38
+ [#314](https://github.com/bogdan/datagrid/pull/314)
15
39
 
16
40
  ## 1.7.0
17
41
 
18
42
  * Depend on `railties` instead of `rails` to prevent loading of unnecessary frameworks
19
- * Bugfix `File.exist?` usage for ruby 3.0 [#307](https://github.com/bogdan/datagrid/issues/307)
20
- * Drop support of old Ruby versions (< 2.7)
21
- * Drop support of old Rails versions (< 6.0)
43
+ * Bugfix `File.exist?` usage for Ruby 3.0 [#307](https://github.com/bogdan/datagrid/issues/307)
44
+ * Drop support of old Ruby versions (< 2.7) [#305](https://github.com/bogdan/datagrid/pull/305)
45
+ * Drop support of old Rails versions (< 6.0) [#305](https://github.com/bogdan/datagrid/pull/305)
22
46
 
23
47
  ## 1.6.3
24
48
 
@@ -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,38 +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
 
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!
25
33
 
26
- ### Documentation
34
+ ## Documentation
27
35
 
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://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
31
42
 
32
43
  ### Live Demo
33
44
 
34
45
  [Datagrid DEMO application](http://datagrid.herokuapp.com) is available live!
35
46
  [Demo source code](https://github.com/bogdan/datagrid-demo).
36
47
 
37
- <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"> -->
38
49
 
39
50
  ### Example
40
51
 
41
52
  In order to create a grid:
42
53
 
43
54
  ``` ruby
44
- class UsersGrid
45
-
46
- include Datagrid
55
+ class UsersGrid < Datagrid::Base
47
56
 
48
57
  scope do
49
58
  User.includes(:group)
@@ -72,7 +81,7 @@ Basic grid api:
72
81
 
73
82
  ``` ruby
74
83
  report = UsersGrid.new(
75
- group_id: [1,2],
84
+ group_id: [1,2],
76
85
  logins_count: [1, nil],
77
86
  category: "first",
78
87
  order: :group,
@@ -80,7 +89,10 @@ report = UsersGrid.new(
80
89
  )
81
90
 
82
91
  report.assets # => Array of User instances:
83
- # 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
84
96
 
85
97
  report.header # => ["Name", "Group", "Activated"]
86
98
  report.rows # => [
@@ -101,11 +113,11 @@ In order to create a report, you need to define:
101
113
  * filters that will be used to filter data
102
114
  * columns that should be displayed and sortable (if possible)
103
115
 
104
-
105
116
  ### Scope
106
117
 
107
118
  Default scope of objects to filter and display.
108
- 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:
109
121
 
110
122
  ``` ruby
111
123
  scope do
@@ -113,7 +125,7 @@ scope do
113
125
  end
114
126
  ```
115
127
 
116
- [More about scope](https://github.com/bogdan/datagrid/wiki/Scope)
128
+ [More about scope](https://rubydoc.info/gems/datagrid/Datagrid/Core)
117
129
 
118
130
  ### Filters
119
131
 
@@ -135,10 +147,9 @@ Datagrid supports different type of filters including:
135
147
  * xboolean - the select of "yes", "no" and any
136
148
  * enum - selection of the given values
137
149
  * string
138
- * dynamic - build dynamic SQL condition
139
-
140
- [More about filters](https://github.com/bogdan/datagrid/wiki/Filters)
150
+ * dynamic - build dynamic SQL condition
141
151
 
152
+ [More about filters](https://rubydoc.info/gems/datagrid/Datagrid/Filters)
142
153
 
143
154
  ### Columns
144
155
 
@@ -157,7 +168,7 @@ Each column is sortable.
157
168
 
158
169
  ### Front end
159
170
 
160
- ### Using Generator
171
+ #### Using Generator
161
172
 
162
173
  Datagrid has a builtin generator:
163
174
 
@@ -175,23 +186,29 @@ route resources :skills
175
186
  insert app/assets/stylesheet/application.css
176
187
  ```
177
188
 
178
- ### Customize Built-in partials
189
+ #### Customize Built-in views
179
190
 
180
- 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:
181
192
 
182
193
  ``` sh
183
- rake datagrid:copy_partials
194
+ rails g datagrid::views
184
195
  ```
185
196
 
186
- ### Advanced frontend
197
+ #### Advanced frontend
187
198
 
188
199
  All advanced frontend things are described in:
189
200
 
190
- [Frontend section on wiki](https://github.com/bogdan/datagrid/wiki/Frontend)
201
+ [Frontend section on wiki](https://rubydoc.info/gems/datagrid/Datagrid/Helper)
191
202
 
192
203
  ## Questions & Issues
193
204
 
194
- 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.
207
+
208
+ ## Contribution
209
+
210
+ If you are interested in contributing to this project,
211
+ please follow the [instructions here](CONTRIBUTING.md).
195
212
 
196
213
  ## Self-Promotion
197
214
 
@@ -201,6 +218,6 @@ Follow the repository on [GitHub](https://github.com/bogdan/datagrid).
201
218
 
202
219
  Read [author blog](http://gusiev.com).
203
220
 
204
-
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,13 +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
- <%# https://github.com/rails/rails/pull/14949 -%>
11
- <%= 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" %>
12
11
  </div>
13
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
@@ -7,31 +7,31 @@ Gem::Specification.new do |s|
7
7
  s.version = Datagrid::VERSION
8
8
  s.require_paths = ["lib"]
9
9
  s.authors = ["Bogdan Gusiev"]
10
- s.summary = "Ruby gem to create datagrids"
11
- s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
10
+ s.summary = "Library that provides DSL to present table like data"
11
+ s.description = "The library allows you to easily build datagrid aka data tables with sortable columns and filters"
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.0"
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