solidus_admin 0.3.2 → 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 +13 -1
- 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 +2 -18
- data/app/components/solidus_admin/layout/navigation/component.js +1 -1
- data/app/components/solidus_admin/orders/index/component.rb +2 -2
- data/app/components/solidus_admin/orders/show/address/component.js +2 -2
- 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/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 +9 -5
- 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 +1 -1
- 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/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 +6 -1
- 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/ransack_filter/component.js +18 -16
- 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/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 +27 -11
- data/app/components/solidus_admin/users/store_credits/index/component.rb +18 -10
- 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/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/controllers/solidus_admin/users_controller.rb +1 -9
- 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 -2
- data/lib/solidus_admin/configuration.rb +0 -5
- 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/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
- metadata +35 -6
@@ -1,10 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusAdmin
|
4
|
-
class StockItemsController < SolidusAdmin::
|
4
|
+
class StockItemsController < SolidusAdmin::ResourcesController
|
5
5
|
include SolidusAdmin::ControllerHelpers::Search
|
6
|
-
before_action :load_stock_items, only: [:index, :edit, :update]
|
7
|
-
before_action :load_stock_item, only: [:edit, :update]
|
8
6
|
|
9
7
|
search_scope(:all, default: true) { _1 }
|
10
8
|
search_scope(:back_orderable) { _1.where(backorderable: true) }
|
@@ -18,49 +16,34 @@ module SolidusAdmin
|
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
|
-
def edit
|
22
|
-
respond_to do |format|
|
23
|
-
format.html { render component('stock_items/edit').new(stock_item: @stock_item, page: @page) }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
19
|
def update
|
28
20
|
quantity_adjustment = params[:quantity_adjustment].to_i
|
29
|
-
@stock_item.assign_attributes(
|
21
|
+
@stock_item.assign_attributes(permitted_resource_params)
|
30
22
|
@stock_item.stock_movements.build(quantity: quantity_adjustment, originator: current_solidus_admin_user)
|
31
23
|
|
32
24
|
if @stock_item.save
|
33
|
-
|
34
|
-
format.html { redirect_to solidus_admin.stock_items_path, status: :see_other }
|
35
|
-
format.turbo_stream { render turbo_stream: '<turbo-stream action="refresh" />' }
|
36
|
-
end
|
25
|
+
redirect_to after_update_path, status: :see_other
|
37
26
|
else
|
38
|
-
|
39
|
-
|
40
|
-
end
|
27
|
+
page_component = edit_component.new(@stock_item)
|
28
|
+
render_resource_form_with_errors(page_component)
|
41
29
|
end
|
42
30
|
end
|
43
31
|
|
44
32
|
private
|
45
33
|
|
46
|
-
def
|
47
|
-
@stock_items = apply_search_to(
|
48
|
-
Spree::StockItem.reorder(nil),
|
49
|
-
param: :q,
|
50
|
-
)
|
34
|
+
def resource_class = Spree::StockItem
|
51
35
|
|
52
|
-
|
36
|
+
def resources_collection = Spree::StockItem.reorder(nil)
|
37
|
+
|
38
|
+
def resources_sorting_options
|
39
|
+
{
|
53
40
|
variant_id: :desc,
|
54
41
|
stock_location_id: :desc,
|
55
42
|
id: :desc,
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def load_stock_item
|
60
|
-
@stock_item = Spree::StockItem.find(params[:id])
|
43
|
+
}
|
61
44
|
end
|
62
45
|
|
63
|
-
def
|
46
|
+
def permitted_resource_params
|
64
47
|
params.require(:stock_item).permit(:backorderable)
|
65
48
|
end
|
66
49
|
end
|
@@ -1,115 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusAdmin
|
4
|
-
class StoreCreditReasonsController < SolidusAdmin::
|
5
|
-
include SolidusAdmin::ControllerHelpers::Search
|
6
|
-
|
7
|
-
before_action :set_store_credit_reason, only: %i[edit update]
|
8
|
-
|
9
|
-
def index
|
10
|
-
set_index_page
|
11
|
-
|
12
|
-
respond_to do |format|
|
13
|
-
format.html { render component('store_credit_reasons/index').new(page: @page) }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def new
|
18
|
-
@store_credit_reason = Spree::StoreCreditReason.new
|
19
|
-
|
20
|
-
set_index_page
|
21
|
-
|
22
|
-
respond_to do |format|
|
23
|
-
format.html { render component('store_credit_reasons/new').new(page: @page, store_credit_reason: @store_credit_reason) }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def create
|
28
|
-
@store_credit_reason = Spree::StoreCreditReason.new(store_credit_reason_params)
|
29
|
-
|
30
|
-
if @store_credit_reason.save
|
31
|
-
respond_to do |format|
|
32
|
-
flash[:notice] = t('.success')
|
33
|
-
|
34
|
-
format.html do
|
35
|
-
redirect_to solidus_admin.store_credit_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('store_credit_reasons/new').new(page: @page, store_credit_reason: @store_credit_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('store_credit_reasons/edit').new(page: @page, store_credit_reason: @store_credit_reason) }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def update
|
63
|
-
if @store_credit_reason.update(store_credit_reason_params)
|
64
|
-
respond_to do |format|
|
65
|
-
flash[:notice] = t('.success')
|
66
|
-
|
67
|
-
format.html do
|
68
|
-
redirect_to solidus_admin.store_credit_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('store_credit_reasons/edit').new(page: @page, store_credit_reason: @store_credit_reason)
|
81
|
-
render page_component, status: :unprocessable_entity
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def destroy
|
88
|
-
@store_credit_reason = Spree::StoreCreditReason.find_by!(id: params[:id])
|
89
|
-
|
90
|
-
Spree::StoreCreditReason.transaction { @store_credit_reason.destroy }
|
91
|
-
|
92
|
-
flash[:notice] = t('.success')
|
93
|
-
redirect_back_or_to store_credit_reasons_path, status: :see_other
|
94
|
-
end
|
95
|
-
|
4
|
+
class StoreCreditReasonsController < SolidusAdmin::ResourcesController
|
96
5
|
private
|
97
6
|
|
98
|
-
def
|
99
|
-
@store_credit_reason = Spree::StoreCreditReason.find(params[:id])
|
100
|
-
end
|
101
|
-
|
102
|
-
def store_credit_reason_params
|
103
|
-
params.require(:store_credit_reason).permit(:name, :active)
|
104
|
-
end
|
7
|
+
def resource_class = Spree::StoreCreditReason
|
105
8
|
|
106
|
-
def
|
107
|
-
store_credit_reasons = apply_search_to(
|
108
|
-
Spree::StoreCreditReason.unscoped.order(id: :desc),
|
109
|
-
param: :q,
|
110
|
-
)
|
9
|
+
def resources_collection = Spree::StoreCreditReason.unscoped
|
111
10
|
|
112
|
-
|
11
|
+
def permitted_resource_params
|
12
|
+
params.require(:store_credit_reason).permit(:name, :active)
|
113
13
|
end
|
114
14
|
end
|
115
15
|
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusAdmin
|
4
|
+
class StoreCreditsController < SolidusAdmin::ResourcesController
|
5
|
+
before_action :set_user
|
6
|
+
before_action :set_store_credit, only: [:show, :edit_amount, :update_amount, :edit_memo, :update_memo, :edit_validity, :invalidate]
|
7
|
+
before_action :set_store_credit_reasons, only: [:edit_amount, :update_amount, :edit_validity, :invalidate]
|
8
|
+
before_action :set_store_credit_events, only: [:show]
|
9
|
+
before_action :set_store_credit_categories, only: [:new]
|
10
|
+
|
11
|
+
def index
|
12
|
+
@store_credits = Spree::StoreCredit.where(user_id: @user.id).order(id: :desc)
|
13
|
+
|
14
|
+
respond_to do |format|
|
15
|
+
format.html { render component("users/store_credits/index").new(user: @user, store_credits: @store_credits) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def show
|
20
|
+
respond_to do |format|
|
21
|
+
format.html { render component("users/store_credits/show").new(user: @user, store_credit: @store_credit, events: @store_credit_events) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def new
|
26
|
+
@store_credit ||= Spree::StoreCredit.new
|
27
|
+
|
28
|
+
respond_to do |format|
|
29
|
+
format.html {
|
30
|
+
render component("users/store_credits/new").new(
|
31
|
+
user: @user,
|
32
|
+
store_credit: @store_credit,
|
33
|
+
categories: @store_credit_categories
|
34
|
+
)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create
|
40
|
+
@store_credit = @user.store_credits.build(
|
41
|
+
permitted_resource_params.merge({
|
42
|
+
created_by: spree_current_user,
|
43
|
+
action_originator: spree_current_user
|
44
|
+
})
|
45
|
+
)
|
46
|
+
|
47
|
+
return unless ensure_amount { render_new_with_errors }
|
48
|
+
return unless ensure_store_credit_category { render_new_with_errors }
|
49
|
+
|
50
|
+
if @store_credit.save
|
51
|
+
flash[:notice] = t('.success')
|
52
|
+
redirect_to after_create_path, status: :see_other
|
53
|
+
else
|
54
|
+
render_new_with_errors
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def edit_amount
|
59
|
+
respond_to do |format|
|
60
|
+
format.html {
|
61
|
+
render component("users/store_credits/edit_amount").new(
|
62
|
+
user: @user,
|
63
|
+
store_credit: @store_credit,
|
64
|
+
reasons: @store_credit_reasons
|
65
|
+
)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def update_amount
|
71
|
+
return unless ensure_amount { render_edit_with_errors }
|
72
|
+
return unless ensure_store_credit_reason { render_edit_with_errors }
|
73
|
+
|
74
|
+
if @store_credit.update_amount(permitted_resource_params[:amount], @store_credit_reason, spree_current_user)
|
75
|
+
flash[:notice] = t('.success')
|
76
|
+
redirect_to after_update_path, status: :see_other
|
77
|
+
else
|
78
|
+
render_edit_with_errors
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def edit_memo
|
83
|
+
respond_to do |format|
|
84
|
+
format.html {
|
85
|
+
render component("users/store_credits/edit_memo").new(
|
86
|
+
user: @user,
|
87
|
+
store_credit: @store_credit,
|
88
|
+
)
|
89
|
+
}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def update_memo
|
94
|
+
if @store_credit.update(memo: permitted_resource_params[:memo])
|
95
|
+
flash[:notice] = t('.success')
|
96
|
+
else
|
97
|
+
# Memo update failures are nearly impossible to trigger due to lack of validation.
|
98
|
+
flash[:error] = t('.failure')
|
99
|
+
end
|
100
|
+
|
101
|
+
redirect_to after_update_path, status: :see_other
|
102
|
+
end
|
103
|
+
|
104
|
+
def edit_validity
|
105
|
+
respond_to do |format|
|
106
|
+
format.html {
|
107
|
+
render component("users/store_credits/edit_validity").new(
|
108
|
+
user: @user,
|
109
|
+
store_credit: @store_credit,
|
110
|
+
reasons: @store_credit_reasons
|
111
|
+
)
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def invalidate
|
117
|
+
return unless ensure_store_credit_reason { render_edit_with_errors }
|
118
|
+
|
119
|
+
if @store_credit.invalidate(@store_credit_reason, spree_current_user)
|
120
|
+
flash[:notice] = t('.success')
|
121
|
+
else
|
122
|
+
# Ensure store_credit_reason handles invalid param/form submissions and modal re-rendering.
|
123
|
+
# This is just a fallback error state in case anything goes wrong with StoreCredit#invalidate.
|
124
|
+
flash[:error] = t('.failure')
|
125
|
+
end
|
126
|
+
|
127
|
+
redirect_to after_update_path, status: :see_other
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def resource_class = Spree::StoreCredit
|
133
|
+
|
134
|
+
def set_store_credit
|
135
|
+
@store_credit ||= Spree::StoreCredit.find(params[:id])
|
136
|
+
end
|
137
|
+
|
138
|
+
def set_user
|
139
|
+
@user = Spree.user_class.find(params[:user_id])
|
140
|
+
end
|
141
|
+
|
142
|
+
def set_store_credit_reasons
|
143
|
+
@store_credit_reasons = Spree::StoreCreditReason.active.order(:name)
|
144
|
+
end
|
145
|
+
|
146
|
+
def set_store_credit_categories
|
147
|
+
@store_credit_categories = Spree::StoreCreditCategory.all.order(:name)
|
148
|
+
end
|
149
|
+
|
150
|
+
def set_store_credit_events
|
151
|
+
@store_credit_events = @store_credit.store_credit_events.chronological
|
152
|
+
end
|
153
|
+
|
154
|
+
def permitted_resource_params
|
155
|
+
permitted_params = [:amount, :currency, :category_id, :memo]
|
156
|
+
permitted_params << :category_id if action_name.to_sym == :create
|
157
|
+
permitted_params << :store_credit_reason_id if [:update_amount, :invalidate].include?(action_name.to_sym)
|
158
|
+
|
159
|
+
params.require(:store_credit).permit(permitted_params).merge(created_by: spree_current_user)
|
160
|
+
end
|
161
|
+
|
162
|
+
def render_new_with_errors
|
163
|
+
set_store_credit_categories
|
164
|
+
|
165
|
+
page_component = component("users/store_credits/new").new(
|
166
|
+
user: @user,
|
167
|
+
store_credit: @store_credit,
|
168
|
+
categories: @store_credit_categories
|
169
|
+
)
|
170
|
+
|
171
|
+
render_resource_form_with_errors(page_component)
|
172
|
+
end
|
173
|
+
|
174
|
+
def render_edit_with_errors
|
175
|
+
set_store_credit_events
|
176
|
+
|
177
|
+
template = if action_name.to_sym == :invalidate
|
178
|
+
"edit_validity"
|
179
|
+
else
|
180
|
+
"edit_amount"
|
181
|
+
end
|
182
|
+
|
183
|
+
page_component = component("users/store_credits/#{template}").new(
|
184
|
+
user: @user,
|
185
|
+
store_credit: @store_credit,
|
186
|
+
reasons: @store_credit_reasons
|
187
|
+
)
|
188
|
+
|
189
|
+
render_resource_form_with_errors(page_component)
|
190
|
+
end
|
191
|
+
|
192
|
+
def ensure_amount
|
193
|
+
if permitted_resource_params[:amount].blank?
|
194
|
+
@store_credit.errors.add(:amount, :greater_than, count: 0, value: permitted_resource_params[:amount])
|
195
|
+
yield if block_given? # Block is for error template rendering on a per-action basis so this can be re-used.
|
196
|
+
return false
|
197
|
+
end
|
198
|
+
true
|
199
|
+
end
|
200
|
+
|
201
|
+
def ensure_store_credit_reason
|
202
|
+
@store_credit_reason = Spree::StoreCreditReason.find_by(id: permitted_resource_params[:store_credit_reason_id])
|
203
|
+
|
204
|
+
if @store_credit_reason.blank?
|
205
|
+
@store_credit.errors.add(:store_credit_reason_id, "Store Credit reason must be provided")
|
206
|
+
yield if block_given? # Block is for error template rendering on a per-action basis so this can be re-used.
|
207
|
+
return false
|
208
|
+
end
|
209
|
+
true
|
210
|
+
end
|
211
|
+
|
212
|
+
def ensure_store_credit_category
|
213
|
+
@store_credit_category = Spree::StoreCreditCategory.find_by(id: permitted_resource_params[:category_id])
|
214
|
+
|
215
|
+
if @store_credit_category.blank?
|
216
|
+
@store_credit.errors.add(:category_id, "Store Credit category must be provided")
|
217
|
+
yield if block_given? # Block is for error template rendering on a per-action basis so this can be re-used.
|
218
|
+
return false
|
219
|
+
end
|
220
|
+
true
|
221
|
+
end
|
222
|
+
|
223
|
+
def after_create_path
|
224
|
+
solidus_admin.user_store_credits_path(@user)
|
225
|
+
end
|
226
|
+
|
227
|
+
def after_update_path
|
228
|
+
solidus_admin.user_store_credit_path(@user, @store_credit)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
@@ -1,119 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SolidusAdmin
|
4
|
-
class TaxCategoriesController < SolidusAdmin::
|
5
|
-
include SolidusAdmin::ControllerHelpers::Search
|
6
|
-
|
7
|
-
before_action :set_tax_category, only: %i[edit update]
|
8
|
-
|
9
|
-
def new
|
10
|
-
@tax_category = Spree::TaxCategory.new
|
11
|
-
|
12
|
-
set_index_page
|
13
|
-
|
14
|
-
respond_to do |format|
|
15
|
-
format.html { render component('tax_categories/new').new(page: @page, tax_category: @tax_category) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def edit
|
20
|
-
@tax_category = Spree::TaxCategory.find(params[:id])
|
21
|
-
|
22
|
-
set_index_page
|
23
|
-
|
24
|
-
respond_to do |format|
|
25
|
-
format.html { render component('tax_categories/edit').new(page: @page, tax_category: @tax_category) }
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def create
|
30
|
-
@tax_category = Spree::TaxCategory.new(tax_category_params)
|
31
|
-
|
32
|
-
if @tax_category.save
|
33
|
-
respond_to do |format|
|
34
|
-
flash[:notice] = t('.success')
|
35
|
-
|
36
|
-
format.html do
|
37
|
-
redirect_to solidus_admin.tax_categories_path, status: :see_other
|
38
|
-
end
|
39
|
-
|
40
|
-
format.turbo_stream do
|
41
|
-
# we need to explicitly write the refresh tag for now.
|
42
|
-
# See https://github.com/hotwired/turbo-rails/issues/579
|
43
|
-
render turbo_stream: '<turbo-stream action="refresh" />'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
else
|
47
|
-
set_index_page
|
48
|
-
|
49
|
-
respond_to do |format|
|
50
|
-
format.html do
|
51
|
-
page_component = component('tax_categories/new').new(page: @page, tax_category: @tax_category)
|
52
|
-
render page_component, status: :unprocessable_entity
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def update
|
59
|
-
if @tax_category.update(tax_category_params)
|
60
|
-
respond_to do |format|
|
61
|
-
flash[:notice] = t('.success')
|
62
|
-
|
63
|
-
format.html do
|
64
|
-
redirect_to solidus_admin.tax_categories_path, status: :see_other
|
65
|
-
end
|
66
|
-
|
67
|
-
format.turbo_stream do
|
68
|
-
render turbo_stream: '<turbo-stream action="refresh" />'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
else
|
72
|
-
set_index_page
|
73
|
-
|
74
|
-
respond_to do |format|
|
75
|
-
format.html do
|
76
|
-
page_component = component('tax_categories/edit').new(page: @page, tax_category: @tax_category)
|
77
|
-
render page_component, status: :unprocessable_entity
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def index
|
84
|
-
set_index_page
|
85
|
-
|
86
|
-
respond_to do |format|
|
87
|
-
format.html { render component('tax_categories/index').new(page: @page) }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def destroy
|
92
|
-
@tax_categories = Spree::TaxCategory.where(id: params[:id])
|
93
|
-
|
94
|
-
Spree::TaxCategory.transaction { @tax_categories.destroy_all }
|
95
|
-
|
96
|
-
flash[:notice] = t('.success')
|
97
|
-
redirect_back_or_to tax_categories_path, status: :see_other
|
98
|
-
end
|
99
|
-
|
4
|
+
class TaxCategoriesController < SolidusAdmin::ResourcesController
|
100
5
|
private
|
101
6
|
|
102
|
-
def
|
103
|
-
@tax_category = Spree::TaxCategory.find(params[:id])
|
104
|
-
end
|
7
|
+
def resource_class = Spree::TaxCategory
|
105
8
|
|
106
|
-
def
|
9
|
+
def permitted_resource_params
|
107
10
|
params.require(:tax_category).permit(:name, :description, :is_default, :tax_code)
|
108
11
|
end
|
109
|
-
|
110
|
-
def set_index_page
|
111
|
-
tax_categories = apply_search_to(
|
112
|
-
Spree::TaxCategory.order(created_at: :desc, id: :desc),
|
113
|
-
param: :q,
|
114
|
-
)
|
115
|
-
|
116
|
-
set_page_and_extract_portion_from(tax_categories)
|
117
|
-
end
|
118
12
|
end
|
119
13
|
end
|
@@ -5,7 +5,7 @@ module SolidusAdmin
|
|
5
5
|
include SolidusAdmin::ControllerHelpers::Search
|
6
6
|
include Spree::Core::ControllerHelpers::StrongParameters
|
7
7
|
|
8
|
-
before_action :set_user, only: [:edit, :addresses, :update_addresses, :orders, :items
|
8
|
+
before_action :set_user, only: [:edit, :addresses, :update_addresses, :orders, :items]
|
9
9
|
|
10
10
|
search_scope(:all, default: true)
|
11
11
|
search_scope(:customers) { _1.left_outer_joins(:role_users).where(role_users: { id: nil }) }
|
@@ -81,14 +81,6 @@ module SolidusAdmin
|
|
81
81
|
redirect_back_or_to users_path, status: :see_other
|
82
82
|
end
|
83
83
|
|
84
|
-
def store_credits
|
85
|
-
@store_credits = Spree::StoreCredit.where(user_id: @user.id).order(id: :desc)
|
86
|
-
|
87
|
-
respond_to do |format|
|
88
|
-
format.html { render component("users/store_credits/index").new(user: @user, store_credits: @store_credits) }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
84
|
private
|
93
85
|
|
94
86
|
def set_user
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusAdmin
|
4
|
+
module VoidElementsHelper
|
5
|
+
# https://github.com/rails/rails/blob/194d697036c61af0caa66de5659721ded2478ce9/actionview/lib/action_view/helpers/tag_helper.rb#L84
|
6
|
+
HTML_VOID_ELEMENTS = %i(area base br col embed hr img input keygen link meta source track wbr)
|
7
|
+
|
8
|
+
# @param element [Symbol]
|
9
|
+
def void_element?(element)
|
10
|
+
HTML_VOID_ELEMENTS.include?(element)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -5,6 +5,9 @@
|
|
5
5
|
|
6
6
|
<title><%= solidus_admin_title %></title>
|
7
7
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
8
|
+
<meta name="turbo-cache-control" content="no-cache">
|
9
|
+
<meta name="turbo-prefetch" content="false">
|
10
|
+
|
8
11
|
<%= csrf_meta_tags %>
|
9
12
|
<%= csp_meta_tag %>
|
10
13
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
en:
|
2
|
+
solidus_admin:
|
3
|
+
store_credits:
|
4
|
+
title: "Store Credits"
|
5
|
+
destroy:
|
6
|
+
success: "Store credit was successfully removed."
|
7
|
+
create:
|
8
|
+
success: "Store credit was successfully created."
|
9
|
+
update_amount:
|
10
|
+
success: "Store credit was successfully updated."
|
11
|
+
update_memo:
|
12
|
+
success: "Store credit was successfully updated."
|
13
|
+
failure: "Something went wrong. Store credit could not be updated."
|
14
|
+
invalidate:
|
15
|
+
success: "Store credit was successfully invalidated."
|
16
|
+
failure: "Something went wrong. Store credit could not be invalidated."
|
data/config/routes.rb
CHANGED
@@ -51,12 +51,22 @@ SolidusAdmin::Engine.routes.draw do
|
|
51
51
|
put :update_addresses
|
52
52
|
get :orders
|
53
53
|
get :items
|
54
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
resources :store_credits, only: [:index, :show, :new, :create], controller: "store_credits" do
|
57
|
+
member do
|
58
|
+
get :edit_amount
|
59
|
+
put :update_amount
|
60
|
+
get :edit_memo
|
61
|
+
put :update_memo
|
62
|
+
get :edit_validity
|
63
|
+
put :invalidate
|
64
|
+
end
|
55
65
|
end
|
56
66
|
end
|
57
67
|
|
58
68
|
admin_resources :promotions, only: [:index, :destroy]
|
59
|
-
admin_resources :properties,
|
69
|
+
admin_resources :properties, except: [:show]
|
60
70
|
admin_resources :option_types, only: [:index, :destroy], sortable: true
|
61
71
|
admin_resources :taxonomies, only: [:index, :destroy], sortable: true
|
62
72
|
admin_resources :promotion_categories, only: [:index, :destroy]
|
data/lib/solidus_admin/engine.rb
CHANGED
@@ -63,5 +63,11 @@ module SolidusAdmin
|
|
63
63
|
SolidusAdmin::Engine.root.join("app/components"),
|
64
64
|
]
|
65
65
|
end
|
66
|
+
|
67
|
+
initializer "solidus_admin.routing_proxies" do |app|
|
68
|
+
ActiveSupport.on_load(:after_routes_loaded) do
|
69
|
+
SolidusAdmin::BaseComponent.include app.routes.mounted_helpers
|
70
|
+
end
|
71
|
+
end
|
66
72
|
end
|
67
73
|
end
|
@@ -8,7 +8,7 @@ input_path = "app/assets/stylesheets/solidus_admin/application.tailwind.css"
|
|
8
8
|
output_path = "app/assets/builds/solidus_admin/tailwind.css"
|
9
9
|
|
10
10
|
unless bundle_command "show tailwindcss-rails"
|
11
|
-
bundle_command "add tailwindcss-rails"
|
11
|
+
bundle_command "add tailwindcss-rails --version '~>3.0'"
|
12
12
|
end
|
13
13
|
|
14
14
|
# Copy the Tailwind CSS main file.
|