Class: SolidusAdmin::Orders::Index::Component
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- SolidusAdmin::Orders::Index::Component
- Includes:
- Layout::PageHelpers
- Defined in:
- app/components/solidus_admin/orders/index/component.rb
Instance Method Summary collapse
- #batch_actions ⇒ Object
- #columns ⇒ Object
- #customer_column ⇒ Object
- #date_column ⇒ Object
- #filters ⇒ Object
-
#initialize(page:) ⇒ Component
constructor
A new instance of Component.
- #items_column ⇒ Object
- #next_page_path ⇒ Object
- #number_column ⇒ Object
- #payment_column ⇒ Object
- #prev_page_path ⇒ Object
- #scopes ⇒ Object
- #shipment_column ⇒ Object
- #state_column ⇒ Object
- #title ⇒ Object
- #total_column ⇒ Object
Constructor Details
#initialize(page:) ⇒ Component
Returns a new instance of Component.
6 7 8 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 6 def initialize(page:) @page = page end |
Instance Method Details
#batch_actions ⇒ Object
24 25 26 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 24 def batch_actions [] end |
#columns ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 86 def columns [ number_column, state_column, date_column, customer_column, total_column, items_column, payment_column, shipment_column, ] end |
#customer_column ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 136 def customer_column { col: { class: "w-[400px]" }, header: :customer, data: ->(order) do customer_email = order.user&.email content_tag :div, String(customer_email) end } end |
#date_column ⇒ Object
127 128 129 130 131 132 133 134 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 127 def date_column { header: :date, data: ->(order) do content_tag :div, l(order.created_at, format: :short) end } end |
#filters ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 38 def filters [ { presentation: t('.filters.status'), combinator: 'or', attribute: "state", predicate: "eq", options: Spree::Order.state_machines[:state].states.map do |state| [ state.value.titleize, state.value ] end }, { presentation: t('.filters.shipment_state'), combinator: 'or', attribute: "shipment_state", predicate: "eq", options: i[backorder canceled partial pending ready shipped].map do |option| [ option.to_s.capitalize, option ] end }, { presentation: t('.filters.payment_state'), combinator: 'or', attribute: "payment_state", predicate: "eq", options: i[balance_due checkout completed credit_owed invalid paid pending processing void].map do |option| [ option.to_s.titleize, option ] end }, { presentation: t('.filters.promotions'), combinator: 'or', attribute: "promotions_id", predicate: "in", options: Spree::Promotion.all.pluck(:name, :id), }, ] end |
#items_column ⇒ Object
156 157 158 159 160 161 162 163 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 156 def items_column { header: :items, data: ->(order) do content_tag :div, t('.columns.items', count: order.line_items.sum(:quantity)) end } end |
#next_page_path ⇒ Object
20 21 22 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 20 def next_page_path solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? end |
#number_column ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 99 def number_column { header: :order, data: ->(order) do if !row_fade.call(order) content_tag :div, order.number, class: 'font-semibold' else content_tag :div, order.number end end } end |
#payment_column ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 165 def payment_column { header: :payment, data: ->(order) do component('ui/badge').new(name: order.payment_state.humanize, color: order.paid? ? :green : :yellow) if order.payment_state? end } end |
#prev_page_path ⇒ Object
16 17 18 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 16 def prev_page_path solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? end |
#scopes ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 28 def scopes [ { label: t('.scopes.complete'), name: 'completed', default: true }, { label: t('.scopes.in_progress'), name: 'in_progress' }, { label: t('.scopes.returned'), name: 'returned' }, { label: t('.scopes.canceled'), name: 'canceled' }, { label: t('.scopes.all_orders'), name: 'all' }, ] end |
#shipment_column ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 174 def shipment_column { header: :shipment, data: ->(order) do component('ui/badge').new(name: order.shipment_state.humanize, color: order.shipped? ? :green : :yellow) if order.shipment_state? end } end |
#state_column ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 112 def state_column { header: :state, data: ->(order) do color = { 'complete' => :green, 'returned' => :red, 'canceled' => :blue, 'cart' => :graphite_light, }[order.state] || :yellow component('ui/badge').new(name: order.state.humanize, color: color) end } end |
#title ⇒ Object
12 13 14 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 12 def title Spree::Order.model_name.human.pluralize end |
#total_column ⇒ Object
147 148 149 150 151 152 153 154 |
# File 'app/components/solidus_admin/orders/index/component.rb', line 147 def total_column { header: :total, data: ->(order) do content_tag :div, number_to_currency(order.total) end } end |