-
-
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.
Merge pull request #5530 from nebulab/rainerd/admin/payment-methods-i…
…ndex-page [Admin] Add `Payment Methods` index component
- Loading branch information
Showing
20 changed files
with
282 additions
and
29 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
2 changes: 1 addition & 1 deletion
2
admin/app/components/solidus_admin/option_types/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
en: | ||
batch_actions: | ||
delete: 'Delete' | ||
create_option_type: Create Option Type | ||
add: 'Add new' |
35 changes: 35 additions & 0 deletions
35
admin/app/components/solidus_admin/payment_methods/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,35 @@ | ||
<%= page do %> | ||
<%= page_header do %> | ||
<%= page_header_title title %> | ||
<%= page_header_actions do %> | ||
<%= render component("ui/button").new( | ||
tag: :a, | ||
text: t('.add'), | ||
href: spree.new_admin_payment_method_path, | ||
icon: "add-line", | ||
) %> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= render component('ui/table').new( | ||
id: stimulus_id, | ||
data: { | ||
class: Spree::PaymentMethod, | ||
rows: @payment_methods, | ||
url: ->(payment_method) { spree.edit_admin_payment_method_path(payment_method) }, | ||
columns: columns, | ||
batch_actions: batch_actions, | ||
}, | ||
search: { | ||
name: :q, | ||
value: params[:q], | ||
url: solidus_admin.payment_methods_path, | ||
searchbar_key: :name_or_description_cont, | ||
scopes: scopes, | ||
}, | ||
sortable: { | ||
url: ->(payment_method) { solidus_admin.move_payment_method_path(payment_method) }, | ||
param: 'position', | ||
}, | ||
) %> | ||
<% end %> |
81 changes: 81 additions & 0 deletions
81
admin/app/components/solidus_admin/payment_methods/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::PaymentMethods::Index::Component < SolidusAdmin::BaseComponent | ||
include SolidusAdmin::Layout::PageHelpers | ||
|
||
def initialize(payment_methods:) | ||
@payment_methods = payment_methods | ||
end | ||
|
||
def title | ||
Spree::PaymentMethod.model_name.human.pluralize | ||
end | ||
|
||
def batch_actions | ||
[ | ||
{ | ||
display_name: t('.batch_actions.delete'), | ||
action: solidus_admin.payment_methods_path, | ||
method: :delete, | ||
icon: 'delete-bin-7-line', | ||
}, | ||
] | ||
end | ||
|
||
def scopes | ||
[ | ||
{ name: :all, label: t('.scopes.all'), default: true }, | ||
{ name: :active, label: t('.scopes.active') }, | ||
{ name: :inactive, label: t('.scopes.inactive') }, | ||
{ name: :storefront, label: t('.scopes.storefront') }, | ||
{ name: :admin, label: t('.scopes.admin') }, | ||
] | ||
end | ||
|
||
def columns | ||
[ | ||
{ | ||
header: :name, | ||
data: ->(payment_method) do | ||
content_tag :div, payment_method.name | ||
end | ||
}, | ||
{ | ||
header: :type, | ||
data: ->(payment_method) do | ||
content_tag :div, payment_method.model_name.human | ||
end | ||
}, | ||
{ | ||
header: :available_to_users, | ||
data: ->(payment_method) do | ||
if payment_method.available_to_users? | ||
component('ui/badge').new(name: t('.yes'), color: :green) | ||
else | ||
component('ui/badge').new(name: t('.no'), color: :graphite_light) | ||
end | ||
end | ||
}, | ||
{ | ||
header: :available_to_admin, | ||
data: ->(payment_method) do | ||
if payment_method.available_to_admin? | ||
component('ui/badge').new(name: t('.yes'), color: :green) | ||
else | ||
component('ui/badge').new(name: t('.no'), color: :graphite_light) | ||
end | ||
end | ||
}, | ||
{ | ||
header: :status, | ||
data: ->(payment_method) do | ||
if payment_method.active? | ||
render component('ui/badge').new(name: t('.status.active'), color: :green) | ||
else | ||
render component('ui/badge').new(name: t('.status.inactive'), color: :graphite_light) | ||
end | ||
end | ||
}, | ||
] | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
admin/app/components/solidus_admin/payment_methods/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,15 @@ | ||
en: | ||
add: 'Add new' | ||
"yes": "Yes" | ||
"no": "No" | ||
status: | ||
active: Active | ||
inactive: Inactive | ||
scopes: | ||
active: Active | ||
inactive: Inactive | ||
admin: Admin | ||
storefront: Storefront | ||
all: All | ||
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
2 changes: 1 addition & 1 deletion
2
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
en: | ||
batch_actions: | ||
delete: 'Delete' | ||
create_promotion_category: Create Promotion Category | ||
add: 'Add new' |
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
2 changes: 1 addition & 1 deletion
2
admin/app/components/solidus_admin/properties/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
en: | ||
add_property: 'Add Property' | ||
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
2 changes: 1 addition & 1 deletion
2
admin/app/components/solidus_admin/taxonomies/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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
en: | ||
batch_actions: | ||
delete: 'Delete' | ||
create_taxonomy: Create Taxonomy | ||
add: 'Add new' |
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
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
50 changes: 50 additions & 0 deletions
50
admin/app/controllers/solidus_admin/payment_methods_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,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin | ||
class PaymentMethodsController < SolidusAdmin::BaseController | ||
include SolidusAdmin::ControllerHelpers::Search | ||
|
||
before_action :load_payment_method, only: [:move] | ||
|
||
search_scope(:all) | ||
search_scope(:active, default: true, &:active) | ||
search_scope(:inactive) { _1.where.not(active: true) } | ||
search_scope(:storefront, &:available_to_users) | ||
search_scope(:admin, &:available_to_admin) | ||
|
||
def index | ||
@payment_methods = apply_search_to( | ||
Spree::PaymentMethod.ordered_by_position, | ||
param: :q, | ||
) | ||
|
||
respond_to do |format| | ||
format.html { render component('payment_methods/index').new(payment_methods: @payment_methods) } | ||
end | ||
end | ||
|
||
def move | ||
@payment_method.insert_at(params[:position].to_i) | ||
|
||
respond_to do |format| | ||
format.js { head :no_content } | ||
end | ||
end | ||
|
||
def destroy | ||
@payment_methods = Spree::PaymentMethod.where(id: params[:id]) | ||
|
||
Spree::PaymentMethod.transaction { @payment_methods.destroy_all } | ||
|
||
flash[:notice] = t('.success') | ||
redirect_back_or_to payment_methods_path, status: :see_other | ||
end | ||
|
||
private | ||
|
||
def load_payment_method | ||
@payment_method = Spree::PaymentMethod.find_by!(id: params[:id]) | ||
authorize! action_name, @payment_method | ||
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: | ||
payment_methods: | ||
title: "Payment Methods" | ||
destroy: | ||
success: "Payment Methods 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
Oops, something went wrong.