Class: SolidusAdmin::Users::Index::Component

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

Instance Method Summary collapse

Constructor Details

#initialize(page:) ⇒ Component

Returns a new instance of Component.



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

def initialize(page:)
  @page = page
end

Instance Method Details

#batch_actionsObject



22
23
24
25
26
27
28
29
30
31
# File 'app/components/solidus_admin/users/index/component.rb', line 22

def batch_actions
  [
    {
      display_name: t('.batch_actions.delete'),
      action: solidus_admin.users_path,
      method: :delete,
      icon: 'delete-bin-7-line',
    },
  ]
end

#columnsObject



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

def columns
  [
    {
      header: :email,
      data: :email,
    },
    {
      header: :roles,
      data: ->(user) do
        roles = user.spree_roles.presence || [Spree::Role.new(name: 'customer')]
        safe_join(roles.map {
          color =
            case _1.name
            when 'admin' then :blue
            when 'customer' then :green
            else :graphite_light
            end
          render component('ui/badge').new(name: _1.name, color: color)
        })
      end,
    },
    {
      header: :order_count,
      data: ->(user) { user.order_count },
    },
    {
      header: :lifetime_value,
      data: -> { _1.display_lifetime_value.to_html },
    },
    {
      header: :created_at,
      data: ->(user) { l(user.created_at.to_date, format: :long) },
    },
  ]
end

#filtersObject



43
44
45
46
47
48
49
50
51
52
# File 'app/components/solidus_admin/users/index/component.rb', line 43

def filters
  [
    {
      presentation: Spree::Role.model_name.human.pluralize,
      attribute: "spree_roles_id",
      predicate: "in",
      options: Spree::Role.pluck(:name, :id)
    }
  ]
end

#next_page_pathObject



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

def next_page_path
  solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last?
end

#prev_page_pathObject



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

def prev_page_path
  solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first?
end

#scopesObject



33
34
35
36
37
38
39
40
41
# File 'app/components/solidus_admin/users/index/component.rb', line 33

def scopes
  [
    { name: :customers, label: t('.scopes.customers'), default: true },
    { name: :admin, label: t('.scopes.admin') },
    { name: :with_orders, label: t('.scopes.with_orders') },
    { name: :without_orders, label: t('.scopes.without_orders') },
    { name: :all, label: t('.scopes.all') },
  ]
end

#titleObject



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

def title
  Spree.user_class.model_name.human.pluralize
end