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

Inherits:
SolidusAdmin::UI::Pages::Index::Component
  • Object
show all
Defined in:
app/components/solidus_admin/users/index/component.rb

Instance Method Summary collapse

Instance Method Details

#batch_actionsObject



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

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

#columnsObject



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

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



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

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

#model_classObject



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

def model_class
  Spree.user_class
end

#page_actionsObject



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

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



16
17
18
# File 'app/components/solidus_admin/users/index/component.rb', line 16

def row_url(user)
  spree.admin_user_path(user)
end

#scopesObject



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

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

#search_keyObject



8
9
10
# File 'app/components/solidus_admin/users/index/component.rb', line 8

def search_key
  :email_cont
end

#search_urlObject



12
13
14
# File 'app/components/solidus_admin/users/index/component.rb', line 12

def search_url
  solidus_admin.users_path
end