forked from thoughtbot/administrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder_dashboard.rb
More file actions
73 lines (69 loc) · 1.71 KB
/
order_dashboard.rb
File metadata and controls
73 lines (69 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require "administrate/base_dashboard"
class OrderDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
id: Field::Number.with_options(searchable: true),
created_at: Field::DateTime,
updated_at: Field::DateTime,
address_line_one: Field::String,
address_line_two: Field::String,
address_city: Field::String,
address_state: Field::String,
address_zip: Field::String,
full_address: Field::String.with_options(
getter: ->(field) {
r = field.resource
[
r.address_line_one,
r.address_line_two,
r.address_city,
r.address_state,
r.address_zip
].compact.join("\n")
},
searchable: false
),
customer: Field::BelongsTo.with_options(order: "name"),
line_items: Field::HasMany.with_options(
collection_attributes: %i[product quantity unit_price total_price]
),
total_price: Field::Number.with_options(prefix: "$", decimals: 2),
shipped_at: Field::DateTime,
payments: Field::HasMany
}
READ_ONLY_ATTRIBUTES = [
:id,
:total_price,
:created_at,
:updated_at
]
COLLECTION_ATTRIBUTES = [
:id,
:customer,
:full_address,
:total_price,
:line_items,
:shipped_at
]
FORM_ATTRIBUTES = {
"" => %i[customer],
"details" => %i[
line_items
shipped_at
payments
],
"address" => %i[
address_line_one
address_line_two
address_city
address_state
address_zip
]
}.freeze
SHOW_PAGE_ATTRIBUTES = FORM_ATTRIBUTES
.except("address")
.merge(
"" => %i[customer full_address created_at updated_at],
"details" => %i[line_items total_price shipped_at payments]
)
.freeze
end