Class: SolidusAdmin::Users::Items::Component

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

Instance Method Summary collapse

Constructor Details

#initialize(user:, items:) ⇒ Component

Returns a new instance of Component.



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

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

Instance Method Details

#columnsObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/components/solidus_admin/users/items/component.rb', line 53

def columns
  [
    date_column,
    image_column,
    description_column,
    price_column,
    quantity_column,
    total_column,
    state_column,
    number_column,
  ]
end

#date_columnObject



66
67
68
69
70
71
72
73
74
# File 'app/components/solidus_admin/users/items/component.rb', line 66

def date_column
  {
    col: { class: "w-[8%]" },
    header: :date,
    data: ->(item) do
       :div, l(item.order.created_at, format: :short), class: "text-sm"
    end
  }
end

#description_columnObject



93
94
95
96
97
98
99
# File 'app/components/solidus_admin/users/items/component.rb', line 93

def description_column
  {
    col: { class: "w-[24%]" },
    header: t(".description_column_header"),
    data: ->(item) { item_name_with_variant_and_sku(item) }
  }
end

#image_columnObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/components/solidus_admin/users/items/component.rb', line 76

def image_column
  {
    col: { class: "w-[8%]" },
    header: tag.span('aria-label': Spree::Image.model_name.human, role: 'text'),
    data: ->(item) do
      image = item.variant.gallery.images.first || item.variant.product.gallery.images.first or return

      render(
        component('ui/thumbnail').new(
          src: image.url(:small),
          alt: item.product.name
        )
      )
    end
  }
end

#model_classObject



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

def model_class
  Spree::LineItem
end

#number_columnObject



147
148
149
150
151
152
153
154
155
# File 'app/components/solidus_admin/users/items/component.rb', line 147

def number_column
  {
    col: { class: "w-[18%]" },
    header: t(".number_column_header"),
    data: ->(item) do
       :div, item.order.number, class: "font-semibold text-sm"
    end
  }
end

#price_columnObject



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

def price_column
  {
    col: { class: "w-[10%]" },
    header: :price,
    data: ->(item) do
       :div, item.single_money.to_html
    end
  }
end

#quantity_columnObject



111
112
113
114
115
116
117
118
119
# File 'app/components/solidus_admin/users/items/component.rb', line 111

def quantity_column
  {
    col: { class: "w-[7%]" },
    header: :qty,
    data: ->(item) do
       :div, item.quantity
    end
  }
end

#row_url(order) ⇒ Object



45
46
47
# File 'app/components/solidus_admin/users/items/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/items/component.rb', line 49

def rows
  @items
end

#state_columnObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/components/solidus_admin/users/items/component.rb', line 131

def state_column
  {
    col: { class: "w-[15%]" },
    header: :state,
    data: ->(item) do
      color = {
        'complete' => :green,
        'returned' => :red,
        'canceled' => :blue,
        'cart' => :graphite_light,
      }[item.order.state] || :yellow
      component('ui/badge').new(name: item.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/items/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: false,
    },
    {
      text: t('.items'),
      href: solidus_admin.items_user_path(@user),
      current: true,
    },
    {
      text: t('.store_credit'),
      href: spree.admin_user_store_credits_path(@user),
      current: false,
    },
  ]
end

#total_columnObject



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

def total_column
  {
    col: { class: "w-[10%]" },
    header: t(".total_column_header"),
    data: ->(item) do
       :div, item.money.to_html
    end
  }
end