app/components/solidus_admin/orders/index/component.rb in solidus_admin-0.0.2 vs app/components/solidus_admin/orders/index/component.rb in solidus_admin-0.1.0
- old
+ new
@@ -1,43 +1,94 @@
# frozen_string_literal: true
class SolidusAdmin::Orders::Index::Component < SolidusAdmin::BaseComponent
+ include SolidusAdmin::Layout::PageHelpers
+
def initialize(page:)
@page = page
end
- class_attribute :fade_row_proc, default: ->(order) { order.paid? && order.shipped? }
+ class_attribute :row_fade, default: ->(order) { order.paid? && order.shipped? }
def title
Spree::Order.model_name.human.pluralize
end
- def prev_page_link
- @page.first? ? nil : solidus_admin.url_for(host: request.host, port: request.port, **request.params, page: @page.number - 1)
+ def prev_page_path
+ solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first?
end
- def next_page_link
- @page.last? ? nil : solidus_admin.url_for(host: request.host, port: request.port, **request.params, page: @page.next_param)
+ 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
[
{
- name: 'q[completed_at_not_null]',
- value: 1,
- label: t('.filters.only_show_complete_orders'),
+ 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.promotions'),
+ combinator: 'or',
+ attribute: "promotions_id",
+ predicate: "in",
+ options: Spree::Promotion.all.pluck(:name, :id),
+ },
]
end
def columns
[
number_column,
+ state_column,
date_column,
customer_column,
total_column,
items_column,
payment_column,
@@ -47,21 +98,34 @@
def number_column
{
header: :order,
data: ->(order) do
- order_path = spree.edit_admin_order_path(order)
-
- if !fade_row_proc.call(order)
- link_to order.number, order_path, class: 'font-semibold'
+ if !row_fade.call(order)
+ content_tag :div, order.number, class: 'font-semibold'
else
- link_to order.number, order_path
+ 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)
@@ -69,11 +133,11 @@
}
end
def customer_column
{
- class_name: "w-[400px]",
+ col: { class: "w-[400px]" },
header: :customer,
data: ->(order) do
customer_email = order.user&.email
content_tag :div, String(customer_email)
end
@@ -100,19 +164,19 @@
def payment_column
{
header: :payment,
data: ->(order) do
- component('ui/badge').new(name: order.payment_state&.humanize, color: order.paid? ? :green : :yellow)
+ 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)
+ component('ui/badge').new(name: order.shipment_state.humanize, color: order.shipped? ? :green : :yellow) if order.shipment_state?
end
}
end
end