terrazzo 0.5.4 → 0.6.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/app/controllers/terrazzo/application_controller.rb +1 -1
- data/app/helpers/terrazzo/collection_actions_helper.rb +2 -1
- data/app/views/terrazzo/application/_show_base.json.props +9 -5
- data/lib/generators/terrazzo/views/templates/pages/show.jsx +20 -16
- data/lib/terrazzo/base_dashboard.rb +4 -0
- data/lib/terrazzo/has_many_pagination.rb +5 -10
- data/lib/terrazzo/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: 6030a4b97c39b154729b26996275571d8a6ffba864d84a0bff348257c308ce16
|
|
4
|
+
data.tar.gz: 82edfaa39bd26353f4c56a2e96b22739620033d527d3c3fb57f6fcde45ec4b7c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cdc8552e4cf480b5dee699776ef5d1337eb7e1d92d387328d379b634165bf941774f4263ef0f0f8159ba8ae5fccb7d827b00425fed500b173f03325efddd908f
|
|
7
|
+
data.tar.gz: c7ff22f7872258e527a0558ef9a54df140a481aa76f8fc906250b16fd7b1210dc7f1a8293a6677398888461e26dd5b82ad967c6463eefd44df3e3d312591c9e6
|
|
@@ -46,7 +46,7 @@ module Terrazzo
|
|
|
46
46
|
@resource = find_resource(params[:id])
|
|
47
47
|
@page = Terrazzo::Page::Show.new(
|
|
48
48
|
dashboard, @resource,
|
|
49
|
-
has_many_params: Terrazzo::HasManyPagination.extract(params)
|
|
49
|
+
has_many_params: Terrazzo::HasManyPagination.extract(params, dashboard.has_many_attributes)
|
|
50
50
|
)
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -16,7 +16,8 @@ module Terrazzo
|
|
|
16
16
|
controller: controller_path,
|
|
17
17
|
action: :show,
|
|
18
18
|
id: resource.to_param,
|
|
19
|
-
format: nil
|
|
19
|
+
format: nil,
|
|
20
|
+
props_at: "data.attributes.#{field.attribute}"
|
|
20
21
|
)
|
|
21
22
|
{
|
|
22
23
|
prevPagePath: (field.current_page > 1 ? url_for(base.merge(param_key => field.current_page - 1)) : nil),
|
|
@@ -25,13 +25,17 @@ show_field_json = ->(json, field) do
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
json.attributes do
|
|
28
|
+
@page.grouped_attributes.flat_map { |g| g[:fields] }.each do |field|
|
|
29
|
+
json.set!(field.attribute.to_s) do
|
|
30
|
+
show_field_json.call(json, field)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
json.attributeGroups do
|
|
28
36
|
json.array! @page.grouped_attributes do |group|
|
|
29
37
|
json.name group[:name]
|
|
30
|
-
json.
|
|
31
|
-
json.array! group[:fields] do |field|
|
|
32
|
-
show_field_json.call(json, field)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
38
|
+
json.attributeKeys group[:fields].map { |f| f.attribute.to_s }
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
41
|
|
|
@@ -10,6 +10,7 @@ export default function AdminShow() {
|
|
|
10
10
|
const {
|
|
11
11
|
pageTitle,
|
|
12
12
|
attributes,
|
|
13
|
+
attributeGroups,
|
|
13
14
|
editPath,
|
|
14
15
|
deletePath,
|
|
15
16
|
indexPath,
|
|
@@ -54,7 +55,7 @@ export default function AdminShow() {
|
|
|
54
55
|
</div>
|
|
55
56
|
}>
|
|
56
57
|
|
|
57
|
-
{
|
|
58
|
+
{attributeGroups.map((group, groupIndex) =>
|
|
58
59
|
<Card key={groupIndex}>
|
|
59
60
|
{group.name && (
|
|
60
61
|
<CardHeader>
|
|
@@ -63,22 +64,25 @@ export default function AdminShow() {
|
|
|
63
64
|
)}
|
|
64
65
|
<CardContent className={group.name ? "" : "pt-6"}>
|
|
65
66
|
<dl className="divide-y">
|
|
66
|
-
{group.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
{group.attributeKeys.map((key) => {
|
|
68
|
+
const attr = attributes[key];
|
|
69
|
+
return (
|
|
70
|
+
<div key={key} className="py-4 grid grid-cols-3 gap-4">
|
|
71
|
+
<dt className="text-sm font-medium text-muted-foreground">
|
|
72
|
+
{attr.label}
|
|
73
|
+
</dt>
|
|
74
|
+
<dd className="col-span-2 text-sm">
|
|
75
|
+
{attr.showPath ? (
|
|
76
|
+
<a href={attr.showPath} data-sg-visit className="hover:underline">
|
|
77
|
+
<FieldRenderer mode="show" {...attr} />
|
|
78
|
+
</a>
|
|
79
|
+
) : (
|
|
74
80
|
<FieldRenderer mode="show" {...attr} />
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
</div>
|
|
81
|
-
)}
|
|
81
|
+
)}
|
|
82
|
+
</dd>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
})}
|
|
82
86
|
</dl>
|
|
83
87
|
</CardContent>
|
|
84
88
|
</Card>
|
|
@@ -58,6 +58,10 @@ module Terrazzo
|
|
|
58
58
|
attribute_types.select { |_attr, type| type.searchable? }.keys
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
def has_many_attributes
|
|
62
|
+
attribute_types.select { |_attr, type| type.field_type == "has_many" }.keys
|
|
63
|
+
end
|
|
64
|
+
|
|
61
65
|
def display_resource(resource)
|
|
62
66
|
"#{resource.class.name} ##{resource.id}"
|
|
63
67
|
end
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
module Terrazzo
|
|
2
2
|
module HasManyPagination
|
|
3
|
-
PARAM_PREFIX = "hm_".freeze
|
|
4
3
|
PARAM_SUFFIX = "_page".freeze
|
|
5
4
|
|
|
6
5
|
module_function
|
|
7
6
|
|
|
8
|
-
def extract(params)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
next unless key_s.start_with?(PARAM_PREFIX) && key_s.end_with?(PARAM_SUFFIX)
|
|
13
|
-
attr = key_s[PARAM_PREFIX.length...-PARAM_SUFFIX.length]
|
|
14
|
-
next if attr.empty?
|
|
7
|
+
def extract(params, attributes)
|
|
8
|
+
attributes.each_with_object({}) do |attr, result|
|
|
9
|
+
value = params[param_key(attr)] || params[param_key(attr).to_sym]
|
|
10
|
+
next if value.nil?
|
|
15
11
|
result[attr.to_sym] = { _page: value.to_i }
|
|
16
12
|
end
|
|
17
|
-
result
|
|
18
13
|
end
|
|
19
14
|
|
|
20
15
|
def param_key(attribute)
|
|
21
|
-
"#{
|
|
16
|
+
"#{attribute}#{PARAM_SUFFIX}"
|
|
22
17
|
end
|
|
23
18
|
end
|
|
24
19
|
end
|
data/lib/terrazzo/version.rb
CHANGED