-
-
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 a tax rates index with scopes and batch deletion
- Loading branch information
Showing
9 changed files
with
195 additions
and
3 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
admin/app/components/solidus_admin/tax_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
32 changes: 32 additions & 0 deletions
32
admin/app/components/solidus_admin/tax_rates/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('taxes').new(model_class: Spree::TaxRate) do |layout| %> | ||
<% layout.with_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.add'), | ||
href: spree.new_admin_tax_rate_path, | ||
icon: "add-line", | ||
class: "align-self-end w-full", | ||
) %> | ||
<% end %> | ||
|
||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: Spree::TaxRate, | ||
rows: @page.records, | ||
url: ->(tax_rate) { spree.edit_admin_tax_rate_path(tax_rate) }, | ||
prev: prev_page_path, | ||
next: next_page_path, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
search: { | ||
name: :q, | ||
value: params[:q], | ||
url: solidus_admin.tax_rates_path, | ||
searchbar_key: :name_or_description_cont, | ||
filters: filters, | ||
scopes: scopes, | ||
}, | ||
) %> | ||
<% end %> |
84 changes: 84 additions & 0 deletions
84
admin/app/components/solidus_admin/tax_rates/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,84 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::TaxRates::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(page:) | ||
@page = page | ||
end | ||
|
||
def title | ||
Spree::TaxRate.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.tax_rates_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
|
||
def filters | ||
[ | ||
{ | ||
presentation: Spree::Zone.model_name.human, | ||
attribute: :zone_id, | ||
predicate: :eq, | ||
options: Spree::Zone.pluck(:name, :id), | ||
}, | ||
{ | ||
presentation: Spree::TaxCategory.model_name.human, | ||
attribute: :tax_categories_id, | ||
predicate: :in, | ||
options: Spree::TaxCategory.pluck(:name, :id), | ||
} | ||
] | ||
end | ||
|
||
def scopes | ||
[] | ||
end | ||
|
||
def columns | ||
[ | ||
{ | ||
header: :zone, | ||
data: -> { _1.zone&.name }, | ||
}, | ||
:name, | ||
{ | ||
header: :tax_categories, | ||
data: -> { _1.tax_categories.map(&:name).join(', ') }, | ||
}, | ||
{ | ||
header: :amount, | ||
data: -> { _1.display_amount }, | ||
}, | ||
{ | ||
header: :included_in_price, | ||
data: -> { _1.included_in_price? ? component('ui/badge').yes : component('ui/badge').no }, | ||
}, | ||
{ | ||
header: :show_rate_in_label, | ||
data: -> { _1.show_rate_in_label? ? component('ui/badge').yes : component('ui/badge').no }, | ||
}, | ||
:expires_at, | ||
{ | ||
header: Spree::Calculator.model_name.human, | ||
data: -> { _1.calculator&.class&.model_name&.human } | ||
}, | ||
] | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
admin/app/components/solidus_admin/tax_rates/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
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/tax_rates_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 TaxRatesController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
def index | ||
tax_rates = apply_search_to( | ||
Spree::TaxRate.order(created_at: :desc, id: :desc), | ||
param: :q, | ||
) | ||
|
||
set_page_and_extract_portion_from(tax_rates) | ||
|
||
respond_to do |format| | ||
format.html { render component('tax_rates/index').new(page: @page) } | ||
end | ||
end | ||
|
||
def destroy | ||
@tax_rates = Spree::TaxRate.where(id: params[:id]) | ||
|
||
Spree::TaxRate.transaction { @tax_rates.destroy_all } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to tax_rates_path, status: :see_other | ||
end | ||
|
||
private | ||
|
||
def load_tax_rate | ||
@tax_rate = Spree::TaxRate.find_by!(number: params[:id]) | ||
authorize! action_name, @tax_rate | ||
end | ||
|
||
def tax_rate_params | ||
params.require(:tax_rate).permit(:tax_rate_id, permitted_tax_rate_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: | ||
tax_rates: | ||
title: "Tax Rates" | ||
destroy: | ||
success: "Tax rates 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,4 +69,10 @@ | |
delete :destroy | ||
end | ||
end | ||
|
||
resources :tax_rates, only: [:index] do | ||
collection do | ||
delete :destroy | ||
end | ||
end | ||
end |