-
-
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
adjustment reasons
index page with dedicated actions
- Loading branch information
1 parent
b50666b
commit bbb692c
Showing
8 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
admin/app/components/solidus_admin/adjustment_reasons/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,31 @@ | ||
<%= render component('refunds_and_returns').new(current_class: Spree::AdjustmentReason) do |layout| %> | ||
<% layout.with_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.add'), | ||
href: spree.new_admin_adjustment_reason_path, | ||
icon: "add-line", | ||
class: "align-self-end w-full", | ||
) %> | ||
<% end %> | ||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: Spree::AdjustmentReason, | ||
rows: @page.records, | ||
url: ->(adjustment_reason) { spree.edit_admin_adjustment_reason_path(adjustment_reason) }, | ||
prev: prev_page_path, | ||
next: next_page_path, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
search: { | ||
name: :q, | ||
value: params[:q], | ||
url: solidus_admin.adjustment_reasons_path, | ||
searchbar_key: :name_cont, | ||
filters: filters, | ||
scopes: scopes, | ||
}, | ||
) %> | ||
<% end %> |
53 changes: 53 additions & 0 deletions
53
admin/app/components/solidus_admin/adjustment_reasons/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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::AdjustmentReasons::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(page:) | ||
@page = page | ||
end | ||
|
||
def title | ||
Spree::AdjustmentReason.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.adjustment_reasons_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
|
||
def filters | ||
[] | ||
end | ||
|
||
def scopes | ||
[] | ||
end | ||
|
||
def columns | ||
[ | ||
:name, | ||
:code, | ||
{ | ||
header: :active, | ||
data: ->(adjustment_reason) do | ||
adjustment_reason.active? ? component('ui/badge').yes : component('ui/badge').no | ||
end | ||
}, | ||
] | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/adjustment_reasons/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' |
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
40 changes: 40 additions & 0 deletions
40
admin/app/controllers/solidus_admin/adjustment_reasons_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 AdjustmentReasonsController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
def index | ||
adjustment_reasons = apply_search_to( | ||
Spree::AdjustmentReason.order(id: :desc), | ||
param: :q, | ||
) | ||
|
||
set_page_and_extract_portion_from(adjustment_reasons) | ||
|
||
respond_to do |format| | ||
format.html { render component('adjustment_reasons/index').new(page: @page) } | ||
end | ||
end | ||
|
||
def destroy | ||
@adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id]) | ||
|
||
Spree::AdjustmentReason.transaction { @adjustment_reason.destroy } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to adjustment_reasons_path, status: :see_other | ||
end | ||
|
||
private | ||
|
||
def load_adjustment_reason | ||
@adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id]) | ||
authorize! action_name, @adjustment_reason | ||
end | ||
|
||
def adjustment_reason_params | ||
params.require(:adjustment_reason).permit(:adjustment_reason_id, permitted_adjustment_reason_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: | ||
adjustment_reasons: | ||
title: "Adjustment Reasons" | ||
destroy: | ||
success: "Adjustment Reasons 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,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe "Adjustment Reasons", :js, type: :feature do | ||
before { sign_in create(:admin_user, email: '[email protected]') } | ||
|
||
it "lists adjustment reasons and allows deleting them" do | ||
create(:adjustment_reason, name: "Default-adjustment-reason") | ||
|
||
visit "/admin/adjustment_reasons" | ||
expect(page).to have_content("Default-adjustment-reason") | ||
expect(page).to be_axe_clean | ||
|
||
select_row("Default-adjustment-reason") | ||
click_on "Delete" | ||
expect(page).to have_content("Adjustment Reasons were successfully removed.") | ||
expect(page).not_to have_content("Default-adjustment-reason") | ||
expect(Spree::AdjustmentReason.count).to eq(0) | ||
expect(page).to be_axe_clean | ||
end | ||
end |