-
-
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
promotion_categories/index
component with dedicated controller …
…actions
- Loading branch information
1 parent
0bbb702
commit ca1302d
Showing
7 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
admin/app/components/solidus_admin/promotion_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,24 @@ | ||
<%= page do %> | ||
<%= page_header do %> | ||
<%= page_header_title title %> | ||
<%= page_header_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.create_promotion_category'), | ||
href: spree.new_admin_promotion_category_path, | ||
icon: "add-line", | ||
) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= render component('ui/table').new( | ||
id: 'promotion-categories-list', | ||
data: { | ||
class: Spree::PromotionCategory, | ||
rows: @promotion_categories, | ||
url: ->(promotion_category) { spree.edit_admin_promotion_category_path(promotion_category) }, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
) %> | ||
<% end %> |
49 changes: 49 additions & 0 deletions
49
admin/app/components/solidus_admin/promotion_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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::PromotionCategories::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(promotion_categories:) | ||
@promotion_categories = promotion_categories | ||
end | ||
|
||
def title | ||
Spree::PromotionCategory.model_name.human.pluralize | ||
end | ||
|
||
def columns | ||
[ | ||
name_column, | ||
code_column, | ||
] | ||
end | ||
|
||
def name_column | ||
{ | ||
header: :name, | ||
data: ->(promotion_category) do | ||
content_tag :div, promotion_category.name | ||
end | ||
} | ||
end | ||
|
||
def code_column | ||
{ | ||
header: :code, | ||
data: ->(promotion_category) do | ||
content_tag :div, promotion_category.code | ||
end | ||
} | ||
end | ||
|
||
def batch_actions | ||
[ | ||
{ | ||
display_name: t('.batch_actions.delete'), | ||
action: solidus_admin.promotion_categories_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/promotion_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: | ||
batch_actions: | ||
delete: 'Delete' | ||
create_promotion_category: Create Promotion Category |
31 changes: 31 additions & 0 deletions
31
admin/app/controllers/solidus_admin/promotion_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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin | ||
class PromotionCategoriesController < SolidusAdmin::BaseController | ||
before_action :load_promotion_category, only: [:move] | ||
|
||
def index | ||
@promotion_categories = Spree::PromotionCategory.all | ||
|
||
respond_to do |format| | ||
format.html { render component('promotion_categories/index').new(promotion_categories: @promotion_categories) } | ||
end | ||
end | ||
|
||
def destroy | ||
@promotion_categories = Spree::PromotionCategory.where(id: params[:id]) | ||
|
||
Spree::PromotionCategory.transaction { @promotion_categories.destroy_all } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to promotion_categories_path, status: :see_other | ||
end | ||
|
||
private | ||
|
||
def load_promotion_category | ||
@promotion_category = Spree::PromotionCategory.find(params[:id]) | ||
authorize! action_name, @promotion_category | ||
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: | ||
promotion_categories: | ||
title: "Promotion Categories" | ||
destroy: | ||
success: "Promotion 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
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe "Promotion Categories", :js, type: :feature do | ||
before { sign_in create(:admin_user, email: '[email protected]') } | ||
|
||
it "lists promotion categories and allows deleting them" do | ||
create(:promotion_category, name: "test1", code: "code1") | ||
create(:promotion_category, name: "test2", code: "code2") | ||
|
||
visit "/admin/promotion_categories" | ||
expect(page).to have_content("test1") | ||
expect(page).to have_content("test2") | ||
|
||
expect(page).to be_axe_clean | ||
|
||
select_row("test1") | ||
click_on "Delete" | ||
expect(page).to have_content("Promotion Categories were successfully removed.") | ||
expect(page).not_to have_content("test1") | ||
expect(Spree::PromotionCategory.count).to eq(1) | ||
end | ||
end |