-
-
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 shipping categories
- Loading branch information
Showing
7 changed files
with
129 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/shipping_categories/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::ShippingCategory) do |layout| %> | ||
<% layout.with_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.add'), | ||
href: spree.new_admin_shipping_category_path, | ||
icon: "add-line", | ||
class: "align-self-end w-full", | ||
) %> | ||
<% end %> | ||
|
||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: Spree::ShippingCategory, | ||
rows: @page.records, | ||
url: ->(shipping_category) { spree.edit_admin_shipping_category_path(shipping_category) }, | ||
prev: prev_page_path, | ||
next: next_page_path, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
search: { | ||
name: :q, | ||
value: params[:q], | ||
url: solidus_admin.shipping_categories_path, | ||
searchbar_key: :name_or_description_cont, | ||
filters: filters, | ||
scopes: scopes, | ||
}, | ||
) %> | ||
<% end %> |
46 changes: 46 additions & 0 deletions
46
admin/app/components/solidus_admin/shipping_categories/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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::ShippingCategories::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(page:) | ||
@page = page | ||
end | ||
|
||
def title | ||
Spree::ShippingCategory.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.shipping_categories_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
|
||
def filters | ||
[] | ||
end | ||
|
||
def scopes | ||
[] | ||
end | ||
|
||
def columns | ||
[ | ||
:name | ||
] | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/shipping_categories/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,4 @@ | ||
en: | ||
add: 'Add new' | ||
batch_actions: | ||
delete: 'Delete' |
40 changes: 40 additions & 0 deletions
40
admin/app/controllers/solidus_admin/shipping_categories_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 ShippingCategoriesController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
def index | ||
shipping_categories = apply_search_to( | ||
Spree::ShippingCategory.order(id: :desc), | ||
param: :q, | ||
) | ||
|
||
set_page_and_extract_portion_from(shipping_categories) | ||
|
||
respond_to do |format| | ||
format.html { render component('shipping_categories/index').new(page: @page) } | ||
end | ||
end | ||
|
||
def destroy | ||
@shipping_category = Spree::ShippingCategory.find_by!(id: params[:id]) | ||
|
||
Spree::ShippingCategory.transaction { @shipping_category.destroy } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to shipping_categories_path, status: :see_other | ||
end | ||
|
||
private | ||
|
||
def load_shipping_category | ||
@shipping_category = Spree::ShippingCategory.find_by!(id: params[:id]) | ||
authorize! action_name, @shipping_category | ||
end | ||
|
||
def shipping_category_params | ||
params.require(:shipping_category).permit(:shipping_category_id, permitted_shipping_category_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,5 @@ | ||
en: | ||
shipping_categories: | ||
title: "Shipping Categories" | ||
destroy: | ||
success: "Shipping categories 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