spree_backend 4.6.0 → 4.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +20 -101
- data/.codeclimate.yml +1 -1
- data/.rubocop.yml +5 -2
- data/Gemfile +9 -13
- data/app/assets/javascripts/spree/backend/stock_transfer.js +1 -1
- data/app/controllers/concerns/spree/admin/translatable.rb +10 -7
- data/app/controllers/spree/admin/products_controller.rb +22 -0
- data/app/helpers/spree/admin/navigation_helper.rb +77 -11
- data/app/helpers/spree/admin/orders_helper.rb +0 -18
- data/app/models/spree/admin/actions/action.rb +48 -0
- data/app/models/spree/admin/actions/action_builder.rb +79 -0
- data/app/models/spree/admin/actions/action_style.rb +11 -0
- data/app/models/spree/admin/actions/adjustments_default_actions_builder.rb +28 -0
- data/app/models/spree/admin/actions/images_default_actions_builder.rb +29 -0
- data/app/models/spree/admin/actions/order_default_actions_builder.rb +92 -0
- data/app/models/spree/admin/actions/orders_default_actions_builder.rb +29 -0
- data/app/models/spree/admin/actions/payments_default_actions_builder.rb +33 -0
- data/app/models/spree/admin/actions/product_properties_default_actions_builder.rb +42 -0
- data/app/models/spree/admin/actions/products_default_actions_builder.rb +29 -0
- data/app/models/spree/admin/actions/root.rb +15 -0
- data/app/models/spree/admin/actions/store_credits_default_actions_builder.rb +28 -0
- data/app/models/spree/admin/actions/user_default_actions_builder.rb +29 -0
- data/app/models/spree/admin/actions/users_default_actions_builder.rb +29 -0
- data/app/models/spree/admin/actions/variants_default_actions_builder.rb +30 -0
- data/app/models/spree/admin/item_manager.rb +50 -0
- data/app/models/spree/admin/main_menu/default_configuration_builder.rb +263 -0
- data/app/models/spree/admin/main_menu/item.rb +30 -0
- data/app/models/spree/admin/main_menu/item_builder.rb +37 -0
- data/app/models/spree/admin/main_menu/root.rb +17 -0
- data/app/models/spree/admin/main_menu/section.rb +31 -0
- data/app/models/spree/admin/main_menu/section_builder.rb +36 -0
- data/app/models/spree/admin/permission_checks.rb +50 -0
- data/app/models/spree/admin/tabs/order_default_tabs_builder.rb +147 -0
- data/app/models/spree/admin/tabs/product_default_tabs_builder.rb +144 -0
- data/app/models/spree/admin/tabs/root.rb +15 -0
- data/app/models/spree/admin/tabs/tab.rb +38 -0
- data/app/models/spree/admin/tabs/tab_builder.rb +63 -0
- data/app/models/spree/admin/tabs/user_default_tabs_builder.rb +77 -0
- data/app/views/spree/admin/adjustments/index.html.erb +9 -1
- data/app/views/spree/admin/cms_sections/types/_image_gallery.html.erb +27 -33
- data/app/views/spree/admin/cms_sections/types/_side_by_side_images.html.erb +18 -22
- data/app/views/spree/admin/dashboard/_getting_started.html.erb +1 -0
- data/app/views/spree/admin/images/index.html.erb +12 -3
- data/app/views/spree/admin/oauth_applications/index.html.erb +7 -0
- data/app/views/spree/admin/orders/_order_actions.html.erb +10 -15
- data/app/views/spree/admin/orders/index.html.erb +11 -6
- data/app/views/spree/admin/payments/index.html.erb +9 -4
- data/app/views/spree/admin/prices/index.html.erb +12 -2
- data/app/views/spree/admin/product_properties/index.html.erb +13 -13
- data/app/views/spree/admin/products/_add_stock_form.html.erb +12 -1
- data/app/views/spree/admin/products/edit.html.erb +12 -1
- data/app/views/spree/admin/products/index.html.erb +11 -2
- data/app/views/spree/admin/shared/_main_menu.html.erb +19 -77
- data/app/views/spree/admin/shared/_order_tabs.html.erb +10 -83
- data/app/views/spree/admin/shared/_product_tabs.html.erb +12 -64
- data/app/views/spree/admin/store_credits/index.html.erb +9 -1
- data/app/views/spree/admin/users/_tabs.html.erb +11 -30
- data/app/views/spree/admin/users/_user_page_actions.html.erb +9 -1
- data/app/views/spree/admin/users/index.html.erb +11 -2
- data/app/views/spree/admin/variants/index.html.erb +12 -2
- data/config/locales/en.yml +10 -5
- data/lib/spree/backend/configuration.rb +0 -17
- data/lib/spree/backend/engine.rb +28 -1
- data/lib/spree/backend/version.rb +1 -1
- data/spree_backend.gemspec +2 -2
- data/yarn.lock +58 -22
- metadata +36 -17
- data/app/views/spree/admin/shared/sub_menu/_apps.html.erb +0 -3
- data/app/views/spree/admin/shared/sub_menu/_configuration.html.erb +0 -19
- data/app/views/spree/admin/shared/sub_menu/_content.html.erb +0 -4
- data/app/views/spree/admin/shared/sub_menu/_integrations.html.erb +0 -5
- data/app/views/spree/admin/shared/sub_menu/_orders.html.erb +0 -5
- data/app/views/spree/admin/shared/sub_menu/_organizations.html.erb +0 -3
- data/app/views/spree/admin/shared/sub_menu/_product.html.erb +0 -8
- data/app/views/spree/admin/shared/sub_menu/_promotion.html.erb +0 -4
- data/app/views/spree/admin/shared/sub_menu/_returns.html.erb +0 -4
- data/app/views/spree/admin/shared/sub_menu/_stock.html.erb +0 -4
@@ -0,0 +1,263 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module MainMenu
|
4
|
+
# rubocop:disable Metrics/ClassLength
|
5
|
+
class DefaultConfigurationBuilder
|
6
|
+
include Spree::Core::Engine.routes.url_helpers
|
7
|
+
|
8
|
+
def build
|
9
|
+
root = Root.new
|
10
|
+
add_dashboard_item(root)
|
11
|
+
add_orders_section(root)
|
12
|
+
add_returns_section(root)
|
13
|
+
add_products_section(root)
|
14
|
+
add_stocks_section(root)
|
15
|
+
add_reports_item(root)
|
16
|
+
add_promotions_section(root)
|
17
|
+
add_users_item(root)
|
18
|
+
add_content_section(root)
|
19
|
+
add_integrations_section(root)
|
20
|
+
add_oauth_section(root)
|
21
|
+
add_settings_section(root)
|
22
|
+
root
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def add_dashboard_item(root)
|
28
|
+
root.add(ItemBuilder.new('dashboard', admin_dashboard_path).
|
29
|
+
with_label_translation_key('admin.home').
|
30
|
+
with_icon_key('house-door-fill.svg').
|
31
|
+
with_match_path('/dashboard').
|
32
|
+
build)
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_orders_section(root)
|
36
|
+
items = [
|
37
|
+
ItemBuilder.new('completed', admin_orders_path(q: { completed_at_not_null: '1' })).
|
38
|
+
with_label_translation_key('admin.orders.all_orders').
|
39
|
+
with_match_path(/completed_at_not_null%5D=1/).
|
40
|
+
build,
|
41
|
+
ItemBuilder.new('draft_orders', admin_orders_path(q: { completed_at_not_null: false, state_eq: :cart })).
|
42
|
+
with_label_translation_key('admin.orders.draft_orders').
|
43
|
+
with_match_path(/cart/).
|
44
|
+
build,
|
45
|
+
ItemBuilder.new('abandoned_checkouts', admin_orders_path(
|
46
|
+
q: { completed_at_not_null: false, state_in: %i[address delivery payment confirm] }
|
47
|
+
)).
|
48
|
+
with_label_translation_key('admin.orders.abandoned_checkouts').
|
49
|
+
with_match_path(/state_in/).
|
50
|
+
build
|
51
|
+
]
|
52
|
+
|
53
|
+
section = SectionBuilder.new('orders', 'inbox-fill.svg').
|
54
|
+
with_admin_ability_check(Spree::Order).
|
55
|
+
with_items(items).
|
56
|
+
build
|
57
|
+
root.add(section)
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_returns_section(root)
|
61
|
+
items = [
|
62
|
+
ItemBuilder.new('return_authorizations', admin_return_authorizations_path).
|
63
|
+
with_manage_ability_check(Spree::ReturnAuthorization).
|
64
|
+
with_match_path('/return_authorizations').
|
65
|
+
build,
|
66
|
+
ItemBuilder.new('customer_returns', admin_customer_returns_path).
|
67
|
+
with_manage_ability_check(Spree::CustomerReturn).
|
68
|
+
with_match_path('/customer_returns').
|
69
|
+
build
|
70
|
+
]
|
71
|
+
|
72
|
+
section = SectionBuilder.new('returns', 'reply-fill.svg').
|
73
|
+
with_manage_ability_check(Spree::ReturnAuthorization, Spree::CustomerReturn).
|
74
|
+
with_items(items).
|
75
|
+
build
|
76
|
+
root.add(section)
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_products_section(root)
|
80
|
+
items = [
|
81
|
+
ItemBuilder.new('products', admin_products_path).with_match_path('/products').build,
|
82
|
+
ItemBuilder.new('option_types', admin_option_types_path).
|
83
|
+
with_admin_ability_check(Spree::OptionType).
|
84
|
+
with_match_path('/option_types').
|
85
|
+
build,
|
86
|
+
ItemBuilder.new('properties', admin_properties_path).
|
87
|
+
with_admin_ability_check(Spree::Property).
|
88
|
+
build,
|
89
|
+
ItemBuilder.new('prototypes', admin_prototypes_path).
|
90
|
+
with_admin_ability_check(Spree::Prototype).
|
91
|
+
build,
|
92
|
+
ItemBuilder.new('taxonomies', admin_taxonomies_path).
|
93
|
+
with_admin_ability_check(Spree::Taxonomy).
|
94
|
+
with_match_path('/taxonomies').
|
95
|
+
build,
|
96
|
+
ItemBuilder.new('taxons', admin_taxons_path).
|
97
|
+
with_admin_ability_check(Spree::Taxon).
|
98
|
+
with_match_path('/taxons').
|
99
|
+
build
|
100
|
+
]
|
101
|
+
|
102
|
+
section = SectionBuilder.new('products', 'tags-fill.svg').
|
103
|
+
with_admin_ability_check(Spree::Product).
|
104
|
+
with_items(items).
|
105
|
+
build
|
106
|
+
root.add(section)
|
107
|
+
end
|
108
|
+
|
109
|
+
def add_stocks_section(root)
|
110
|
+
items = [
|
111
|
+
ItemBuilder.new('stock_transfers', admin_stock_transfers_path).
|
112
|
+
with_manage_ability_check(Spree::StockTransfer).
|
113
|
+
build,
|
114
|
+
ItemBuilder.new('stock_locations', admin_stock_locations_path).
|
115
|
+
with_manage_ability_check(Spree::StockLocation).
|
116
|
+
build
|
117
|
+
]
|
118
|
+
|
119
|
+
section = SectionBuilder.new('stocks', 'box-seam.svg').
|
120
|
+
with_manage_ability_check(Spree::StockLocation, Spree::StockTransfer).
|
121
|
+
with_label_translation_key('admin.tab.stock').
|
122
|
+
with_items(items).
|
123
|
+
build
|
124
|
+
root.add(section)
|
125
|
+
end
|
126
|
+
|
127
|
+
def add_reports_item(root)
|
128
|
+
root.add(ItemBuilder.new('reports', admin_reports_path).
|
129
|
+
with_icon_key('pie-chart-fill.svg').
|
130
|
+
with_admin_ability_check(Spree::Admin::ReportsController).
|
131
|
+
build)
|
132
|
+
end
|
133
|
+
|
134
|
+
def add_promotions_section(root)
|
135
|
+
items = [
|
136
|
+
ItemBuilder.new('promotions', admin_promotions_path).build,
|
137
|
+
ItemBuilder.new('promotion_categories', admin_promotion_categories_path).
|
138
|
+
with_admin_ability_check(Spree::PromotionCategory).
|
139
|
+
with_label_translation_key('admin.tab.promotion_categories').
|
140
|
+
build
|
141
|
+
]
|
142
|
+
|
143
|
+
section = SectionBuilder.new('promotions', 'percent.svg').
|
144
|
+
with_admin_ability_check(Spree::Promotion).
|
145
|
+
with_items(items).
|
146
|
+
build
|
147
|
+
root.add(section)
|
148
|
+
end
|
149
|
+
|
150
|
+
def add_users_item(root)
|
151
|
+
root.add(ItemBuilder.new('users', admin_users_path).
|
152
|
+
with_icon_key('people-fill.svg').
|
153
|
+
with_availability_check(->(ability, _store) { Spree.user_class && ability.can?(:admin, Spree.user_class) }).
|
154
|
+
build)
|
155
|
+
end
|
156
|
+
|
157
|
+
def add_content_section(root)
|
158
|
+
items = [
|
159
|
+
ItemBuilder.new('menus', admin_menus_path).
|
160
|
+
with_label_translation_key('admin.tab.navigation').
|
161
|
+
with_admin_ability_check(Spree::Menu).
|
162
|
+
with_match_path('/menus').
|
163
|
+
build,
|
164
|
+
ItemBuilder.new('cms_pages', admin_cms_pages_path).
|
165
|
+
with_label_translation_key('admin.tab.pages').
|
166
|
+
with_admin_ability_check(Spree::CmsPage).
|
167
|
+
with_match_path('/cms_pages').
|
168
|
+
build
|
169
|
+
]
|
170
|
+
|
171
|
+
section = SectionBuilder.new('content', 'card-heading.svg').
|
172
|
+
with_admin_ability_check(Spree::Menu).
|
173
|
+
with_label_translation_key('admin.tab.content').
|
174
|
+
with_items(items).
|
175
|
+
build
|
176
|
+
root.add(section)
|
177
|
+
end
|
178
|
+
|
179
|
+
def add_integrations_section(root)
|
180
|
+
items = [
|
181
|
+
ItemBuilder.new('payment_methods', admin_payment_methods_path).
|
182
|
+
with_manage_ability_check(Spree::PaymentMethod).
|
183
|
+
with_match_path('/payment_methods').
|
184
|
+
build,
|
185
|
+
ItemBuilder.new('data_feeds', admin_data_feeds_path).
|
186
|
+
with_manage_ability_check(Spree::DataFeed).
|
187
|
+
with_label_translation_key('admin.data_feeds.data_feeds').
|
188
|
+
with_match_path('/data_feeds').
|
189
|
+
build,
|
190
|
+
ItemBuilder.new('webhook_subscribers', admin_webhooks_subscribers_path).
|
191
|
+
with_manage_ability_check(Spree::Webhooks::Subscriber).
|
192
|
+
with_label_translation_key('admin.tab.webhook_subscribers').
|
193
|
+
with_match_path('/webhooks_subscribers').
|
194
|
+
build
|
195
|
+
]
|
196
|
+
|
197
|
+
section = SectionBuilder.new('integrations', 'stack.svg').
|
198
|
+
with_manage_ability_check(Spree::Webhooks::Subscriber, Spree::PaymentMethod, Spree::DataFeed).
|
199
|
+
with_label_translation_key('admin.tab.integrations').
|
200
|
+
with_items(items).
|
201
|
+
build
|
202
|
+
root.add(section)
|
203
|
+
end
|
204
|
+
|
205
|
+
def add_oauth_section(root)
|
206
|
+
section = SectionBuilder.new('oauth', 'terminal-fill.svg').
|
207
|
+
with_admin_ability_check(Spree::OauthApplication).
|
208
|
+
with_label_translation_key('admin.tab.apps').
|
209
|
+
with_item(ItemBuilder.new('oauth_applications', admin_oauth_applications_path).
|
210
|
+
with_label_translation_key('admin.oauth_applications.list').
|
211
|
+
with_match_path('/oauth_applications').
|
212
|
+
build).
|
213
|
+
build
|
214
|
+
root.add(section)
|
215
|
+
end
|
216
|
+
|
217
|
+
# rubocop:disable Metrics/AbcSize
|
218
|
+
def add_settings_section(root)
|
219
|
+
items = [
|
220
|
+
ItemBuilder.new('store', ->(store) { edit_admin_store_path(store) }).build,
|
221
|
+
ItemBuilder.new('tax_categories', admin_tax_categories_path).
|
222
|
+
with_manage_ability_check(Spree::TaxCategory).
|
223
|
+
build,
|
224
|
+
ItemBuilder.new('tax_rates', admin_tax_rates_path).with_manage_ability_check(Spree::TaxRate).build,
|
225
|
+
ItemBuilder.new('zones', admin_zones_path).with_manage_ability_check(Spree::Zone).build,
|
226
|
+
ItemBuilder.new('country', admin_countries_path).with_manage_ability_check(Spree::Country).build,
|
227
|
+
ItemBuilder.new('states', ->(store) { admin_country_states_path(store.default_country) }).
|
228
|
+
with_manage_ability_check(->(ability, store) { store.default_country && ability.can?(:manage, Spree::Country) }).
|
229
|
+
build,
|
230
|
+
ItemBuilder.new('shipping_methods', admin_shipping_methods_path).
|
231
|
+
with_manage_ability_check(Spree::ShippingMethod).
|
232
|
+
build,
|
233
|
+
ItemBuilder.new('shipping_categories', admin_shipping_categories_path).
|
234
|
+
with_manage_ability_check(Spree::ShippingCategory).
|
235
|
+
build,
|
236
|
+
ItemBuilder.new('store_credit_categories', admin_store_credit_categories_path).
|
237
|
+
with_manage_ability_check(Spree::StoreCreditCategory).
|
238
|
+
build,
|
239
|
+
ItemBuilder.new('refund_reasons', admin_refund_reasons_path).
|
240
|
+
with_manage_ability_check(Spree::RefundReason).
|
241
|
+
build,
|
242
|
+
ItemBuilder.new('reimbursement_types', admin_reimbursement_types_path).
|
243
|
+
with_manage_ability_check(Spree::ReimbursementType).
|
244
|
+
build,
|
245
|
+
ItemBuilder.new('return_authorization_reasons', admin_return_authorization_reasons_path).
|
246
|
+
with_manage_ability_check(Spree::ReturnAuthorizationReason).
|
247
|
+
build,
|
248
|
+
ItemBuilder.new('roles', admin_roles_path).with_manage_ability_check(Spree::Role).build
|
249
|
+
]
|
250
|
+
|
251
|
+
section = SectionBuilder.new('settings', 'gear-fill.svg').
|
252
|
+
with_availability_check(->(ability, store) { ability.can?(:manage, store) }).
|
253
|
+
with_label_translation_key('admin.settings').
|
254
|
+
with_items(items).
|
255
|
+
build
|
256
|
+
root.add(section)
|
257
|
+
end
|
258
|
+
# rubocop:enable Metrics/AbcSize
|
259
|
+
end
|
260
|
+
# rubocop:enable Metrics/ClassLength
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module MainMenu
|
4
|
+
class Item
|
5
|
+
attr_reader :key, :label_translation_key, :icon_key, :url, :match_path
|
6
|
+
|
7
|
+
def initialize(key, label_translation_key, url, icon_key, availability_checks, match_path) # rubocop:disable Metrics/ParameterLists
|
8
|
+
@key = key
|
9
|
+
@label_translation_key = label_translation_key
|
10
|
+
@url = url
|
11
|
+
@icon_key = icon_key
|
12
|
+
@availability_checks = availability_checks
|
13
|
+
@match_path = match_path
|
14
|
+
end
|
15
|
+
|
16
|
+
def available?(current_ability, resource)
|
17
|
+
return true if @availability_checks.empty?
|
18
|
+
|
19
|
+
result = @availability_checks.map { |check| check.call(current_ability, resource) }
|
20
|
+
|
21
|
+
result.all?(true)
|
22
|
+
end
|
23
|
+
|
24
|
+
def children?
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module MainMenu
|
4
|
+
class ItemBuilder
|
5
|
+
include ::Spree::Admin::PermissionChecks
|
6
|
+
|
7
|
+
def initialize(key, url)
|
8
|
+
@key = key
|
9
|
+
@label_translation_key = key
|
10
|
+
@url = url
|
11
|
+
@icon_key = nil
|
12
|
+
@availability_checks = []
|
13
|
+
@match_path = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_label_translation_key(key)
|
17
|
+
@label_translation_key = key
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def with_icon_key(icon_key)
|
22
|
+
@icon_key = icon_key
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def with_match_path(match_path)
|
27
|
+
@match_path = match_path
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def build
|
32
|
+
Item.new(@key, @label_translation_key, @url, @icon_key, @availability_checks, @match_path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module MainMenu
|
4
|
+
class Root < Section
|
5
|
+
attr_reader :items
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super('root', 'root', nil, [], [])
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_to_section(section_key, item)
|
12
|
+
@items.find { |e| e.key == section_key }.add(item)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module MainMenu
|
4
|
+
class Section
|
5
|
+
include ::Spree::Admin::ItemManager
|
6
|
+
|
7
|
+
attr_reader :key, :label_translation_key, :icon_key, :items
|
8
|
+
|
9
|
+
def initialize(key, label_translation_key, icon_key, availability_checks, items)
|
10
|
+
@key = key
|
11
|
+
@label_translation_key = label_translation_key
|
12
|
+
@icon_key = icon_key
|
13
|
+
@availability_checks = availability_checks
|
14
|
+
@items = items
|
15
|
+
end
|
16
|
+
|
17
|
+
def available?(current_ability, resource)
|
18
|
+
return true if @availability_checks.empty?
|
19
|
+
|
20
|
+
result = @availability_checks.map { |check| check.call(current_ability, resource) }
|
21
|
+
|
22
|
+
result.all?(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def children?
|
26
|
+
@items.any?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module MainMenu
|
4
|
+
class SectionBuilder
|
5
|
+
include ::Spree::Admin::PermissionChecks
|
6
|
+
|
7
|
+
def initialize(key, icon_key)
|
8
|
+
@key = key
|
9
|
+
@label_translation_key = key
|
10
|
+
@icon_key = icon_key
|
11
|
+
@availability_checks = []
|
12
|
+
@items = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def with_label_translation_key(key)
|
16
|
+
@label_translation_key = key
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def with_item(item)
|
21
|
+
@items << item
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def with_items(items)
|
26
|
+
@items += items
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
def build
|
31
|
+
Section.new(@key, @label_translation_key, @icon_key, @availability_checks, @items)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module PermissionChecks
|
4
|
+
def with_availability_check(availability_check)
|
5
|
+
@availability_checks << availability_check
|
6
|
+
self
|
7
|
+
end
|
8
|
+
|
9
|
+
def with_manage_ability_check(*classes)
|
10
|
+
@availability_checks << ->(ability, _current) { classes.any? { |c| ability.can?(:manage, c) } }
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_admin_ability_check(*classes)
|
15
|
+
@availability_checks << ->(ability, _current) { classes.any? { |c| ability.can?(:admin, c) } }
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def with_index_ability_check(*classes)
|
20
|
+
@availability_checks << ->(ability, _current) { classes.any? { |c| ability.can?(:index, c) } }
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def with_create_ability_check(*classes)
|
25
|
+
@availability_checks << ->(ability, _current) { classes.any? { |c| ability.can?(:create, c) } }
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def with_update_ability_check
|
30
|
+
@availability_checks << ->(ability, resource) { ability.can?(:update, resource) }
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def with_resend_ability_check
|
35
|
+
@availability_checks << ->(ability, resource) { ability.can?(:resend, resource) }
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def with_fire_ability_check
|
40
|
+
@availability_checks << ->(ability, resource) { ability.can?(:fire, resource) }
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def with_state_change_check(event)
|
45
|
+
@availability_checks << ->(_ability, resource) { resource.send("can_#{event}?") }
|
46
|
+
self
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
module Tabs
|
4
|
+
# rubocop:disable Metrics/ClassLength
|
5
|
+
class OrderDefaultTabsBuilder
|
6
|
+
include Spree::Core::Engine.routes.url_helpers
|
7
|
+
|
8
|
+
def build
|
9
|
+
root = Root.new
|
10
|
+
add_cart_tab(root)
|
11
|
+
add_channel_tab(root)
|
12
|
+
add_customer_tab(root)
|
13
|
+
add_shipments_tab(root)
|
14
|
+
add_adjustments_tab(root)
|
15
|
+
add_payments_tab(root)
|
16
|
+
add_return_authorizations_tab(root)
|
17
|
+
add_customer_returns_tab(root)
|
18
|
+
add_state_changes_tab(root)
|
19
|
+
root
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def add_cart_tab(root)
|
25
|
+
tab =
|
26
|
+
TabBuilder.new('cart', ->(resource) { cart_admin_order_path(resource) }).
|
27
|
+
with_icon_key('cart-check.svg').
|
28
|
+
with_active_check.
|
29
|
+
with_availability_check(
|
30
|
+
# An abstract module should not be aware of resource's internal structure.
|
31
|
+
# If these checks are elaborate, it's better to have this complexity declared explicitly here.
|
32
|
+
lambda do |ability, resource|
|
33
|
+
ability.can?(:update, resource) && (resource.shipments.empty? || resource.shipments.shipped.empty?)
|
34
|
+
end
|
35
|
+
).
|
36
|
+
with_data_hook('admin_order_tabs_cart_details').
|
37
|
+
build
|
38
|
+
|
39
|
+
root.add(tab)
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_channel_tab(root)
|
43
|
+
tab =
|
44
|
+
TabBuilder.new('channel', ->(resource) { channel_admin_order_path(resource) }).
|
45
|
+
with_icon_key('funnel.svg').
|
46
|
+
with_active_check.
|
47
|
+
with_update_ability_check.
|
48
|
+
with_data_hook('admin_order_tabs_channel_details').
|
49
|
+
build
|
50
|
+
|
51
|
+
root.add(tab)
|
52
|
+
end
|
53
|
+
|
54
|
+
def add_customer_tab(root)
|
55
|
+
tab =
|
56
|
+
TabBuilder.new('customer', ->(resource) { admin_order_customer_path(resource) }).
|
57
|
+
with_icon_key('person-lines-fill.svg').
|
58
|
+
with_partial_name('customer_details').
|
59
|
+
with_active_check.
|
60
|
+
with_availability_check(
|
61
|
+
lambda do |ability, resource|
|
62
|
+
ability.can?(:update, resource) && resource.checkout_steps.include?('address')
|
63
|
+
end
|
64
|
+
).
|
65
|
+
with_data_hook('admin_order_tabs_customer_details').
|
66
|
+
build
|
67
|
+
|
68
|
+
root.add(tab)
|
69
|
+
end
|
70
|
+
|
71
|
+
def add_shipments_tab(root)
|
72
|
+
tab =
|
73
|
+
TabBuilder.new('shipments', ->(resource) { edit_admin_order_path(resource) }).
|
74
|
+
with_icon_key('truck.svg').
|
75
|
+
with_active_check.
|
76
|
+
with_update_ability_check.
|
77
|
+
with_data_hook('admin_order_tabs_shipment_details').
|
78
|
+
build
|
79
|
+
|
80
|
+
root.add(tab)
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_adjustments_tab(root)
|
84
|
+
tab =
|
85
|
+
TabBuilder.new('adjustments', ->(resource) { admin_order_adjustments_path(resource) }).
|
86
|
+
with_icon_key('adjust.svg').
|
87
|
+
with_active_check.
|
88
|
+
with_index_ability_check(::Spree::Adjustment).
|
89
|
+
with_data_hook('admin_order_tabs_adjustments').
|
90
|
+
build
|
91
|
+
|
92
|
+
root.add(tab)
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_payments_tab(root)
|
96
|
+
tab =
|
97
|
+
TabBuilder.new('payments', ->(resource) { admin_order_payments_path(resource) }).
|
98
|
+
with_icon_key('credit-card.svg').
|
99
|
+
with_active_check.
|
100
|
+
with_index_ability_check(::Spree::Payment).
|
101
|
+
with_data_hook('admin_order_tabs_payments').
|
102
|
+
build
|
103
|
+
|
104
|
+
root.add(tab)
|
105
|
+
end
|
106
|
+
|
107
|
+
def add_return_authorizations_tab(root)
|
108
|
+
tab =
|
109
|
+
TabBuilder.new('return_authorizations', ->(resource) { admin_order_return_authorizations_path(resource) }).
|
110
|
+
with_icon_key('enter.svg').
|
111
|
+
with_active_check.
|
112
|
+
with_completed_check.
|
113
|
+
with_index_ability_check(::Spree::ReturnAuthorization).
|
114
|
+
with_data_hook('admin_order_tabs_return_authorizations').
|
115
|
+
build
|
116
|
+
|
117
|
+
root.add(tab)
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_customer_returns_tab(root)
|
121
|
+
tab =
|
122
|
+
TabBuilder.new('customer_returns', ->(resource) { admin_order_customer_returns_path(resource) }).
|
123
|
+
with_icon_key('returns.svg').
|
124
|
+
with_active_check.
|
125
|
+
with_completed_check.
|
126
|
+
with_index_ability_check(::Spree::CustomerReturn).
|
127
|
+
build
|
128
|
+
|
129
|
+
root.add(tab)
|
130
|
+
end
|
131
|
+
|
132
|
+
def add_state_changes_tab(root)
|
133
|
+
tab =
|
134
|
+
TabBuilder.new('state_changes', ->(resource) { admin_order_state_changes_path(resource) }).
|
135
|
+
with_icon_key('calendar3.svg').
|
136
|
+
with_active_check.
|
137
|
+
with_update_ability_check.
|
138
|
+
with_data_hook('admin_order_tabs_state_changes').
|
139
|
+
build
|
140
|
+
|
141
|
+
root.add(tab)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
# rubocop:enable Metrics/ClassLength
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|