Class: SolidusAdmin::Users::Orders::Component

Inherits:
BaseComponent
  • Object
show all
Includes:
Layout::PageHelpers
Defined in:
app/components/solidus_admin/users/orders/component.rb

Instance Method Summary collapse

Constructor Details

#initialize(user:, orders:) ⇒ Component

Returns a new instance of Component.



6
7
8
9
# File 'app/components/solidus_admin/users/orders/component.rb', line 6

def initialize(user:, orders:)
  @user = user
  @orders = orders
end

Instance Method Details

#columnsObject



57
58
59
60
61
62
63
64
65
66
# File 'app/components/solidus_admin/users/orders/component.rb', line 57

def columns
  [
    number_column,
    state_column,
    date_column,
    payment_column,
    shipment_column,
    total_column,
  ]
end

#date_columnObject



96
97
98
99
100
101
102
103
# File 'app/components/solidus_admin/users/orders/component.rb', line 96

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

#model_classObject



41
42
43
# File 'app/components/solidus_admin/users/orders/component.rb', line 41

def model_class
  Spree::Order
end

#number_columnObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/components/solidus_admin/users/orders/component.rb', line 68

def number_column
  {
    header: :order,
    data: ->(order) do
      if !row_fade(order)
         :div, order.number, class: 'font-semibold'
      else
         :div, order.number
      end
    end
  }
end

#payment_columnObject



114
115
116
117
118
119
120
121
# File 'app/components/solidus_admin/users/orders/component.rb', line 114

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

#row_fade(_order) ⇒ Object



53
54
55
# File 'app/components/solidus_admin/users/orders/component.rb', line 53

def row_fade(_order)
  false
end

#row_url(order) ⇒ Object



45
46
47
# File 'app/components/solidus_admin/users/orders/component.rb', line 45

def row_url(order)
  spree.edit_admin_order_path(order)
end

#rowsObject



49
50
51
# File 'app/components/solidus_admin/users/orders/component.rb', line 49

def rows
  @orders
end

#shipment_columnObject



123
124
125
126
127
128
129
130
# File 'app/components/solidus_admin/users/orders/component.rb', line 123

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

#state_columnObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/components/solidus_admin/users/orders/component.rb', line 81

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

#tabsObject



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
# File 'app/components/solidus_admin/users/orders/component.rb', line 11

def tabs
  [
    {
      text: t('.account'),
      href: solidus_admin.user_path(@user),
      current: false,
    },
    {
      text: t('.addresses'),
      href: solidus_admin.addresses_user_path(@user),
      current: false,
    },
    {
      text: t('.order_history'),
      href: solidus_admin.orders_user_path(@user),
      current: true,
    },
    {
      text: t('.items'),
      href: spree.items_admin_user_path(@user),
      current: false,
    },
    {
      text: t('.store_credit'),
      href: spree.admin_user_store_credits_path(@user),
      current: false,
    },
  ]
end

#total_columnObject



105
106
107
108
109
110
111
112
# File 'app/components/solidus_admin/users/orders/component.rb', line 105

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