Class: SolidusAdmin::StockItems::Index::Component
- Inherits:
-
UI::Pages::Index::Component
- Object
- UI::Pages::Index::Component
- SolidusAdmin::StockItems::Index::Component
- Defined in:
- app/components/solidus_admin/stock_items/index/component.rb
Instance Method Summary collapse
- #back_orderable_column ⇒ Object
- #columns ⇒ Object
- #count_on_hand_column ⇒ Object
- #filters ⇒ Object
- #image_column ⇒ Object
- #model_class ⇒ Object
- #name_column ⇒ Object
- #row_url(stock_item) ⇒ Object
- #scopes ⇒ Object
- #search_key ⇒ Object
- #search_url ⇒ Object
- #sku_column ⇒ Object
- #stock_location_column ⇒ Object
-
#stock_movement_counts ⇒ Object
Cache the stock movement counts to avoid N+1 queries.
- #stock_movements_column ⇒ Object
- #turbo_frames ⇒ Object
- #variant_column ⇒ Object
Instance Method Details
#back_orderable_column ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 152 def back_orderable_column { header: :back_orderable, data: ->(stock_item) do stock_item.backorderable? ? component('ui/badge').yes : component('ui/badge').no end } end |
#columns ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 59 def columns [ image_column, name_column, sku_column, variant_column, stock_location_column, back_orderable_column, count_on_hand_column, stock_movements_column, ] end |
#count_on_hand_column ⇒ Object
161 162 163 164 165 166 167 168 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 161 def count_on_hand_column { header: :count_on_hand, data: ->(stock_item) do content_tag :div, stock_item.count_on_hand end } end |
#filters ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 30 def filters [ { label: t('.filters.stock_locations'), combinator: 'or', attribute: "stock_location_id", predicate: "eq", options: Spree::StockLocation.all.map do |stock_location| [ stock_location.name.titleize, stock_location.id ] end }, { label: t('.filters.variants'), combinator: 'or', attribute: "variant_id", predicate: "eq", options: Spree::Variant.all.map do |variant| [ variant.descriptive_name, variant.id ] end }, ] end |
#image_column ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 72 def image_column { col: { class: "w-[72px]" }, header: tag.span('aria-label': Spree::Image.model_name.human, role: 'text'), data: ->(stock_item) do image = stock_item.variant.gallery.images.first or return render( component('ui/thumbnail').new( src: image.url(:small), alt: stock_item.variant.name ) ) end } end |
#model_class ⇒ Object
4 5 6 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 4 def model_class Spree::StockItem end |
#name_column ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 89 def name_column { header: :name, data: ->(stock_item) do content_tag :div, stock_item.variant.name end } end |
#row_url(stock_item) ⇒ Object
16 17 18 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 16 def row_url(stock_item) solidus_admin.edit_stock_item_path(stock_item, _turbo_frame: :edit_stock_item_modal) end |
#scopes ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 20 def scopes [ { label: t('.scopes.all_stock_items'), name: 'all', default: true }, { label: t('.scopes.back_orderable'), name: 'back_orderable' }, { label: t('.scopes.out_of_stock'), name: 'out_of_stock' }, { label: t('.scopes.low_stock'), name: 'low_stock' }, { label: t('.scopes.in_stock'), name: 'in_stock' }, ] end |
#search_key ⇒ Object
8 9 10 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 8 def search_key :variant_product_name_or_variant_sku_or_variant_option_values_name_or_variant_option_values_presentation_cont end |
#search_url ⇒ Object
12 13 14 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 12 def search_url solidus_admin.stock_items_path end |
#sku_column ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 98 def sku_column { header: :sku, data: ->(stock_item) do content_tag :div, stock_item.variant.sku end } end |
#stock_location_column ⇒ Object
122 123 124 125 126 127 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 122 def stock_location_column { header: :stock_location, data: ->(stock_item) { stock_item.stock_location.name }, } end |
#stock_movement_counts ⇒ Object
Cache the stock movement counts to avoid N+1 queries
130 131 132 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 130 def stock_movement_counts @stock_movement_counts ||= Spree::StockMovement.where(stock_item_id: @page.records.ids).group(:stock_item_id).count end |
#stock_movements_column ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 134 def stock_movements_column { header: :stock_movements, data: -> do count = stock_movement_counts[_1.id] || 0 link_to( "#{count} #{Spree::StockMovement.model_name.human(count:).downcase}", spree.admin_stock_location_stock_movements_path( _1.stock_location.id, q: { variant_sku_eq: _1.variant.sku }, ), class: 'body-link' ) end } end |
#turbo_frames ⇒ Object
170 171 172 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 170 def turbo_frames %w[edit_stock_item_modal] end |
#variant_column ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/components/solidus_admin/stock_items/index/component.rb', line 107 def variant_column { header: :variant, data: ->(stock_item) do content_tag(:div, class: "space-y-0.5") do safe_join( stock_item.variant.option_values.sort_by(&:option_type_name).map do |option_value| render(component('ui/badge').new(name: "#{option_value.option_type_presentation}: #{option_value.presentation}")) end ) end end } end |