-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an index page for stock locations
- Loading branch information
Showing
7 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
admin/app/components/solidus_admin/stock_locations/index/component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %> |
81 changes: 81 additions & 0 deletions
81
admin/app/components/solidus_admin/stock_locations/index/component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
6 changes: 6 additions & 0 deletions
6
admin/app/components/solidus_admin/stock_locations/index/component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
en: | ||
active: 'Active' | ||
inactive: 'Inactive' | ||
add: 'Add new' | ||
batch_actions: | ||
delete: 'Delete' |
40 changes: 40 additions & 0 deletions
40
admin/app/controllers/solidus_admin/stock_locations_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
en: | ||
solidus_admin: | ||
stock_locations: | ||
title: "Stock Locations" | ||
destroy: | ||
success: "Stock locations were successfully removed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters