katalyst-tables 2.2.0 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/controllers/tables/orderable/form_controller.js +11 -5
- data/app/assets/javascripts/controllers/tables/orderable/item_controller.js +5 -2
- data/app/assets/javascripts/controllers/tables/orderable/list_controller.js +2 -2
- data/app/components/concerns/katalyst/tables/has_table_content.rb +1 -1
- data/app/components/concerns/katalyst/tables/orderable.rb +54 -23
- data/app/components/concerns/katalyst/tables/turbo_replaceable.rb +24 -7
- data/app/components/katalyst/turbo/table_component.rb +4 -4
- data/app/models/concerns/katalyst/tables/collection/core.rb +1 -1
- data/lib/katalyst/tables/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b8413e971a3164d1ab1fa688a20ce34e1f25768da7650565d9f600e1612a80e
|
4
|
+
data.tar.gz: d14455c86030073e293aafbaaf86a4da483be27912cca5a8d46cc43cc3a532b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5825f4058bc40aa823dbdd0719d8738a5fa4e4738442438c7e0c86ae9942cb5fc163d19b7754eb27b1abd061699dccfd79b249c93ceef8ce3605c101a4262522
|
7
|
+
data.tar.gz: ed4ccfa22d6342eff7c6f0a84ac6c28472263c249846594d794492c40c2b2a8bd9265f26fe897cb5a331c489b2b2d5caf59da98619ad16763a8a4dd4e8124f05
|
@@ -1,20 +1,26 @@
|
|
1
1
|
import { Controller } from "@hotwired/stimulus";
|
2
2
|
|
3
3
|
export default class OrderableFormController extends Controller {
|
4
|
-
add(
|
4
|
+
add(item, index) {
|
5
|
+
const { id_name, id_value, index_name } = item.paramsValue;
|
5
6
|
this.element.insertAdjacentHTML(
|
6
7
|
"beforeend",
|
7
|
-
`<input type="hidden" name="${
|
8
|
+
`<input type="hidden" name="${id_name}" value="${id_value}" data-generated>
|
9
|
+
<input type="hidden" name="${index_name}" value="${index}" data-generated>`,
|
8
10
|
);
|
9
11
|
}
|
10
12
|
|
11
13
|
submit() {
|
14
|
+
if (this.inputs.length === 0) return;
|
15
|
+
|
12
16
|
this.element.requestSubmit();
|
13
17
|
}
|
14
18
|
|
15
19
|
clear() {
|
16
|
-
this.
|
17
|
-
|
18
|
-
|
20
|
+
this.inputs.forEach((input) => input.remove());
|
21
|
+
}
|
22
|
+
|
23
|
+
get inputs() {
|
24
|
+
return this.element.querySelectorAll("input[data-generated]");
|
19
25
|
}
|
20
26
|
}
|
@@ -2,7 +2,10 @@ import { Controller } from "@hotwired/stimulus";
|
|
2
2
|
|
3
3
|
export default class OrderableRowController extends Controller {
|
4
4
|
static values = {
|
5
|
-
|
6
|
-
value: Number,
|
5
|
+
params: Object,
|
7
6
|
};
|
7
|
+
|
8
|
+
get index() {
|
9
|
+
return this.paramsValue.index_value;
|
10
|
+
}
|
8
11
|
}
|
@@ -41,8 +41,8 @@ export default class OrderableListController extends Controller {
|
|
41
41
|
|
42
42
|
// insert any items that have changed position
|
43
43
|
this.tablesOrderableItemOutlets.forEach((item, index) => {
|
44
|
-
if (item.
|
45
|
-
this.tablesOrderableFormOutlet.add(item
|
44
|
+
if (item.index !== index) {
|
45
|
+
this.tablesOrderableFormOutlet.add(item, index);
|
46
46
|
}
|
47
47
|
});
|
48
48
|
|
@@ -26,7 +26,7 @@ module Katalyst
|
|
26
26
|
def row_partial(row, record = nil)
|
27
27
|
partial = @partial || model_name&.param_key&.to_s
|
28
28
|
as = @as || model_name&.param_key&.to_sym
|
29
|
-
render(partial: partial, variants: [:row], locals: { as => record, row: row })
|
29
|
+
render(partial: partial, variants: [:row], formats: [:html], locals: { as => record, row: row })
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -13,28 +13,30 @@ module Katalyst
|
|
13
13
|
|
14
14
|
using HasHtmlAttributes
|
15
15
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
# Add `orderable` columns to row components
|
20
|
-
table_class.header_row_component.include(HeaderRow)
|
21
|
-
table_class.body_row_component.include(BodyRow)
|
22
|
-
|
16
|
+
# Support for inclusion in a table component class
|
17
|
+
# Adds an `orderable` slot and component configuration
|
18
|
+
included do
|
23
19
|
# Add `orderable` slot to table component
|
24
|
-
|
25
|
-
|
20
|
+
config_component :orderable, default: "Katalyst::Tables::Orderable::FormComponent"
|
21
|
+
renders_one(:orderable, lambda do |**attrs|
|
26
22
|
orderable_component.new(table: self, **attrs)
|
27
23
|
end)
|
28
24
|
end
|
29
25
|
|
30
|
-
# Support for inclusion in a table component class
|
31
|
-
included do
|
32
|
-
Orderable.make_orderable(self)
|
33
|
-
end
|
34
|
-
|
35
26
|
# Support for extending a table component instance
|
27
|
+
# Adds methods to the table component instance
|
36
28
|
def self.extended(table)
|
37
|
-
|
29
|
+
table.extend(TableMethods)
|
30
|
+
|
31
|
+
# ensure row components support orderable column calls
|
32
|
+
table.send(:add_orderable_columns)
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(**attributes)
|
36
|
+
super
|
37
|
+
|
38
|
+
# ensure row components support orderable column calls
|
39
|
+
add_orderable_columns
|
38
40
|
end
|
39
41
|
|
40
42
|
def tbody_attributes
|
@@ -53,6 +55,31 @@ module Katalyst
|
|
53
55
|
)
|
54
56
|
end
|
55
57
|
|
58
|
+
private
|
59
|
+
|
60
|
+
# Add `orderable` columns to row components
|
61
|
+
def add_orderable_columns
|
62
|
+
header_row_component.include(HeaderRow)
|
63
|
+
body_row_component.include(BodyRow)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Methods required to emulate a slot when extending an existing table.
|
67
|
+
module TableMethods
|
68
|
+
def with_orderable(**attrs)
|
69
|
+
@orderable = FormComponent.new(table: self, **attrs)
|
70
|
+
|
71
|
+
self
|
72
|
+
end
|
73
|
+
|
74
|
+
def orderable?
|
75
|
+
@orderable.present?
|
76
|
+
end
|
77
|
+
|
78
|
+
def orderable
|
79
|
+
@orderable
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
56
83
|
module HeaderRow # :nodoc:
|
57
84
|
def ordinal(attribute = :ordinal, **)
|
58
85
|
cell(attribute, class: "ordinal", label: "")
|
@@ -60,13 +87,17 @@ module Katalyst
|
|
60
87
|
end
|
61
88
|
|
62
89
|
module BodyRow # :nodoc:
|
63
|
-
def ordinal(attribute = :ordinal,
|
64
|
-
|
65
|
-
|
90
|
+
def ordinal(attribute = :ordinal, primary_key: :id)
|
91
|
+
id = @record.public_send(primary_key)
|
92
|
+
params = {
|
93
|
+
id_name: @table.orderable.record_scope(id, primary_key),
|
94
|
+
id_value: id,
|
95
|
+
index_name: @table.orderable.record_scope(id, attribute),
|
96
|
+
index_value: @record.public_send(attribute),
|
97
|
+
}
|
66
98
|
cell(attribute, class: "ordinal", data: {
|
67
|
-
controller:
|
68
|
-
"#{ITEM_CONTROLLER}-
|
69
|
-
"#{ITEM_CONTROLLER}-value-value" => value,
|
99
|
+
controller: ITEM_CONTROLLER,
|
100
|
+
"#{ITEM_CONTROLLER}-params-value": params.to_json,
|
70
101
|
}) { t("katalyst.tables.orderable.value") }
|
71
102
|
end
|
72
103
|
|
@@ -94,8 +125,8 @@ module Katalyst
|
|
94
125
|
@scope = scope
|
95
126
|
end
|
96
127
|
|
97
|
-
def record_scope(
|
98
|
-
"#{scope}[#{
|
128
|
+
def record_scope(id, attribute)
|
129
|
+
"#{scope}[#{id}][#{attribute}]"
|
99
130
|
end
|
100
131
|
|
101
132
|
def call
|
@@ -13,10 +13,16 @@ module Katalyst
|
|
13
13
|
|
14
14
|
include ::Turbo::StreamsHelper
|
15
15
|
|
16
|
+
# Is turbo rendering enabled for this component?
|
16
17
|
def turbo?
|
17
18
|
@turbo
|
18
19
|
end
|
19
20
|
|
21
|
+
# Are we rendering a turbo stream response?
|
22
|
+
def turbo_stream_response?
|
23
|
+
response.media_type.eql?("text/vnd.turbo-stream.html")
|
24
|
+
end
|
25
|
+
|
20
26
|
def initialize(turbo: true, **options)
|
21
27
|
super(**options)
|
22
28
|
|
@@ -44,16 +50,27 @@ module Katalyst
|
|
44
50
|
super
|
45
51
|
|
46
52
|
redefinition_lock.synchronize do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
# Capture the instance method added by the default compiler and
|
54
|
+
# wrap it in a turbo stream replacement. Take care to ensure that
|
55
|
+
# subclasses of this component don't break delegation, as each
|
56
|
+
# subclass of ViewComponent::Base defines its own version of this
|
57
|
+
# method.
|
58
|
+
vc_render_template = component_class.instance_method(:render_template_for)
|
59
|
+
component_class.define_method(:render_template_for) do |variant = nil|
|
60
|
+
# VC discards the output from this method and uses the buffer
|
61
|
+
# if both are set. Capture and wrap the output.
|
62
|
+
content = capture { vc_render_template.bind_call(self, variant) }
|
63
|
+
# In turbo mode, replace the inner-most element using a turbo
|
64
|
+
# stream. Note that we only want one turbo stream per component
|
65
|
+
# from this mechanism, as subclasses may want to concat their
|
66
|
+
# own additional streams.
|
67
|
+
if turbo? && turbo_stream_response? && !@streamed
|
68
|
+
@streamed = true
|
69
|
+
concat(turbo_stream.replace(id, content))
|
52
70
|
else
|
53
|
-
|
71
|
+
concat(content)
|
54
72
|
end
|
55
73
|
end
|
56
|
-
RUBY
|
57
74
|
end
|
58
75
|
end
|
59
76
|
end
|
@@ -7,6 +7,8 @@ module Katalyst
|
|
7
7
|
class TableComponent < ::Katalyst::TableComponent
|
8
8
|
include Tables::TurboReplaceable
|
9
9
|
|
10
|
+
attr_reader :id
|
11
|
+
|
10
12
|
def initialize(collection:, id:, header: true, **options)
|
11
13
|
header = if header.is_a?(Hash)
|
12
14
|
default_header_options.merge(header)
|
@@ -14,11 +16,9 @@ module Katalyst
|
|
14
16
|
default_header_options
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
|
-
end
|
19
|
+
@id = id
|
19
20
|
|
20
|
-
|
21
|
-
html_attributes[:id]
|
21
|
+
super(collection: collection, header: header, id: id, **options)
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
@@ -16,7 +16,7 @@ module Katalyst
|
|
16
16
|
included do
|
17
17
|
attr_accessor :items
|
18
18
|
|
19
|
-
delegate :model, :
|
19
|
+
delegate :model, :each, :count, :empty?, to: :items, allow_nil: true
|
20
20
|
delegate :model_name, to: :model, allow_nil: true
|
21
21
|
end
|
22
22
|
|