katalyst-tables 3.0.0 → 3.1.0
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.md +15 -3
- data/app/assets/stylesheets/katalyst/tables/_index.scss +1 -0
- data/app/assets/stylesheets/katalyst/tables/_summary.scss +14 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_boolean.scss +1 -1
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_currency.scss +3 -0
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_date.scss +1 -1
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_datetime.scss +1 -1
- data/app/assets/stylesheets/katalyst/tables/typed-columns/_number.scss +3 -0
- data/app/components/concerns/katalyst/tables/has_table_content.rb +2 -2
- data/app/components/concerns/katalyst/tables/row_renderer.rb +1 -1
- data/app/components/concerns/katalyst/tables/sortable.rb +1 -1
- data/app/components/katalyst/summary_table_component.html.erb +15 -0
- data/app/components/katalyst/summary_table_component.rb +44 -0
- data/app/components/katalyst/tables/summary/body_component.html.erb +3 -0
- data/app/components/katalyst/tables/summary/body_component.rb +10 -0
- data/app/components/katalyst/tables/summary/header_component.html.erb +3 -0
- data/app/components/katalyst/tables/summary/header_component.rb +10 -0
- data/app/components/katalyst/tables/summary/row_component.html.erb +4 -0
- data/app/components/katalyst/tables/summary/row_component.rb +12 -0
- data/app/controllers/concerns/katalyst/tables/backend.rb +15 -0
- data/app/helpers/katalyst/tables/frontend.rb +19 -0
- data/app/models/concerns/katalyst/tables/collection/pagination.rb +2 -2
- data/app/models/concerns/katalyst/tables/collection/sorting.rb +2 -2
- data/app/models/katalyst/tables/collection/filter.rb +2 -2
- data/config/importmap.rb +1 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 196a8b7ff382215cbb156ff83099071aa983176353f819f5031aac774a88a572
|
4
|
+
data.tar.gz: 3d7463ccb20935e52500f186fb7c4024f3c8c236bfb9338a331a0830bf58edb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 325bfa1b161fa322acd419279a57ddb644f5a3e0289ca42294c9936fe7ea6fcded6f1d077f8866b5b70408d7d495c8dabe4733ba83a1f7652c4eb02115bc5438
|
7
|
+
data.tar.gz: 1382995a15fdc57829232223d67d20a691b9f5b908f4059c7b41dcfdb9396ce1d90f3431417ceb2b88a10eca880939608b20ec19dc421288f25b8c6bfad0c58c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -32,10 +32,11 @@ application.load(tables);
|
|
32
32
|
## Usage
|
33
33
|
|
34
34
|
This gem provides entry points for backend and frontend concerns:
|
35
|
-
* `Katalyst::TableComponent` can be used render encapsulated tables
|
36
|
-
* `Katalyst::
|
35
|
+
* `Katalyst::TableComponent` can be used render encapsulated tables,
|
36
|
+
* `Katalyst::SummaryTableComponent` can be used render a record using the table syntax,
|
37
|
+
* `Katalyst::Tables::Frontend` provides `table_with` for inline table generation,
|
37
38
|
* `Katalyst::Tables::Collection::Base` provides a default entry point for
|
38
|
-
building collections in your controller actions
|
39
|
+
building collections in your controller actions
|
39
40
|
|
40
41
|
### Frontend
|
41
42
|
|
@@ -205,6 +206,17 @@ detect features such as sorting and generate the appropriate table header links.
|
|
205
206
|
<%= table_with(collection:) %>
|
206
207
|
```
|
207
208
|
|
209
|
+
## Summary tables
|
210
|
+
You can use the `Katalyst::SummaryTableComponent` to render a single record utilizing all the functionality from the
|
211
|
+
`Katalyst::TableComponent`.
|
212
|
+
|
213
|
+
```erb
|
214
|
+
<%= summary_table_with model: @person do |row| %>
|
215
|
+
<% row.text :name %>
|
216
|
+
<% row.text :email %>
|
217
|
+
<% end %>
|
218
|
+
```
|
219
|
+
|
208
220
|
## Extensions
|
209
221
|
|
210
222
|
The following extensions are available and activated by default:
|
@@ -5,8 +5,8 @@ module Katalyst
|
|
5
5
|
module HasTableContent # :nodoc:
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
def initialize(object_name: nil, partial: nil, as: nil, **
|
9
|
-
super(**
|
8
|
+
def initialize(object_name: nil, partial: nil, as: nil, **)
|
9
|
+
super(**)
|
10
10
|
|
11
11
|
@object_name = object_name || model_name&.i18n_key
|
12
12
|
@partial = partial
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%# Simulating a normal table render for the side effects %>
|
2
|
+
<% capture do %>
|
3
|
+
<%= header_row %>
|
4
|
+
<% body_rows.each do |body| %>
|
5
|
+
<%= body %>
|
6
|
+
<% end %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<%= tag.table(**html_attributes) do %>
|
10
|
+
<%= tag.tbody(**tbody_attributes) do %>
|
11
|
+
<% summary_rows.each do |summary_row| %>
|
12
|
+
<%= summary_row %>
|
13
|
+
<% end %>
|
14
|
+
<% end %>
|
15
|
+
<% end %>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Katalyst
|
4
|
+
# A component for rendering a summary table for a model.
|
5
|
+
# @example
|
6
|
+
# <%= Katalyst::SummaryTableComponent.new(model: @person) do |row, person| %>
|
7
|
+
# <%= row.text :name do |cell| %>
|
8
|
+
# <%= link_to cell.value, person %>
|
9
|
+
# <% end %>
|
10
|
+
# <%= row.text :email %>
|
11
|
+
# <% end %>
|
12
|
+
# Generates:
|
13
|
+
# <table>
|
14
|
+
# <tr><th>Name</th><td><a href="/people/1">Aaron</a></td></tr>
|
15
|
+
# <tr><th>Email</th><td>aaron@example.com</td></tr>
|
16
|
+
# </table>
|
17
|
+
class SummaryTableComponent < TableComponent
|
18
|
+
renders_many :summary_rows, Tables::Summary::RowComponent
|
19
|
+
|
20
|
+
def initialize(model:, **)
|
21
|
+
super(collection: [model], **)
|
22
|
+
|
23
|
+
@summary_rows = []
|
24
|
+
|
25
|
+
update_html_attributes(class: "summary-table")
|
26
|
+
end
|
27
|
+
|
28
|
+
def with_cell(cell, &)
|
29
|
+
if row.header?
|
30
|
+
@summary_rows << with_summary_row do |row|
|
31
|
+
row.with_header do |header|
|
32
|
+
header.with_cell(cell)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@index = 0
|
36
|
+
else
|
37
|
+
@summary_rows[@index].with_body do |body|
|
38
|
+
body.with_cell(cell, &)
|
39
|
+
end
|
40
|
+
@index += 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -8,6 +8,7 @@ module Katalyst
|
|
8
8
|
|
9
9
|
included do
|
10
10
|
class_attribute :_default_table_component, instance_accessor: false
|
11
|
+
class_attribute :_default_summary_table_component, instance_accessor: false
|
11
12
|
end
|
12
13
|
|
13
14
|
class_methods do
|
@@ -18,12 +19,26 @@ module Katalyst
|
|
18
19
|
def default_table_component(component)
|
19
20
|
self._default_table_component = component
|
20
21
|
end
|
22
|
+
|
23
|
+
# Set the summary table component to be used as the default for all
|
24
|
+
# summary tables in the views rendered by this controller and its
|
25
|
+
# subclasses.
|
26
|
+
#
|
27
|
+
# @param component [Class] the summary table component class to use
|
28
|
+
def default_summary_table_component(component)
|
29
|
+
self._default_summary_table_component = component
|
30
|
+
end
|
21
31
|
end
|
22
32
|
|
23
33
|
# Default table component for this controller
|
24
34
|
def default_table_component
|
25
35
|
self.class._default_table_component
|
26
36
|
end
|
37
|
+
|
38
|
+
# Default summary table component for this controller
|
39
|
+
def default_summary_table_component
|
40
|
+
self.class._default_summary_table_component
|
41
|
+
end
|
27
42
|
end
|
28
43
|
end
|
29
44
|
end
|
@@ -55,12 +55,31 @@ module Katalyst
|
|
55
55
|
render(Selectable::FormComponent.new(collection:, id:, primary_key:), &)
|
56
56
|
end
|
57
57
|
|
58
|
+
# Construct a new summary table component.
|
59
|
+
#
|
60
|
+
# @param model [ActiveRecord::Base] subject for the table
|
61
|
+
#
|
62
|
+
# Blocks will receive the table in row-rendering mode (with row and record defined):
|
63
|
+
# @yieldparam [Katalyst::TableComponent] the table component to render rows
|
64
|
+
# @yieldparam [nil, Object] nil for the header column, or the given model for the value column
|
65
|
+
def summary_table_with(model:, **, &)
|
66
|
+
component ||= default_summary_table_component_class
|
67
|
+
component = component.new(model:, **)
|
68
|
+
|
69
|
+
render(component, &)
|
70
|
+
end
|
71
|
+
|
58
72
|
private
|
59
73
|
|
60
74
|
def default_table_component_class
|
61
75
|
component = controller.try(:default_table_component) || TableComponent
|
62
76
|
component.respond_to?(:constantize) ? component.constantize : component
|
63
77
|
end
|
78
|
+
|
79
|
+
def default_summary_table_component_class
|
80
|
+
component = controller.try(:default_summary_table_component) || SummaryTableComponent
|
81
|
+
component.respond_to?(:constantize) ? component.constantize : component
|
82
|
+
end
|
64
83
|
end
|
65
84
|
end
|
66
85
|
end
|
@@ -45,10 +45,10 @@ module Katalyst
|
|
45
45
|
attr_reader :default_sort
|
46
46
|
end
|
47
47
|
|
48
|
-
def initialize(sorting: config.sorting, **
|
48
|
+
def initialize(sorting: config.sorting, **)
|
49
49
|
@default_sort = sorting.to_param if sorting.present?
|
50
50
|
|
51
|
-
super(sort: @default_sort, **
|
51
|
+
super(sort: @default_sort, **) # set default sort based on config
|
52
52
|
end
|
53
53
|
|
54
54
|
def default_sort?
|
data/config/importmap.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katalyst-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katalyst Interactive
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: katalyst-html-attributes
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- app/assets/config/katalyst-tables.js
|
57
57
|
- app/assets/stylesheets/katalyst/tables/_index.scss
|
58
58
|
- app/assets/stylesheets/katalyst/tables/_ordinal.scss
|
59
|
+
- app/assets/stylesheets/katalyst/tables/_summary.scss
|
59
60
|
- app/assets/stylesheets/katalyst/tables/_table.scss
|
60
61
|
- app/assets/stylesheets/katalyst/tables/typed-columns/_boolean.scss
|
61
62
|
- app/assets/stylesheets/katalyst/tables/typed-columns/_currency.scss
|
@@ -69,6 +70,8 @@ files:
|
|
69
70
|
- app/components/concerns/katalyst/tables/row_renderer.rb
|
70
71
|
- app/components/concerns/katalyst/tables/selectable.rb
|
71
72
|
- app/components/concerns/katalyst/tables/sortable.rb
|
73
|
+
- app/components/katalyst/summary_table_component.html.erb
|
74
|
+
- app/components/katalyst/summary_table_component.rb
|
72
75
|
- app/components/katalyst/table_component.html.erb
|
73
76
|
- app/components/katalyst/table_component.rb
|
74
77
|
- app/components/katalyst/tables/body_row_component.html.erb
|
@@ -92,6 +95,12 @@ files:
|
|
92
95
|
- app/components/katalyst/tables/pagy_nav_component.rb
|
93
96
|
- app/components/katalyst/tables/selectable/form_component.html.erb
|
94
97
|
- app/components/katalyst/tables/selectable/form_component.rb
|
98
|
+
- app/components/katalyst/tables/summary/body_component.html.erb
|
99
|
+
- app/components/katalyst/tables/summary/body_component.rb
|
100
|
+
- app/components/katalyst/tables/summary/header_component.html.erb
|
101
|
+
- app/components/katalyst/tables/summary/header_component.rb
|
102
|
+
- app/components/katalyst/tables/summary/row_component.html.erb
|
103
|
+
- app/components/katalyst/tables/summary/row_component.rb
|
95
104
|
- app/controllers/concerns/katalyst/tables/backend.rb
|
96
105
|
- app/helpers/katalyst/tables/frontend.rb
|
97
106
|
- app/javascript/tables/application.js
|
@@ -131,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
140
|
requirements:
|
132
141
|
- - ">="
|
133
142
|
- !ruby/object:Gem::Version
|
134
|
-
version: 3.
|
143
|
+
version: 3.3.0
|
135
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
145
|
requirements:
|
137
146
|
- - ">="
|