diff --git a/admin/app/components/solidus_admin/shipping/component.rb b/admin/app/components/solidus_admin/shipping/component.rb index 7aa0223145e..a9a68ed13e7 100644 --- a/admin/app/components/solidus_admin/shipping/component.rb +++ b/admin/app/components/solidus_admin/shipping/component.rb @@ -12,6 +12,7 @@ def tabs { Spree::ShippingMethod => solidus_admin.shipping_methods_path, Spree::ShippingCategory => solidus_admin.shipping_categories_path, + Spree::StockLocation => solidus_admin.stock_locations_path, } end end diff --git a/admin/app/components/solidus_admin/stock_locations/index/component.html.erb b/admin/app/components/solidus_admin/stock_locations/index/component.html.erb new file mode 100644 index 00000000000..b127f86ba5c --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/index/component.html.erb @@ -0,0 +1,32 @@ +<%= render component('shipping').new(current_class: Spree::StockLocation) do |layout| %> + <% layout.with_actions do %> + <%= 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 %> + + <%= render component('ui/table').new( + id: stimulus_id, + data: { + class: Spree::StockLocation, + rows: @page.records, + url: ->(stock_location) { spree.edit_admin_stock_location_path(stock_location) }, + prev: prev_page_path, + next: next_page_path, + columns: columns, + batch_actions: batch_actions, + }, + search: { + name: :q, + value: params[:q], + url: solidus_admin.stock_locations_path, + searchbar_key: :name_or_description_cont, + filters: filters, + scopes: scopes, + }, + ) %> +<% end %> diff --git a/admin/app/components/solidus_admin/stock_locations/index/component.rb b/admin/app/components/solidus_admin/stock_locations/index/component.rb new file mode 100644 index 00000000000..4ea95405227 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/index/component.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +class SolidusAdmin::StockLocations::Index::Component < SolidusAdmin::BaseComponent + include SolidusAdmin::Layout::PageHelpers + + def initialize(page:) + @page = page + end + + def title + Spree::StockLocation.model_name.human.pluralize + end + + def prev_page_path + solidus_admin.url_for(**request.params, page: @page.number - 1, only_path: true) unless @page.first? + end + + def next_page_path + solidus_admin.url_for(**request.params, page: @page.next_param, only_path: true) unless @page.last? + end + + def batch_actions + [ + { + display_name: t('.batch_actions.delete'), + action: solidus_admin.stock_locations_path, + method: :delete, + icon: 'delete-bin-7-line', + }, + ] + end + + def filters + [] + end + + def scopes + [] + 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 diff --git a/admin/app/components/solidus_admin/stock_locations/index/component.yml b/admin/app/components/solidus_admin/stock_locations/index/component.yml new file mode 100644 index 00000000000..72183961309 --- /dev/null +++ b/admin/app/components/solidus_admin/stock_locations/index/component.yml @@ -0,0 +1,6 @@ +en: + active: 'Active' + inactive: 'Inactive' + add: 'Add new' + batch_actions: + delete: 'Delete' diff --git a/admin/app/controllers/solidus_admin/stock_locations_controller.rb b/admin/app/controllers/solidus_admin/stock_locations_controller.rb new file mode 100644 index 00000000000..364bfb12fc3 --- /dev/null +++ b/admin/app/controllers/solidus_admin/stock_locations_controller.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +module SolidusAdmin + class StockLocationsController < SolidusAdmin::BaseController + include SolidusAdmin::ControllerHelpers::Search + + def index + stock_locations = apply_search_to( + Spree::StockLocation.order(id: :desc), + param: :q, + ) + + set_page_and_extract_portion_from(stock_locations) + + respond_to do |format| + format.html { render component('stock_locations/index').new(page: @page) } + end + end + + def destroy + @stock_locations = Spree::StockLocation.where(id: params[:id]) + + Spree::StockLocation.transaction { @stock_locations.destroy_all } + + flash[:notice] = t('.success') + redirect_back_or_to stock_locations_path, status: :see_other + end + + private + + def load_stock_location + @stock_location = Spree::StockLocation.find_by!(number: params[:id]) + authorize! action_name, @stock_location + end + + def stock_location_params + params.require(:stock_location).permit(:stock_location_id, permitted_stock_location_attributes) + end + end +end diff --git a/admin/config/locales/stock_locations.en.yml b/admin/config/locales/stock_locations.en.yml new file mode 100644 index 00000000000..5c365e48372 --- /dev/null +++ b/admin/config/locales/stock_locations.en.yml @@ -0,0 +1,6 @@ +en: + solidus_admin: + stock_locations: + title: "Stock Locations" + destroy: + success: "Stock locations were successfully removed." diff --git a/admin/config/routes.rb b/admin/config/routes.rb index 114285e094c..3bc0f3eda41 100644 --- a/admin/config/routes.rb +++ b/admin/config/routes.rb @@ -42,4 +42,5 @@ admin_resources :payment_methods, only: [:index, :destroy], sortable: true admin_resources :shipping_methods, only: [:index, :destroy] admin_resources :shipping_categories, only: [:index, :destroy] + admin_resources :stock_locations, only: [:index, :destroy] end