Class: SolidusAdmin::Promotions::Index::Component

Inherits:
UI::Pages::Index::Component
  • Object
show all
Defined in:
app/components/solidus_admin/promotions/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/promotions/index/component.rb', line 29

def batch_actions
  [
    {
      display_name: t('.batch_actions.delete'),
      action: solidus_admin.promotions_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
96
97
98
99
100
101
102
103
# File 'app/components/solidus_admin/promotions/index/component.rb', line 61

def columns
  [
    {
      header: :name,
      data: ->(promotion) do
         :div, promotion.name
      end
    },
    {
      header: :code,
      data: ->(promotion) do
        count = promotion.codes.count
        (count == 1) ? promotion.codes.pick(:value) : t('spree.number_of_codes', count: count)
      end
    },
    {
      header: :status,
      data: ->(promotion) do
        if promotion.active?
          render component('ui/badge').new(name: t('.status.active'), color: :green)
        else
          render component('ui/badge').new(name: t('.status.inactive'), color: :graphite_light)
        end
      end
    },
    {
      header: :usage_limit,
      data: ->(promotion) { promotion.usage_limit || icon_tag('infinity-line') }
    },
    {
      header: :uses,
      data: ->(promotion) { promotion.usage_count }
    },
    {
      header: :starts_at,
      data: ->(promotion) { promotion.starts_at ? l(promotion.starts_at, format: :long) : icon_tag('infinity-line') }
    },
    {
      header: :expires_at,
      data: ->(promotion) { promotion.expires_at ? l(promotion.expires_at, format: :long) : icon_tag('infinity-line') }
    },
  ]
end

#filtersObject



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

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

#model_classObject



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

def model_class
  Spree::Promotion
end

#page_actionsObject



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

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

#row_url(promotion) ⇒ Object



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

def row_url(promotion)
  spree.admin_promotion_path(promotion)
end

#scopesObject



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

def scopes
  [
    { name: :active, label: t('.scopes.active'), default: true },
    { name: :draft, label: t('.scopes.draft') },
    { name: :future, label: t('.scopes.future') },
    { name: :expired, label: t('.scopes.expired') },
    { name: :all, label: t('.scopes.all') },
  ]
end

#search_keyObject



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

def search_key
  :name_or_codes_value_or_path_or_description_cont
end

#search_urlObject



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

def search_url
  solidus_admin.promotions_path
end