-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
component.rb
197 lines (180 loc) 路 4.48 KB
/
component.rb
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# frozen_string_literal: true
class SolidusAdmin::Orders::Index::Component < SolidusAdmin::BaseComponent
def initialize(page:)
@page = page
end
class_attribute :row_fade, default: ->(order) { order.paid? && order.shipped? }
def title
Spree::Order.model_name.human.pluralize
end
def prev_page_path
solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first?
end
def next_page_path
solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last?
end
def batch_actions
[]
end
def scopes
[
{ label: t('.scopes.complete'), name: 'completed', default: true },
{ label: t('.scopes.in_progress'), name: 'in_progress' },
{ label: t('.scopes.returned'), name: 'returned' },
{ label: t('.scopes.canceled'), name: 'canceled' },
{ label: t('.scopes.all_orders'), name: 'all' },
]
end
def filters
[
{
presentation: t('.filters.status'),
combinator: 'or',
attribute: "state",
predicate: "eq",
options: Spree::Order.state_machines[:state].states.map do |state|
[
state.value.titleize,
state.value
]
end
},
{
presentation: t('.filters.shipment_state'),
combinator: 'or',
attribute: "shipment_state",
predicate: "eq",
options: %i[backorder canceled partial pending ready shipped].map do |option|
[
option.to_s.capitalize,
option
]
end
},
{
presentation: t('.filters.payment_state'),
combinator: 'or',
attribute: "payment_state",
predicate: "eq",
options: %i[balance_due checkout completed credit_owed invalid paid pending processing void].map do |option|
[
option.to_s.titleize,
option
]
end
},
{
presentation: t('.filters.variants'),
combinator: 'or',
attribute: "line_items_variant_id",
predicate: "in",
options: Spree::Variant.all.map do |variant|
[
variant.descriptive_name,
variant.id
]
end
},
{
presentation: t('.filters.promotions'),
combinator: 'or',
attribute: "promotions_id",
predicate: "in",
options: Spree::Promotion.all.map do |promotion|
[
promotion.name,
promotion.id
]
end
},
]
end
def columns
[
number_column,
state_column,
date_column,
customer_column,
total_column,
items_column,
payment_column,
shipment_column,
]
end
def number_column
{
header: :order,
data: ->(order) do
if !row_fade.call(order)
content_tag :div, order.number, class: 'font-semibold'
else
content_tag :div, order.number
end
end
}
end
def state_column
{
header: :state,
data: ->(order) do
color = {
'complete' => :green,
'returned' => :red,
'canceled' => :blue,
'cart' => :graphite_light,
}[order.state] || :yellow
component('ui/badge').new(name: order.state.humanize, color: color)
end
}
end
def date_column
{
header: :date,
data: ->(order) do
content_tag :div, l(order.created_at, format: :short)
end
}
end
def customer_column
{
col: { class: "w-[400px]" },
header: :customer,
data: ->(order) do
customer_email = order.user&.email
content_tag :div, String(customer_email)
end
}
end
def total_column
{
header: :total,
data: ->(order) do
content_tag :div, number_to_currency(order.total)
end
}
end
def items_column
{
header: :items,
data: ->(order) do
content_tag :div, t('.columns.items', count: order.line_items.sum(:quantity))
end
}
end
def payment_column
{
header: :payment,
data: ->(order) do
component('ui/badge').new(name: order.payment_state.humanize, color: order.paid? ? :green : :yellow) if order.payment_state?
end
}
end
def shipment_column
{
header: :shipment,
data: ->(order) do
component('ui/badge').new(name: order.shipment_state.humanize, color: order.shipped? ? :green : :yellow) if order.shipment_state?
end
}
end
end