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

Inherits:
SolidusAdmin::UsersAndRoles::Component
  • Object
show all
Includes:
LastLoginHelper
Defined in:
app/components/solidus_admin/users/index/component.rb

Instance Method Summary collapse

Methods included from LastLoginHelper

#last_login

Instance Method Details

#batch_actionsObject



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

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

#columnsObject



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
89
90
91
92
93
94
95
96
97
# File 'app/components/solidus_admin/users/index/component.rb', line 63

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:)
        })
      end,
    },
    {
      header: :order_count,
      data: ->(user) { user.order_count },
    },
    {
      header: :lifetime_value,
      data: -> { _1.display_lifetime_value.to_html },
    },
    {
      header: :last_active,
      data: ->(user) { (user) },
    },
  ]
end

#filtersObject



52
53
54
55
56
57
58
59
60
61
# File 'app/components/solidus_admin/users/index/component.rb', line 52

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

#model_classObject



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

def model_class
  Spree.user_class
end

#page_actionsObject



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

def page_actions
  render component("ui/button").new(
    tag: :a,
    text: t('.add'),
    href: spree.new_admin_user_path,
    icon: "add-line",
  )
end

#row_url(user) ⇒ Object



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

def row_url(user)
  solidus_admin.edit_user_path(user)
end

#scopesObject



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

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

#search_keyObject



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

def search_key
  :email_cont
end

#search_urlObject



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

def search_url
  solidus_admin.users_path
end