Sha256: b6f9b4a44424f4944f828ebf334ea05ab76c9a478b503b75330573f2c9042aa3

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

class SolidusAdmin::StockLocations::Index::Component < SolidusAdmin::Shipping::Component
  def model_class
    Spree::StockLocation
  end

  def actions
    render component("ui/button").new(
      tag: :a,
      text: t('.add'),
      href: spree.new_admin_stock_location_path,
      icon: "add-line",
      class: "align-self-end w-full",
    )
  end

  def row_url(stock_location)
    spree.edit_admin_stock_location_path(stock_location)
  end

  def search_url
    solidus_admin.stock_locations_path
  end

  def search_key
    :name_or_description_cont
  end

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

  def scopes
    []
  end

  def filters
    []
  end

  def columns
    [
      :name,
      :code,
      :admin_name,
      {
        header: :state,
        data: -> {
          color = _1.active? ? :green : :graphite_light
          text = _1.active? ? t('.active') : t('.inactive')

          component('ui/badge').new(name: text, color: color)
        },
      },
      {
        header: :backorderable,
        data: -> {
          _1.backorderable_default ? component('ui/badge').yes : component('ui/badge').no
        }
      },
      {
        header: :default,
        data: -> {
          _1.default ? component('ui/badge').yes : component('ui/badge').no
        }
      },
      {
        header: :stock_movements,
        data: -> {
          count = _1.stock_movements.count

          link_to(
            "#{count} #{Spree::StockMovement.model_name.human(count: count).downcase}",
            spree.admin_stock_location_stock_movements_path(_1),
            class: 'body-link'
          )
        }
      }
    ]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_admin-0.3.1 app/components/solidus_admin/stock_locations/index/component.rb
solidus_admin-0.3.0 app/components/solidus_admin/stock_locations/index/component.rb