activeadmin_table_footer 1.0.1 → 1.0.2
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a9874aaf42089efb8297cda5f60411bad438d691a12098a19439f38d5986d308
|
|
4
|
+
data.tar.gz: fff210775c3c1e30d1ee09ae20d596ff7a684f0091f47209b9fbd95d9f3a0053
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef0407e70f5a3129e88db017a39bc252745fcaba6cc015783b445528b9f572bc694d957b28aef299f15214d09e0e84e0e76caee32c6f2d8b175dc28262637356
|
|
7
|
+
data.tar.gz: 89bf638f6ab6ff73023dd42de1ce8f62afc8305a11339e15347d00f626f0ccfea2896c5a562aa2eb243993c22780044d89963ab7907c870bb34615dabdf0b520
|
|
@@ -7,17 +7,20 @@ module ActiveadminTableFooter
|
|
|
7
7
|
module IndexAsTableExtension
|
|
8
8
|
def build(page_presenter, collection)
|
|
9
9
|
footer_proc = page_presenter[:footer_data]
|
|
10
|
+
return super unless footer_proc && page_presenter.block
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
instance_exec(table, &original_block)
|
|
16
|
-
end
|
|
17
|
-
page_presenter.instance_variable_set(:@block, wrapped)
|
|
12
|
+
original_block = page_presenter.block
|
|
13
|
+
wrapped = lambda do |table|
|
|
14
|
+
table.instance_variable_set(:@footer_data_proc, footer_proc)
|
|
15
|
+
instance_exec(table, &original_block)
|
|
18
16
|
end
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
# Render against a copy. ActiveAdmin builds one PagePresenter per
|
|
19
|
+
# `index do ... end` when it loads the resource and hands that same
|
|
20
|
+
# object to every render, so writing the wrapper back into the presenter
|
|
21
|
+
# would wrap the previous wrapper once per request — growing retained
|
|
22
|
+
# closures and block call depth until a render raises SystemStackError.
|
|
23
|
+
super(ActiveAdmin::PagePresenter.new(page_presenter.options, &wrapped), collection)
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
end
|
|
@@ -8,10 +8,12 @@ module ActiveadminTableFooter
|
|
|
8
8
|
super(obj, *attrs, options)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
+
# Any falsy callback means "no footer" — `&.` would only skip nil and raise
|
|
12
|
+
# on `footer_data: false`, which is what `footer_data: flag && ->(c) { ... }`
|
|
13
|
+
# passes when the flag is off.
|
|
11
14
|
def footer_data
|
|
12
15
|
return @footer_data if defined?(@footer_data)
|
|
13
|
-
|
|
14
|
-
@footer_data = @footer_data_proc.call(unscoped_collection_for_footer)
|
|
16
|
+
@footer_data = (@footer_data_proc.call(unscoped_collection_for_footer) if @footer_data_proc)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# The collection AA passes us is the paginated + ordered slice. Aggregates
|
|
@@ -49,14 +51,15 @@ module ActiveadminTableFooter
|
|
|
49
51
|
def build_footer_cell_for(col)
|
|
50
52
|
within @aatf_footer_row do
|
|
51
53
|
column_key = column_key_for(col)
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
# `col` + `col-<key>` keeps capybara_active_admin's
|
|
55
|
+
# `have_table_cell(column: ...)` matcher working on AA 3 and AA 4.
|
|
56
|
+
classes = [
|
|
57
|
+
col.html_class,
|
|
58
|
+
"col",
|
|
59
|
+
("col-#{column_key}" if column_key),
|
|
60
|
+
ActiveadminTableFooter.footer_th_class
|
|
61
|
+
].compact_blank.join(" ").presence
|
|
62
|
+
attrs = { class: classes }
|
|
60
63
|
attrs[:"data-column"] = column_key if column_key
|
|
61
64
|
td(**attrs) do
|
|
62
65
|
render_footer_value(col) if column_has_footer?(col)
|
|
@@ -66,12 +69,8 @@ module ActiveadminTableFooter
|
|
|
66
69
|
|
|
67
70
|
def column_key_for(col)
|
|
68
71
|
# AA 4 exposes Column#title_id; AA 3 does not — derive from title.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
end
|
|
72
|
-
title = col.title.to_s
|
|
73
|
-
return nil if title.empty?
|
|
74
|
-
title.parameterize(separator: "_")
|
|
72
|
+
return col.title_id.presence if col.respond_to?(:title_id)
|
|
73
|
+
col.title.to_s.presence&.parameterize(separator: "_")
|
|
75
74
|
end
|
|
76
75
|
|
|
77
76
|
def ensure_tfoot!
|