Class: SolidusAdmin::Orders::Index::Component

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/solidus_admin/orders/index/component.rb

Instance Method Summary collapse

Constructor Details

#initialize(page:) ⇒ Component

Returns a new instance of Component.



4
5
6
# File 'app/components/solidus_admin/orders/index/component.rb', line 4

def initialize(page:)
  @page = page
end

Instance Method Details

#batch_actionsObject



22
23
24
# File 'app/components/solidus_admin/orders/index/component.rb', line 22

def batch_actions
  []
end

#columnsObject



36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/solidus_admin/orders/index/component.rb', line 36

def columns
  [
    number_column,
    date_column,
    customer_column,
    total_column,
    items_column,
    payment_column,
    shipment_column,
  ]
end

#customer_columnObject



72
73
74
75
76
77
78
79
80
81
# File 'app/components/solidus_admin/orders/index/component.rb', line 72

def customer_column
  {
    class_name: "w-[400px]",
    header: :customer,
    data: ->(order) do
      customer_email = order.user&.email
       :div, String(customer_email)
    end
  }
end

#date_columnObject



63
64
65
66
67
68
69
70
# File 'app/components/solidus_admin/orders/index/component.rb', line 63

def date_column
  {
    header: :date,
    data: ->(order) do
       :div, l(order.created_at, format: :short)
    end
  }
end

#filtersObject



26
27
28
29
30
31
32
33
34
# File 'app/components/solidus_admin/orders/index/component.rb', line 26

def filters
  [
    {
      name: 'q[completed_at_not_null]',
      value: 1,
      label: t('.filters.only_show_complete_orders'),
    },
  ]
end

#items_columnObject



92
93
94
95
96
97
98
99
# File 'app/components/solidus_admin/orders/index/component.rb', line 92

def items_column
  {
    header: :items,
    data: ->(order) do
       :div, t('.columns.items', count: order.line_items.sum(:quantity))
    end
  }
end


18
19
20
# File 'app/components/solidus_admin/orders/index/component.rb', line 18

def next_page_link
  @page.last? ? nil : solidus_admin.url_for(host: request.host, port: request.port, **request.params, page: @page.next_param)
end

#number_columnObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/components/solidus_admin/orders/index/component.rb', line 48

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'
      else
        link_to order.number, order_path
      end
    end
  }
end

#payment_columnObject



101
102
103
104
105
106
107
108
# File 'app/components/solidus_admin/orders/index/component.rb', line 101

def payment_column
  {
    header: :payment,
    data: ->(order) do
      component('ui/badge').new(name: order.payment_state&.humanize, color: order.paid? ? :green : :yellow)
    end
  }
end


14
15
16
# File 'app/components/solidus_admin/orders/index/component.rb', line 14

def prev_page_link
  @page.first? ? nil : solidus_admin.url_for(host: request.host, port: request.port, **request.params, page: @page.number - 1)
end

#shipment_columnObject



110
111
112
113
114
115
116
117
# File 'app/components/solidus_admin/orders/index/component.rb', line 110

def shipment_column
  {
    header: :shipment,
    data: ->(order) do
      component('ui/badge').new(name: order.shipment_state&.humanize, color: order.shipped? ? :green : :yellow)
    end
  }
end

#titleObject



10
11
12
# File 'app/components/solidus_admin/orders/index/component.rb', line 10

def title
  Spree::Order.model_name.human.pluralize
end

#total_columnObject



83
84
85
86
87
88
89
90
# File 'app/components/solidus_admin/orders/index/component.rb', line 83

def total_column
  {
    header: :total,
    data: ->(order) do
       :div, number_to_currency(order.total)
    end
  }
end