solidus_admin 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.prettierrc +4 -0
- data/app/assets/builds/solidus_admin/tailwind.css +164 -132
- data/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +2 -3
- data/app/components/solidus_admin/adjustment_reasons/edit/component.rb +1 -9
- data/app/components/solidus_admin/adjustment_reasons/index/component.rb +22 -8
- data/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +2 -4
- data/app/components/solidus_admin/adjustment_reasons/new/component.rb +1 -9
- data/app/components/solidus_admin/base_component.rb +7 -9
- data/app/components/solidus_admin/layout/navigation/account/component.rb +2 -2
- data/app/components/solidus_admin/layout/navigation/component.js +1 -1
- data/app/components/solidus_admin/layout/navigation/component.rb +1 -1
- data/app/components/solidus_admin/layout/navigation/item/component.html.erb +2 -2
- data/app/components/solidus_admin/layout/navigation/item/component.rb +3 -6
- data/app/components/solidus_admin/orders/index/component.rb +3 -3
- data/app/components/solidus_admin/orders/show/address/component.js +2 -2
- data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/component.rb +1 -1
- data/app/components/solidus_admin/orders/show/adjustments/index/source/component.rb +1 -1
- data/app/components/solidus_admin/orders/show/component.js +2 -2
- data/app/components/solidus_admin/orders/show/customer_search/component.js +5 -4
- data/app/components/solidus_admin/orders/show/summary/component.html.erb +6 -6
- data/app/components/solidus_admin/products/show/component.html.erb +7 -1
- data/app/components/solidus_admin/products/show/component.rb +6 -0
- data/app/components/solidus_admin/products/status/component.rb +1 -1
- data/app/components/solidus_admin/properties/edit/component.html.erb +16 -0
- data/app/components/solidus_admin/properties/edit/component.rb +4 -0
- data/app/components/solidus_admin/properties/edit/component.yml +4 -0
- data/app/components/solidus_admin/properties/index/component.rb +19 -6
- data/app/components/solidus_admin/properties/new/component.html.erb +16 -0
- data/app/components/solidus_admin/properties/new/component.rb +4 -0
- data/app/components/solidus_admin/properties/new/component.yml +4 -0
- data/app/components/solidus_admin/refund_reasons/edit/component.html.erb +2 -3
- data/app/components/solidus_admin/refund_reasons/edit/component.rb +1 -9
- data/app/components/solidus_admin/refund_reasons/index/component.rb +22 -8
- data/app/components/solidus_admin/refund_reasons/new/component.html.erb +2 -4
- data/app/components/solidus_admin/refund_reasons/new/component.rb +1 -9
- data/app/components/solidus_admin/resources/base_component.rb +20 -0
- data/app/components/solidus_admin/resources/edit/component.rb +11 -0
- data/app/components/solidus_admin/resources/new/component.rb +11 -0
- data/app/components/solidus_admin/return_reasons/edit/component.html.erb +2 -3
- data/app/components/solidus_admin/return_reasons/edit/component.rb +1 -9
- data/app/components/solidus_admin/return_reasons/index/component.rb +13 -7
- data/app/components/solidus_admin/return_reasons/new/component.html.erb +2 -4
- data/app/components/solidus_admin/return_reasons/new/component.rb +1 -9
- data/app/components/solidus_admin/roles/edit/component.html.erb +2 -4
- data/app/components/solidus_admin/roles/edit/component.rb +1 -10
- data/app/components/solidus_admin/roles/index/component.rb +16 -8
- data/app/components/solidus_admin/roles/new/component.html.erb +2 -4
- data/app/components/solidus_admin/roles/new/component.rb +1 -10
- data/app/components/solidus_admin/shipping_categories/edit/component.html.erb +2 -3
- data/app/components/solidus_admin/shipping_categories/edit/component.rb +1 -9
- data/app/components/solidus_admin/shipping_categories/index/component.rb +14 -17
- data/app/components/solidus_admin/shipping_categories/new/component.html.erb +2 -4
- data/app/components/solidus_admin/shipping_categories/new/component.rb +1 -9
- data/app/components/solidus_admin/stock_items/edit/component.html.erb +74 -73
- data/app/components/solidus_admin/stock_items/edit/component.js +4 -3
- data/app/components/solidus_admin/stock_items/edit/component.rb +1 -10
- data/app/components/solidus_admin/stock_items/index/component.rb +10 -6
- data/app/components/solidus_admin/stock_locations/index/component.rb +2 -2
- data/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +2 -3
- data/app/components/solidus_admin/store_credit_reasons/edit/component.rb +1 -9
- data/app/components/solidus_admin/store_credit_reasons/index/component.rb +14 -7
- data/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +2 -4
- data/app/components/solidus_admin/store_credit_reasons/new/component.rb +1 -9
- data/app/components/solidus_admin/tax_categories/edit/component.html.erb +2 -4
- data/app/components/solidus_admin/tax_categories/edit/component.rb +1 -9
- data/app/components/solidus_admin/tax_categories/index/component.rb +30 -9
- data/app/components/solidus_admin/tax_categories/new/component.html.erb +2 -4
- data/app/components/solidus_admin/tax_categories/new/component.rb +1 -9
- data/app/components/solidus_admin/ui/dropdown/component.js +3 -3
- data/app/components/solidus_admin/ui/forms/address/component.js +5 -6
- data/app/components/solidus_admin/ui/forms/field/component.rb +18 -18
- data/app/components/solidus_admin/ui/forms/input/component.js +3 -4
- data/app/components/solidus_admin/ui/forms/input/component.rb +15 -4
- data/app/components/solidus_admin/ui/icon/component.rb +3 -1
- data/app/components/solidus_admin/ui/modal/component.js +2 -2
- data/app/components/solidus_admin/ui/pages/index/component.html.erb +3 -3
- data/app/components/solidus_admin/ui/pages/index/component.rb +11 -6
- data/app/components/solidus_admin/ui/table/component.html.erb +4 -3
- data/app/components/solidus_admin/ui/table/component.js +13 -17
- data/app/components/solidus_admin/ui/table/component.rb +1 -1
- data/app/components/solidus_admin/ui/table/ransack_filter/component.js +18 -16
- data/app/components/solidus_admin/ui/thumbnail_with_caption/component.rb +1 -1
- data/app/components/solidus_admin/ui/toast/component.html.erb +1 -1
- data/app/components/solidus_admin/ui/toast/component.js +3 -3
- data/app/components/solidus_admin/ui/toggletip/component.js +14 -12
- data/app/components/solidus_admin/users/index/component.rb +1 -1
- data/app/components/solidus_admin/users/orders/component.rb +1 -1
- data/app/components/solidus_admin/users/store_credits/edit_amount/component.html.erb +22 -0
- data/app/components/solidus_admin/users/store_credits/edit_amount/component.rb +22 -0
- data/app/components/solidus_admin/users/store_credits/edit_amount/component.yml +5 -0
- data/app/components/solidus_admin/users/store_credits/edit_memo/component.html.erb +15 -0
- data/app/components/solidus_admin/users/store_credits/edit_memo/component.rb +16 -0
- data/app/components/solidus_admin/users/store_credits/edit_memo/component.yml +4 -0
- data/app/components/solidus_admin/users/store_credits/edit_validity/component.html.erb +21 -0
- data/app/components/solidus_admin/users/store_credits/edit_validity/component.rb +22 -0
- data/app/components/solidus_admin/users/store_credits/edit_validity/component.yml +5 -0
- data/app/components/solidus_admin/users/store_credits/index/component.html.erb +65 -0
- data/app/components/solidus_admin/users/store_credits/index/component.rb +114 -0
- data/app/components/solidus_admin/users/store_credits/index/component.yml +12 -0
- data/app/components/solidus_admin/users/store_credits/new/component.html.erb +30 -0
- data/app/components/solidus_admin/users/store_credits/new/component.rb +22 -0
- data/app/components/solidus_admin/users/store_credits/new/component.yml +5 -0
- data/app/components/solidus_admin/users/store_credits/show/component.html.erb +83 -0
- data/app/components/solidus_admin/users/store_credits/show/component.rb +120 -0
- data/app/components/solidus_admin/users/store_credits/show/component.yml +18 -0
- data/app/controllers/solidus_admin/adjustment_reasons_controller.rb +3 -105
- data/app/controllers/solidus_admin/authentication_adapters/backend.rb +1 -1
- data/app/controllers/solidus_admin/base_controller.rb +12 -1
- data/app/controllers/solidus_admin/controller_helpers/search.rb +4 -4
- data/app/controllers/solidus_admin/properties_controller.rb +6 -24
- data/app/controllers/solidus_admin/refund_reasons_controller.rb +5 -105
- data/app/controllers/solidus_admin/resources_controller.rb +152 -0
- data/app/controllers/solidus_admin/return_reasons_controller.rb +4 -104
- data/app/controllers/solidus_admin/roles_controller.rb +3 -105
- data/app/controllers/solidus_admin/shipping_categories_controller.rb +3 -107
- data/app/controllers/solidus_admin/stock_items_controller.rb +12 -29
- data/app/controllers/solidus_admin/store_credit_reasons_controller.rb +5 -105
- data/app/controllers/solidus_admin/store_credits_controller.rb +231 -0
- data/app/controllers/solidus_admin/tax_categories_controller.rb +3 -109
- data/app/helpers/solidus_admin/void_elements_helper.rb +13 -0
- data/app/views/layouts/solidus_admin/application.html.erb +3 -0
- data/config/locales/menu_item.en.yml +0 -1
- data/config/locales/properties.en.yml +4 -0
- data/config/locales/store_credits.en.yml +16 -0
- data/config/routes.rb +12 -1
- data/lib/generators/solidus_admin/install/install_generator.rb +2 -0
- data/lib/solidus_admin/component_registry.rb +1 -1
- data/lib/solidus_admin/configuration.rb +3 -8
- data/lib/solidus_admin/engine.rb +6 -0
- data/lib/solidus_admin/install_tailwindcss.rb +1 -1
- data/lib/solidus_admin/testing_support/component_helpers.rb +3 -9
- data/lib/solidus_admin/testing_support/feature_helpers.rb +1 -1
- data/lib/solidus_admin/testing_support/shared_examples/bulk_delete_resources.rb +20 -0
- data/lib/solidus_admin/testing_support/shared_examples/crud_resource_requests.rb +138 -0
- data/lib/solidus_admin/testing_support/shared_examples/promotion_categories_features.rb +72 -0
- data/lib/solidus_admin/version.rb +1 -1
- data/solidus_admin.gemspec +2 -2
- metadata +39 -8
- data/bin/rails +0 -13
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SolidusAdmin::Users::StoreCredits::Show::Component < SolidusAdmin::BaseComponent
|
4
|
+
include SolidusAdmin::Layout::PageHelpers
|
5
|
+
include Spree::Admin::StoreCreditEventsHelper
|
6
|
+
|
7
|
+
def initialize(user:, store_credit:, events:)
|
8
|
+
@user = user
|
9
|
+
@store_credit = store_credit
|
10
|
+
@events = events
|
11
|
+
end
|
12
|
+
|
13
|
+
def model_class
|
14
|
+
Spree::StoreCredit
|
15
|
+
end
|
16
|
+
|
17
|
+
def event_model_class
|
18
|
+
Spree::StoreCreditEvent
|
19
|
+
end
|
20
|
+
|
21
|
+
def tabs
|
22
|
+
[
|
23
|
+
{
|
24
|
+
text: t('.account'),
|
25
|
+
href: solidus_admin.user_path(@user),
|
26
|
+
current: false,
|
27
|
+
},
|
28
|
+
{
|
29
|
+
text: t('.addresses'),
|
30
|
+
href: solidus_admin.addresses_user_path(@user),
|
31
|
+
current: false,
|
32
|
+
},
|
33
|
+
{
|
34
|
+
text: t('.order_history'),
|
35
|
+
href: solidus_admin.orders_user_path(@user),
|
36
|
+
current: false,
|
37
|
+
},
|
38
|
+
{
|
39
|
+
text: t('.items'),
|
40
|
+
href: spree.items_admin_user_path(@user),
|
41
|
+
current: false,
|
42
|
+
},
|
43
|
+
{
|
44
|
+
text: t('.store_credit'),
|
45
|
+
href: solidus_admin.user_store_credits_path(@user),
|
46
|
+
current: true,
|
47
|
+
},
|
48
|
+
]
|
49
|
+
end
|
50
|
+
|
51
|
+
def form_id
|
52
|
+
@form_id ||= "#{stimulus_id}--form-#{@store_credit.id}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def edit_validity_url
|
56
|
+
solidus_admin.edit_validity_user_store_credit_path(@user, @store_credit, **search_filter_params)
|
57
|
+
end
|
58
|
+
|
59
|
+
def edit_memo_url
|
60
|
+
solidus_admin.edit_memo_user_store_credit_path(@user, @store_credit, **search_filter_params)
|
61
|
+
end
|
62
|
+
|
63
|
+
def edit_amount_url
|
64
|
+
solidus_admin.edit_amount_user_store_credit_path(@user, @store_credit, **search_filter_params)
|
65
|
+
end
|
66
|
+
|
67
|
+
def columns
|
68
|
+
[
|
69
|
+
{
|
70
|
+
header: :date,
|
71
|
+
col: { class: "w-[15%]" },
|
72
|
+
data: ->(event) do
|
73
|
+
content_tag :span, I18n.l(event.created_at, format: :short), class: "text-sm"
|
74
|
+
end
|
75
|
+
},
|
76
|
+
{
|
77
|
+
header: :action,
|
78
|
+
col: { class: "w-[10%]" },
|
79
|
+
data: ->(event) do
|
80
|
+
content_tag :span, store_credit_event_admin_action_name(event), class: "text-sm"
|
81
|
+
end
|
82
|
+
},
|
83
|
+
{
|
84
|
+
header: :credited,
|
85
|
+
col: { class: "w-[10%]" },
|
86
|
+
data: ->(event) do
|
87
|
+
content_tag :span, event.display_amount, class: "text-sm"
|
88
|
+
end
|
89
|
+
},
|
90
|
+
{
|
91
|
+
header: :created_by,
|
92
|
+
col: { class: "w-[20%]" },
|
93
|
+
data: ->(event) do
|
94
|
+
content_tag :span, store_credit_event_originator_link(event), class: "body-link text-sm"
|
95
|
+
end
|
96
|
+
},
|
97
|
+
{
|
98
|
+
header: :total_amount,
|
99
|
+
col: { class: "w-[10%]" },
|
100
|
+
data: ->(event) do
|
101
|
+
content_tag :span, event.display_user_total_amount, class: "text-sm"
|
102
|
+
end
|
103
|
+
},
|
104
|
+
{
|
105
|
+
header: :total_unused,
|
106
|
+
col: { class: "w-[10%]" },
|
107
|
+
data: ->(event) do
|
108
|
+
content_tag :span, event.display_remaining_amount, class: "text-sm"
|
109
|
+
end
|
110
|
+
},
|
111
|
+
{
|
112
|
+
header: :reason_for_updating,
|
113
|
+
col: { class: "w-[25%]" },
|
114
|
+
data: ->(event) do
|
115
|
+
content_tag :span, event.store_credit_reason&.name, class: "text-sm"
|
116
|
+
end
|
117
|
+
},
|
118
|
+
]
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
en:
|
2
|
+
title: "Users / %{email} / Store Credit / %{amount}"
|
3
|
+
account: Account
|
4
|
+
addresses: Addresses
|
5
|
+
order_history: Order History
|
6
|
+
items: Items
|
7
|
+
store_credit: Store Credit
|
8
|
+
last_active: Last Active
|
9
|
+
add_store_credit: Add Store Credit
|
10
|
+
edit_amount: Edit Amount
|
11
|
+
edit_memo: Edit Memo
|
12
|
+
invalidate: Invalidate
|
13
|
+
store_credit_history: Store Credit History
|
14
|
+
credited: Credited
|
15
|
+
created_by: Created By
|
16
|
+
type: Type
|
17
|
+
memo: Memo
|
18
|
+
back: Back
|
@@ -1,115 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusAdmin
|
4
|
-
class AdjustmentReasonsController < SolidusAdmin::
|
5
|
-
include SolidusAdmin::ControllerHelpers::Search
|
6
|
-
|
7
|
-
before_action :set_adjustment_reason, only: %i[edit update]
|
8
|
-
|
9
|
-
def index
|
10
|
-
set_index_page
|
11
|
-
|
12
|
-
respond_to do |format|
|
13
|
-
format.html { render component('adjustment_reasons/index').new(page: @page) }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def new
|
18
|
-
@adjustment_reason = Spree::AdjustmentReason.new
|
19
|
-
|
20
|
-
set_index_page
|
21
|
-
|
22
|
-
respond_to do |format|
|
23
|
-
format.html { render component('adjustment_reasons/new').new(page: @page, adjustment_reason: @adjustment_reason) }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def create
|
28
|
-
@adjustment_reason = Spree::AdjustmentReason.new(adjustment_reason_params)
|
29
|
-
|
30
|
-
if @adjustment_reason.save
|
31
|
-
respond_to do |format|
|
32
|
-
flash[:notice] = t('.success')
|
33
|
-
|
34
|
-
format.html do
|
35
|
-
redirect_to solidus_admin.adjustment_reasons_path, status: :see_other
|
36
|
-
end
|
37
|
-
|
38
|
-
format.turbo_stream do
|
39
|
-
render turbo_stream: '<turbo-stream action="refresh" />'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
else
|
43
|
-
set_index_page
|
44
|
-
|
45
|
-
respond_to do |format|
|
46
|
-
format.html do
|
47
|
-
page_component = component('adjustment_reasons/new').new(page: @page, adjustment_reason: @adjustment_reason)
|
48
|
-
render page_component, status: :unprocessable_entity
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def edit
|
55
|
-
set_index_page
|
56
|
-
|
57
|
-
respond_to do |format|
|
58
|
-
format.html { render component('adjustment_reasons/edit').new(page: @page, adjustment_reason: @adjustment_reason) }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def update
|
63
|
-
if @adjustment_reason.update(adjustment_reason_params)
|
64
|
-
respond_to do |format|
|
65
|
-
flash[:notice] = t('.success')
|
66
|
-
|
67
|
-
format.html do
|
68
|
-
redirect_to solidus_admin.adjustment_reasons_path, status: :see_other
|
69
|
-
end
|
70
|
-
|
71
|
-
format.turbo_stream do
|
72
|
-
render turbo_stream: '<turbo-stream action="refresh" />'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
else
|
76
|
-
set_index_page
|
77
|
-
|
78
|
-
respond_to do |format|
|
79
|
-
format.html do
|
80
|
-
page_component = component('adjustment_reasons/edit').new(page: @page, adjustment_reason: @adjustment_reason)
|
81
|
-
render page_component, status: :unprocessable_entity
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def destroy
|
88
|
-
@adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id])
|
89
|
-
|
90
|
-
Spree::AdjustmentReason.transaction { @adjustment_reason.destroy }
|
91
|
-
|
92
|
-
flash[:notice] = t('.success')
|
93
|
-
redirect_back_or_to adjustment_reasons_path, status: :see_other
|
94
|
-
end
|
95
|
-
|
4
|
+
class AdjustmentReasonsController < SolidusAdmin::ResourcesController
|
96
5
|
private
|
97
6
|
|
98
|
-
def
|
99
|
-
@adjustment_reason = Spree::AdjustmentReason.find(params[:id])
|
100
|
-
end
|
7
|
+
def resource_class = Spree::AdjustmentReason
|
101
8
|
|
102
|
-
def
|
9
|
+
def permitted_resource_params
|
103
10
|
params.require(:adjustment_reason).permit(:name, :code, :active)
|
104
11
|
end
|
105
|
-
|
106
|
-
def set_index_page
|
107
|
-
adjustment_reasons = apply_search_to(
|
108
|
-
Spree::AdjustmentReason.order(id: :desc),
|
109
|
-
param: :q,
|
110
|
-
)
|
111
|
-
|
112
|
-
set_page_and_extract_portion_from(adjustment_reasons)
|
113
|
-
end
|
114
12
|
end
|
115
13
|
end
|
@@ -13,7 +13,7 @@ module SolidusAdmin::AuthenticationAdapters::Backend
|
|
13
13
|
def authenticate_solidus_backend_user!
|
14
14
|
return if spree_current_user
|
15
15
|
|
16
|
-
|
16
|
+
Spree::Backend::Config.unauthorized_redirect_handler_class.new(self).call
|
17
17
|
end
|
18
18
|
|
19
19
|
def store_location
|
@@ -15,8 +15,19 @@ module SolidusAdmin
|
|
15
15
|
include SolidusAdmin::ComponentsHelper
|
16
16
|
include SolidusAdmin::AuthenticationAdapters::Backend if defined?(Spree::Backend)
|
17
17
|
|
18
|
-
layout
|
18
|
+
layout :set_layout
|
19
|
+
|
19
20
|
helper 'solidus_admin/components'
|
20
21
|
helper 'solidus_admin/layout'
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def set_layout
|
26
|
+
if turbo_frame_request?
|
27
|
+
'turbo_rails/frame'
|
28
|
+
else
|
29
|
+
'solidus_admin/application'
|
30
|
+
end
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
@@ -7,8 +7,8 @@ module SolidusAdmin::ControllerHelpers::Search
|
|
7
7
|
def search_scope(name, default: false, &block)
|
8
8
|
search_scopes << SearchScope.new(
|
9
9
|
name: name.to_s,
|
10
|
-
block
|
11
|
-
default
|
10
|
+
block:,
|
11
|
+
default:,
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
@@ -20,8 +20,8 @@ module SolidusAdmin::ControllerHelpers::Search
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def apply_search_to(relation, param:)
|
23
|
-
relation = apply_scopes_to(relation, param:
|
24
|
-
apply_ransack_search_to(relation, param:
|
23
|
+
relation = apply_scopes_to(relation, param:)
|
24
|
+
apply_ransack_search_to(relation, param:)
|
25
25
|
end
|
26
26
|
|
27
27
|
def apply_ransack_search_to(relation, param:)
|
@@ -1,33 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusAdmin
|
4
|
-
class PropertiesController < SolidusAdmin::
|
5
|
-
|
4
|
+
class PropertiesController < SolidusAdmin::ResourcesController
|
5
|
+
private
|
6
6
|
|
7
|
-
def
|
8
|
-
properties = apply_search_to(
|
9
|
-
Spree::Property.order(created_at: :desc, id: :desc),
|
10
|
-
param: :q,
|
11
|
-
)
|
7
|
+
def resource_class = Spree::Property
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
)
|
16
|
-
|
17
|
-
respond_to do |format|
|
18
|
-
format.html { render component('properties/index').new(page: @page) }
|
19
|
-
end
|
9
|
+
def permitted_resource_params
|
10
|
+
params.require(:property).permit(:name, :presentation)
|
20
11
|
end
|
21
12
|
|
22
|
-
def
|
23
|
-
@properties = Spree::Property.where(id: params[:id])
|
24
|
-
|
25
|
-
Spree::Property.transaction do
|
26
|
-
@properties.destroy_all
|
27
|
-
end
|
28
|
-
|
29
|
-
flash[:notice] = t('.success')
|
30
|
-
redirect_to properties_path, status: :see_other
|
31
|
-
end
|
13
|
+
def resources_collection = Spree::Property.unscoped
|
32
14
|
end
|
33
15
|
end
|
@@ -1,115 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusAdmin
|
4
|
-
class RefundReasonsController < SolidusAdmin::
|
5
|
-
include SolidusAdmin::ControllerHelpers::Search
|
6
|
-
|
7
|
-
before_action :set_refund_reason, only: %i[edit update]
|
8
|
-
|
9
|
-
def index
|
10
|
-
set_index_page
|
11
|
-
|
12
|
-
respond_to do |format|
|
13
|
-
format.html { render component('refund_reasons/index').new(page: @page) }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def new
|
18
|
-
@refund_reason = Spree::RefundReason.new
|
19
|
-
|
20
|
-
set_index_page
|
21
|
-
|
22
|
-
respond_to do |format|
|
23
|
-
format.html { render component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason) }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def create
|
28
|
-
@refund_reason = Spree::RefundReason.new(refund_reason_params)
|
29
|
-
|
30
|
-
if @refund_reason.save
|
31
|
-
respond_to do |format|
|
32
|
-
flash[:notice] = t('.success')
|
33
|
-
|
34
|
-
format.html do
|
35
|
-
redirect_to solidus_admin.refund_reasons_path, status: :see_other
|
36
|
-
end
|
37
|
-
|
38
|
-
format.turbo_stream do
|
39
|
-
render turbo_stream: '<turbo-stream action="refresh" />'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
else
|
43
|
-
set_index_page
|
44
|
-
|
45
|
-
respond_to do |format|
|
46
|
-
format.html do
|
47
|
-
page_component = component('refund_reasons/new').new(page: @page, refund_reason: @refund_reason)
|
48
|
-
render page_component, status: :unprocessable_entity
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def edit
|
55
|
-
set_index_page
|
56
|
-
|
57
|
-
respond_to do |format|
|
58
|
-
format.html { render component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason) }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def update
|
63
|
-
if @refund_reason.update(refund_reason_params)
|
64
|
-
respond_to do |format|
|
65
|
-
flash[:notice] = t('.success')
|
66
|
-
|
67
|
-
format.html do
|
68
|
-
redirect_to solidus_admin.refund_reasons_path, status: :see_other
|
69
|
-
end
|
70
|
-
|
71
|
-
format.turbo_stream do
|
72
|
-
render turbo_stream: '<turbo-stream action="refresh" />'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
else
|
76
|
-
set_index_page
|
77
|
-
|
78
|
-
respond_to do |format|
|
79
|
-
format.html do
|
80
|
-
page_component = component('refund_reasons/edit').new(page: @page, refund_reason: @refund_reason)
|
81
|
-
render page_component, status: :unprocessable_entity
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def destroy
|
88
|
-
@refund_reason = Spree::RefundReason.find_by!(id: params[:id])
|
89
|
-
|
90
|
-
Spree::RefundReason.transaction { @refund_reason.destroy }
|
91
|
-
|
92
|
-
flash[:notice] = t('.success')
|
93
|
-
redirect_back_or_to refund_reasons_path, status: :see_other
|
94
|
-
end
|
95
|
-
|
4
|
+
class RefundReasonsController < SolidusAdmin::ResourcesController
|
96
5
|
private
|
97
6
|
|
98
|
-
def
|
99
|
-
@refund_reason = Spree::RefundReason.find(params[:id])
|
100
|
-
end
|
101
|
-
|
102
|
-
def refund_reason_params
|
103
|
-
params.require(:refund_reason).permit(:name, :code, :active)
|
104
|
-
end
|
7
|
+
def resource_class = Spree::RefundReason
|
105
8
|
|
106
|
-
def
|
107
|
-
refund_reasons = apply_search_to(
|
108
|
-
Spree::RefundReason.unscoped.order(id: :desc),
|
109
|
-
param: :q,
|
110
|
-
)
|
9
|
+
def resources_collection = Spree::RefundReason.unscoped
|
111
10
|
|
112
|
-
|
11
|
+
def permitted_resource_params
|
12
|
+
params.require(:refund_reason).permit(:name, :code, :active)
|
113
13
|
end
|
114
14
|
end
|
115
15
|
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusAdmin
|
4
|
+
class ResourcesController < SolidusAdmin::BaseController
|
5
|
+
include SolidusAdmin::ControllerHelpers::Search
|
6
|
+
|
7
|
+
helper_method :search_filter_params
|
8
|
+
|
9
|
+
before_action :set_paginated_resources, only: %i[index]
|
10
|
+
before_action :set_resource, only: %i[edit update]
|
11
|
+
|
12
|
+
# GET /index
|
13
|
+
#
|
14
|
+
# Uses {set_paginated_resources} to set @resources
|
15
|
+
# and a instance variable with the plural name of the resource.
|
16
|
+
#
|
17
|
+
# Uses the geared_pagination gem to set @page for pagination.
|
18
|
+
#
|
19
|
+
# @see set_paginated_resources
|
20
|
+
# @see resources_collection
|
21
|
+
def index
|
22
|
+
respond_to do |format|
|
23
|
+
format.html { render index_component.new(page: @page) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def new
|
28
|
+
@resource = resource_class.new
|
29
|
+
render new_component.new(@resource)
|
30
|
+
end
|
31
|
+
|
32
|
+
def create
|
33
|
+
@resource = resource_class.new(permitted_resource_params)
|
34
|
+
|
35
|
+
if @resource.save
|
36
|
+
flash[:notice] = t('.success')
|
37
|
+
redirect_to after_create_path, status: :see_other
|
38
|
+
else
|
39
|
+
page_component = new_component.new(@resource)
|
40
|
+
render_resource_form_with_errors(page_component)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def edit
|
45
|
+
render edit_component.new(@resource)
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
if @resource.update(permitted_resource_params)
|
50
|
+
flash[:notice] = t('.success')
|
51
|
+
redirect_to after_update_path, status: :see_other
|
52
|
+
else
|
53
|
+
page_component = edit_component.new(@resource)
|
54
|
+
render_resource_form_with_errors(page_component)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def destroy
|
59
|
+
@resource = resource_class.where(id: params[:id])
|
60
|
+
|
61
|
+
resource_class.transaction { @resource.destroy_all }
|
62
|
+
|
63
|
+
flash[:notice] = t('.success')
|
64
|
+
redirect_back_or_to after_destroy_path, status: :see_other
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def search_filter_params
|
70
|
+
request.params.slice(:q, :page)
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_paginated_resources
|
74
|
+
@resources ||= apply_search_to(
|
75
|
+
resources_collection,
|
76
|
+
param: :q,
|
77
|
+
).tap do |resources|
|
78
|
+
instance_variable_set("@#{plural_resource_name}", resources)
|
79
|
+
# sets @page instance variable in geared_pagination gem
|
80
|
+
set_page_and_extract_portion_from(resources, ordered_by: resources_sorting_options)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def resources_sorting_options
|
85
|
+
{ id: :desc }
|
86
|
+
end
|
87
|
+
|
88
|
+
def resources_collection
|
89
|
+
resource_class.all
|
90
|
+
end
|
91
|
+
|
92
|
+
def set_resource
|
93
|
+
@resource ||= resource_class.find(params[:id]).tap do |resource|
|
94
|
+
instance_variable_set("@#{resource_name}", resource)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def resource_class
|
99
|
+
raise NotImplementedError,
|
100
|
+
"You must implement the resource_class method in #{self.class}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def resource_name
|
104
|
+
resource_class.model_name.singular_route_key
|
105
|
+
end
|
106
|
+
|
107
|
+
def plural_resource_name
|
108
|
+
resource_class.model_name.route_key
|
109
|
+
end
|
110
|
+
|
111
|
+
def index_component
|
112
|
+
component("#{plural_resource_name}/index")
|
113
|
+
end
|
114
|
+
|
115
|
+
def new_component
|
116
|
+
component("#{plural_resource_name}/new")
|
117
|
+
end
|
118
|
+
|
119
|
+
def edit_component
|
120
|
+
component("#{plural_resource_name}/edit")
|
121
|
+
end
|
122
|
+
|
123
|
+
def render_resource_form_with_errors(page_component)
|
124
|
+
respond_to do |format|
|
125
|
+
format.html do
|
126
|
+
render page_component, status: :unprocessable_entity
|
127
|
+
end
|
128
|
+
format.turbo_stream do
|
129
|
+
render turbo_stream: turbo_stream.replace(:resource_modal, page_component),
|
130
|
+
status: :unprocessable_entity
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def permitted_resource_params
|
136
|
+
raise NotImplementedError,
|
137
|
+
"You must implement the permitted_resource_params method in #{self.class}"
|
138
|
+
end
|
139
|
+
|
140
|
+
def after_create_path
|
141
|
+
solidus_admin.send("#{plural_resource_name}_path", **search_filter_params)
|
142
|
+
end
|
143
|
+
|
144
|
+
def after_update_path
|
145
|
+
solidus_admin.send("#{plural_resource_name}_path", **search_filter_params)
|
146
|
+
end
|
147
|
+
|
148
|
+
def after_destroy_path
|
149
|
+
solidus_admin.send("#{plural_resource_name}_path", **search_filter_params)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|