solidus_admin 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -6
  3. data/Rakefile +1 -0
  4. data/app/assets/builds/solidus_admin/tailwind.css +198 -163
  5. data/app/assets/stylesheets/solidus_admin/dark.css +1 -0
  6. data/app/assets/stylesheets/solidus_admin/dimmed.css +1 -0
  7. data/app/components/solidus_admin/adjustment_reasons/edit/component.html.erb +27 -0
  8. data/app/components/solidus_admin/adjustment_reasons/edit/component.rb +12 -0
  9. data/app/components/solidus_admin/adjustment_reasons/edit/component.yml +8 -0
  10. data/app/components/solidus_admin/adjustment_reasons/index/component.rb +19 -2
  11. data/app/components/solidus_admin/adjustment_reasons/new/component.html.erb +28 -0
  12. data/app/components/solidus_admin/adjustment_reasons/new/component.rb +12 -0
  13. data/app/components/solidus_admin/adjustment_reasons/new/component.yml +8 -0
  14. data/app/components/solidus_admin/base_component.rb +0 -25
  15. data/app/components/solidus_admin/option_types/index/component.rb +1 -1
  16. data/app/components/solidus_admin/orders/index/component.rb +8 -8
  17. data/app/components/solidus_admin/orders/index/component.yml +1 -0
  18. data/app/components/solidus_admin/orders/show/address/component.html.erb +56 -54
  19. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/component.rb +27 -0
  20. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_line_item/component.rb +14 -0
  21. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_order/component.rb +11 -0
  22. data/app/components/solidus_admin/orders/show/adjustments/index/adjustable/spree_shipment/component.rb +15 -0
  23. data/app/components/solidus_admin/orders/show/adjustments/index/component.rb +147 -0
  24. data/app/components/solidus_admin/orders/show/adjustments/index/component.yml +21 -0
  25. data/app/components/solidus_admin/orders/show/adjustments/index/source/component.rb +26 -0
  26. data/app/components/solidus_admin/orders/show/adjustments/index/source/spree_tax_rate/component.rb +17 -0
  27. data/app/components/solidus_admin/orders/show/adjustments/index/source/spree_unit_cancel/component.rb +7 -0
  28. data/app/components/solidus_admin/orders/show/component.html.erb +7 -3
  29. data/app/components/solidus_admin/orders/show/component.rb +8 -0
  30. data/app/components/solidus_admin/orders/show/email/component.html.erb +18 -13
  31. data/app/components/solidus_admin/orders/show/email/component.rb +0 -4
  32. data/app/components/solidus_admin/orders/show/summary/component.html.erb +1 -1
  33. data/app/components/solidus_admin/payment_methods/index/component.rb +1 -1
  34. data/app/components/solidus_admin/products/index/component.rb +8 -5
  35. data/app/components/solidus_admin/products/show/component.html.erb +14 -3
  36. data/app/components/solidus_admin/products/status/component.rb +4 -1
  37. data/app/components/solidus_admin/products/status/component.yml +1 -0
  38. data/app/components/solidus_admin/properties/index/component.rb +1 -1
  39. data/app/components/solidus_admin/refund_reasons/edit/component.html.erb +27 -0
  40. data/app/components/solidus_admin/refund_reasons/edit/component.rb +12 -0
  41. data/app/components/solidus_admin/refund_reasons/edit/component.yml +8 -0
  42. data/app/components/solidus_admin/refund_reasons/index/component.rb +11 -4
  43. data/app/components/solidus_admin/refund_reasons/new/component.html.erb +27 -0
  44. data/app/components/solidus_admin/refund_reasons/new/component.rb +12 -0
  45. data/app/components/solidus_admin/refund_reasons/new/component.yml +6 -0
  46. data/app/components/solidus_admin/return_reasons/edit/component.html.erb +26 -0
  47. data/app/components/solidus_admin/return_reasons/edit/component.rb +12 -0
  48. data/app/components/solidus_admin/return_reasons/edit/component.yml +8 -0
  49. data/app/components/solidus_admin/return_reasons/index/component.rb +20 -2
  50. data/app/components/solidus_admin/return_reasons/new/component.html.erb +27 -0
  51. data/app/components/solidus_admin/return_reasons/new/component.rb +12 -0
  52. data/app/components/solidus_admin/return_reasons/new/component.yml +8 -0
  53. data/app/components/solidus_admin/roles/edit/component.html.erb +33 -0
  54. data/app/components/solidus_admin/roles/edit/component.rb +20 -0
  55. data/app/components/solidus_admin/roles/edit/component.yml +19 -0
  56. data/app/components/solidus_admin/roles/index/component.rb +70 -0
  57. data/app/components/solidus_admin/roles/index/component.yml +6 -0
  58. data/app/components/solidus_admin/roles/new/component.html.erb +33 -0
  59. data/app/components/solidus_admin/roles/new/component.rb +20 -0
  60. data/app/components/solidus_admin/roles/new/component.yml +19 -0
  61. data/app/components/solidus_admin/shipping_categories/edit/component.html.erb +16 -0
  62. data/app/components/solidus_admin/shipping_categories/edit/component.rb +12 -0
  63. data/app/components/solidus_admin/shipping_categories/edit/component.yml +6 -0
  64. data/app/components/solidus_admin/shipping_categories/index/component.rb +20 -3
  65. data/app/components/solidus_admin/shipping_categories/new/component.html.erb +17 -0
  66. data/app/components/solidus_admin/shipping_categories/new/component.rb +12 -0
  67. data/app/components/solidus_admin/shipping_categories/new/component.yml +6 -0
  68. data/app/components/solidus_admin/shipping_methods/index/component.rb +2 -2
  69. data/app/components/solidus_admin/stock_items/edit/component.html.erb +66 -72
  70. data/app/components/solidus_admin/stock_items/edit/component.rb +0 -5
  71. data/app/components/solidus_admin/stock_items/index/component.rb +5 -6
  72. data/app/components/solidus_admin/stock_locations/index/component.rb +1 -1
  73. data/app/components/solidus_admin/store_credit_reasons/edit/component.html.erb +26 -0
  74. data/app/components/solidus_admin/store_credit_reasons/edit/component.rb +12 -0
  75. data/app/components/solidus_admin/store_credit_reasons/edit/component.yml +8 -0
  76. data/app/components/solidus_admin/store_credit_reasons/index/component.rb +11 -4
  77. data/app/components/solidus_admin/store_credit_reasons/new/component.html.erb +27 -0
  78. data/app/components/solidus_admin/store_credit_reasons/new/component.rb +12 -0
  79. data/app/components/solidus_admin/store_credit_reasons/new/component.yml +8 -0
  80. data/app/components/solidus_admin/stores/index/component.rb +1 -1
  81. data/app/components/solidus_admin/tax_categories/edit/component.html.erb +28 -0
  82. data/app/components/solidus_admin/tax_categories/edit/component.rb +12 -0
  83. data/app/components/solidus_admin/tax_categories/edit/component.yml +8 -0
  84. data/app/components/solidus_admin/tax_categories/index/component.rb +11 -4
  85. data/app/components/solidus_admin/tax_categories/new/component.html.erb +28 -0
  86. data/app/components/solidus_admin/tax_categories/new/component.rb +12 -0
  87. data/app/components/solidus_admin/tax_categories/new/component.yml +8 -0
  88. data/app/components/solidus_admin/tax_rates/index/component.rb +3 -3
  89. data/app/components/solidus_admin/taxonomies/index/component.rb +1 -1
  90. data/app/components/solidus_admin/ui/button/component.rb +1 -1
  91. data/app/components/solidus_admin/ui/checkbox_row/component.html.erb +29 -0
  92. data/app/components/solidus_admin/ui/checkbox_row/component.rb +11 -0
  93. data/app/components/solidus_admin/ui/forms/address/component.html.erb +27 -9
  94. data/app/components/solidus_admin/ui/forms/address/component.js +38 -13
  95. data/app/components/solidus_admin/ui/forms/search/component.html.erb +2 -3
  96. data/app/components/solidus_admin/ui/forms/search/component.js +3 -3
  97. data/app/components/solidus_admin/ui/modal/component.html.erb +7 -7
  98. data/app/components/solidus_admin/ui/modal/component.js +7 -0
  99. data/app/components/solidus_admin/ui/modal/component.rb +1 -1
  100. data/app/components/solidus_admin/ui/pages/index/component.html.erb +17 -3
  101. data/app/components/solidus_admin/ui/pages/index/component.rb +29 -43
  102. data/app/components/solidus_admin/ui/panel/component.html.erb +5 -16
  103. data/app/components/solidus_admin/ui/panel/component.rb +11 -7
  104. data/app/components/solidus_admin/ui/table/component.js +31 -2
  105. data/app/components/solidus_admin/ui/table/component.rb +23 -7
  106. data/app/components/solidus_admin/ui/table/component.yml +1 -0
  107. data/app/components/solidus_admin/ui/thumbnail/component.rb +1 -1
  108. data/app/components/solidus_admin/ui/thumbnail_with_caption/component.html.erb +17 -0
  109. data/app/components/solidus_admin/ui/thumbnail_with_caption/component.rb +15 -0
  110. data/app/components/solidus_admin/users/addresses/component.html.erb +46 -0
  111. data/app/components/solidus_admin/users/addresses/component.rb +61 -0
  112. data/app/components/solidus_admin/users/addresses/component.yml +14 -0
  113. data/app/components/solidus_admin/users/edit/api_access/component.html.erb +49 -0
  114. data/app/components/solidus_admin/users/edit/api_access/component.js +9 -0
  115. data/app/components/solidus_admin/users/edit/api_access/component.rb +7 -0
  116. data/app/components/solidus_admin/users/edit/api_access/component.yml +10 -0
  117. data/app/components/solidus_admin/users/edit/component.html.erb +52 -0
  118. data/app/components/solidus_admin/users/edit/component.rb +51 -0
  119. data/app/components/solidus_admin/users/edit/component.yml +12 -0
  120. data/app/components/solidus_admin/users/index/component.rb +10 -8
  121. data/app/components/solidus_admin/users/items/component.html.erb +41 -0
  122. data/app/components/solidus_admin/users/items/component.rb +170 -0
  123. data/app/components/solidus_admin/users/items/component.yml +16 -0
  124. data/app/components/solidus_admin/users/orders/component.html.erb +42 -0
  125. data/app/components/solidus_admin/users/orders/component.rb +131 -0
  126. data/app/components/solidus_admin/users/orders/component.yml +12 -0
  127. data/app/components/solidus_admin/users/stats/component.html.erb +11 -0
  128. data/app/components/solidus_admin/users/stats/component.rb +9 -0
  129. data/app/components/solidus_admin/users/stats/component.yml +2 -0
  130. data/app/components/solidus_admin/users_and_roles/component.rb +24 -0
  131. data/app/components/solidus_admin/users_and_roles/component.yml +2 -0
  132. data/app/components/solidus_admin/zones/index/component.rb +1 -1
  133. data/app/controllers/solidus_admin/addresses_controller.rb +6 -1
  134. data/app/controllers/solidus_admin/adjustment_reasons_controller.rb +85 -10
  135. data/app/controllers/solidus_admin/adjustments_controller.rb +57 -0
  136. data/app/controllers/solidus_admin/customers_controller.rb +5 -1
  137. data/app/controllers/solidus_admin/orders_controller.rb +5 -1
  138. data/app/controllers/solidus_admin/products_controller.rb +11 -0
  139. data/app/controllers/solidus_admin/refund_reasons_controller.rb +85 -10
  140. data/app/controllers/solidus_admin/reimbursement_types_controller.rb +0 -5
  141. data/app/controllers/solidus_admin/return_reasons_controller.rb +85 -10
  142. data/app/controllers/solidus_admin/roles_controller.rb +118 -0
  143. data/app/controllers/solidus_admin/shipping_categories_controller.rb +87 -10
  144. data/app/controllers/solidus_admin/shipping_methods_controller.rb +0 -5
  145. data/app/controllers/solidus_admin/stock_items_controller.rb +6 -6
  146. data/app/controllers/solidus_admin/stock_locations_controller.rb +0 -5
  147. data/app/controllers/solidus_admin/store_credit_reasons_controller.rb +85 -10
  148. data/app/controllers/solidus_admin/stores_controller.rb +0 -5
  149. data/app/controllers/solidus_admin/tax_categories_controller.rb +89 -10
  150. data/app/controllers/solidus_admin/tax_rates_controller.rb +0 -5
  151. data/app/controllers/solidus_admin/users_controller.rb +85 -6
  152. data/app/controllers/solidus_admin/zones_controller.rb +0 -5
  153. data/app/helpers/solidus_admin/last_login_helper.rb +16 -0
  154. data/app/helpers/solidus_admin/permission_sets_helper.rb +32 -0
  155. data/app/views/layouts/solidus_admin/application.html.erb +2 -1
  156. data/config/locales/adjustment_reasons.en.yml +5 -1
  157. data/config/locales/adjustments.en.yml +10 -0
  158. data/config/locales/refund_reasons.en.yml +10 -0
  159. data/config/locales/return_reasons.en.yml +5 -1
  160. data/config/locales/roles.en.yml +10 -0
  161. data/config/locales/shipping_categories.en.yml +4 -0
  162. data/config/locales/store_credit_reasons.en.yml +5 -1
  163. data/config/locales/tax_categories.en.yml +4 -0
  164. data/config/locales/users.en.yml +10 -0
  165. data/config/routes.rb +24 -7
  166. data/docs/components.md +109 -0
  167. data/docs/{customizing_view_components.md → customizing_components.md} +2 -7
  168. data/docs/index_pages.md +146 -0
  169. data/docs/{customizing_menu_items.md → menu_items.md} +1 -1
  170. data/docs/stimulusjs.md +85 -0
  171. data/docs/{customizing_tailwindcss.md → tailwindcss.md} +27 -8
  172. data/lib/solidus_admin/component_registry.rb +40 -0
  173. data/lib/solidus_admin/configuration.rb +2 -26
  174. data/lib/solidus_admin/install_tailwindcss.rb +4 -2
  175. data/lib/solidus_admin/testing_support/admin_assets.rb +10 -0
  176. data/lib/solidus_admin/testing_support/component_helpers.rb +27 -0
  177. data/lib/solidus_admin/testing_support/dummy_app/rake_tasks.rb +60 -0
  178. data/lib/solidus_admin/testing_support/feature_helpers.rb +34 -0
  179. data/lib/solidus_admin/version.rb +1 -1
  180. data/solidus_admin.gemspec +7 -3
  181. metadata +108 -19
  182. data/app/components/solidus_admin/promotion_categories/index/component.rb +0 -56
  183. data/app/components/solidus_admin/promotions/index/component.rb +0 -104
  184. data/app/components/solidus_admin/promotions/index/component.yml +0 -10
  185. data/app/controllers/solidus_admin/promotion_categories_controller.rb +0 -29
  186. data/app/controllers/solidus_admin/promotions_controller.rb +0 -46
  187. data/config/locales/promotion_categories.en.yml +0 -6
  188. data/config/locales/promotions.en.yml +0 -6
  189. data/config/locales/refund_reasons_.en.yml +0 -6
@@ -0,0 +1,42 @@
1
+ <%= page do %>
2
+ <%= page_header do %>
3
+ <%= page_header_back(solidus_admin.users_path) %>
4
+ <%= page_header_title(t(".title", email: @user.email)) %>
5
+
6
+ <%= page_header_actions do %>
7
+ <%= render component("ui/button").new(tag: :a, text: t(".create_order_for_user"), href: spree.new_admin_order_path(user_id: @user.id)) %>
8
+ <% end %>
9
+ <% end %>
10
+
11
+ <%= page_header do %>
12
+ <% tabs.each do |tab| %>
13
+ <%= render(component("ui/button").new(tag: :a, scheme: :ghost, text: tab[:text], 'aria-current': tab[:current], href: tab[:href])) %>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <%= page_with_sidebar do %>
18
+ <%= page_with_sidebar_main do %>
19
+ <%= render component('ui/panel').new(title: t(".order_history")) do %>
20
+ <% if @orders.present? %>
21
+ <%= render component('ui/table').new(
22
+ id: stimulus_id,
23
+ data: {
24
+ class: model_class,
25
+ rows: rows,
26
+ fade: -> { row_fade(_1) },
27
+ columns: columns,
28
+ url: -> { row_url(_1) },
29
+ },
30
+ )%>
31
+ <% else %>
32
+ <%= t(".no_orders_found") %>
33
+ <%= render component("ui/button").new(tag: :a, text: t(".create_one"), href: spree.new_admin_order_path(user_id: @user.id)) %>
34
+ <% end %>
35
+ <% end %>
36
+ <% end %>
37
+
38
+ <%= page_with_sidebar_aside do %>
39
+ <%= render component("users/stats").new(user: @user) %>
40
+ <% end %>
41
+ <% end %>
42
+ <% end %>
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SolidusAdmin::Users::Orders::Component < SolidusAdmin::BaseComponent
4
+ include SolidusAdmin::Layout::PageHelpers
5
+
6
+ def initialize(user:, orders:)
7
+ @user = user
8
+ @orders = orders
9
+ end
10
+
11
+ def tabs
12
+ [
13
+ {
14
+ text: t('.account'),
15
+ href: solidus_admin.user_path(@user),
16
+ current: false,
17
+ },
18
+ {
19
+ text: t('.addresses'),
20
+ href: solidus_admin.addresses_user_path(@user),
21
+ current: false,
22
+ },
23
+ {
24
+ text: t('.order_history'),
25
+ href: solidus_admin.orders_user_path(@user),
26
+ current: true,
27
+ },
28
+ {
29
+ text: t('.items'),
30
+ href: spree.items_admin_user_path(@user),
31
+ current: false,
32
+ },
33
+ {
34
+ text: t('.store_credit'),
35
+ href: spree.admin_user_store_credits_path(@user),
36
+ current: false,
37
+ },
38
+ ]
39
+ end
40
+
41
+ def model_class
42
+ Spree::Order
43
+ end
44
+
45
+ def row_url(order)
46
+ spree.edit_admin_order_path(order)
47
+ end
48
+
49
+ def rows
50
+ @orders
51
+ end
52
+
53
+ def row_fade(_order)
54
+ false
55
+ end
56
+
57
+ def columns
58
+ [
59
+ number_column,
60
+ state_column,
61
+ date_column,
62
+ payment_column,
63
+ shipment_column,
64
+ total_column,
65
+ ]
66
+ end
67
+
68
+ def number_column
69
+ {
70
+ header: :order,
71
+ data: ->(order) do
72
+ if !row_fade(order)
73
+ content_tag :div, order.number, class: 'font-semibold'
74
+ else
75
+ content_tag :div, order.number
76
+ end
77
+ end
78
+ }
79
+ end
80
+
81
+ def state_column
82
+ {
83
+ header: :state,
84
+ data: ->(order) do
85
+ color = {
86
+ 'complete' => :green,
87
+ 'returned' => :red,
88
+ 'canceled' => :blue,
89
+ 'cart' => :graphite_light,
90
+ }[order.state] || :yellow
91
+ component('ui/badge').new(name: order.state.humanize, color: color)
92
+ end
93
+ }
94
+ end
95
+
96
+ def date_column
97
+ {
98
+ header: :date,
99
+ data: ->(order) do
100
+ content_tag :div, l(order.created_at, format: :short)
101
+ end
102
+ }
103
+ end
104
+
105
+ def total_column
106
+ {
107
+ header: :total,
108
+ data: ->(order) do
109
+ content_tag :div, number_to_currency(order.total)
110
+ end
111
+ }
112
+ end
113
+
114
+ def payment_column
115
+ {
116
+ header: :payment,
117
+ data: ->(order) do
118
+ component('ui/badge').new(name: order.payment_state.humanize, color: order.paid? ? :green : :yellow) if order.payment_state?
119
+ end
120
+ }
121
+ end
122
+
123
+ def shipment_column
124
+ {
125
+ header: :shipment,
126
+ data: ->(order) do
127
+ component('ui/badge').new(name: order.shipment_state.humanize, color: order.shipped? ? :green : :yellow) if order.shipment_state?
128
+ end
129
+ }
130
+ end
131
+ end
@@ -0,0 +1,12 @@
1
+ en:
2
+ title: "Users / %{email} / Order History"
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
+ create_order_for_user: Create order for this user
10
+ no_orders_found: No Orders found.
11
+ create_one: Create One
12
+ back: Back
@@ -0,0 +1,11 @@
1
+ <%= render component("ui/panel").new(title: t("spree.lifetime_stats")) do %>
2
+ <%= render component("ui/details_list").new(
3
+ items: [
4
+ { label: t("spree.total_sales"), value: @user.display_lifetime_value.to_html },
5
+ { label: t("spree.order_count"), value: @user.order_count.to_i },
6
+ { label: t("spree.average_order_value"), value: @user.display_average_order_value.to_html },
7
+ { label: t("spree.member_since"), value: @user.created_at.to_date },
8
+ { label: t(".last_active"), value: last_login(@user) },
9
+ ]
10
+ ) %>
11
+ <% end %>
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SolidusAdmin::Users::Stats::Component < SolidusAdmin::BaseComponent
4
+ include SolidusAdmin::LastLoginHelper
5
+
6
+ def initialize(user:)
7
+ @user = user
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ en:
2
+ last_active: Last Active
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SolidusAdmin::UsersAndRoles::Component < SolidusAdmin::UI::Pages::Index::Component
4
+ def title
5
+ page_header_title safe_join([
6
+ tag.div(t(".title")),
7
+ ])
8
+ end
9
+
10
+ def tabs
11
+ [
12
+ {
13
+ text: Spree.user_class.model_name.human(count: 2),
14
+ href: solidus_admin.users_path,
15
+ current: model_class == Spree.user_class,
16
+ },
17
+ {
18
+ text: Spree::Role.model_name.human(count: 2),
19
+ href: solidus_admin.roles_path,
20
+ current: model_class == Spree::Role,
21
+ },
22
+ ]
23
+ end
24
+ end
@@ -0,0 +1,2 @@
1
+ en:
2
+ title: "Users and Roles"
@@ -30,7 +30,7 @@ class SolidusAdmin::Zones::Index::Component < SolidusAdmin::UI::Pages::Index::Co
30
30
  def batch_actions
31
31
  [
32
32
  {
33
- display_name: t('.batch_actions.delete'),
33
+ label: t('.batch_actions.delete'),
34
34
  action: solidus_admin.zones_path,
35
35
  method: :delete,
36
36
  icon: 'delete-bin-7-line',
@@ -26,7 +26,12 @@ module SolidusAdmin
26
26
 
27
27
  def update
28
28
  if @order.contents.update_cart(order_params)
29
- redirect_to order_path(@order), status: :see_other, notice: t('.success')
29
+ respond_to do |format|
30
+ flash[:notice] = t('.success')
31
+
32
+ format.html { redirect_to order_path(@order), status: :see_other }
33
+ format.turbo_stream { render turbo_stream: '<turbo-stream action="refresh" />' }
34
+ end
30
35
  else
31
36
  flash.now[:error] = @order.errors[:base].join(", ") if @order.errors[:base].any?
32
37
 
@@ -4,19 +4,86 @@ module SolidusAdmin
4
4
  class AdjustmentReasonsController < SolidusAdmin::BaseController
5
5
  include SolidusAdmin::ControllerHelpers::Search
6
6
 
7
- def index
8
- adjustment_reasons = apply_search_to(
9
- Spree::AdjustmentReason.order(id: :desc),
10
- param: :q,
11
- )
7
+ before_action :set_adjustment_reason, only: %i[edit update]
12
8
 
13
- set_page_and_extract_portion_from(adjustment_reasons)
9
+ def index
10
+ set_index_page
14
11
 
15
12
  respond_to do |format|
16
13
  format.html { render component('adjustment_reasons/index').new(page: @page) }
17
14
  end
18
15
  end
19
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
+
20
87
  def destroy
21
88
  @adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id])
22
89
 
@@ -28,13 +95,21 @@ module SolidusAdmin
28
95
 
29
96
  private
30
97
 
31
- def load_adjustment_reason
32
- @adjustment_reason = Spree::AdjustmentReason.find_by!(id: params[:id])
33
- authorize! action_name, @adjustment_reason
98
+ def set_adjustment_reason
99
+ @adjustment_reason = Spree::AdjustmentReason.find(params[:id])
34
100
  end
35
101
 
36
102
  def adjustment_reason_params
37
- params.require(:adjustment_reason).permit(:adjustment_reason_id, permitted_adjustment_reason_attributes)
103
+ params.require(:adjustment_reason).permit(:name, :code, :active)
104
+ 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)
38
113
  end
39
114
  end
40
115
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SolidusAdmin::AdjustmentsController < SolidusAdmin::BaseController
4
+ before_action :load_order
5
+
6
+ def index
7
+ load_adjustments
8
+ set_page_and_extract_portion_from(@adjustments)
9
+
10
+ respond_to do |format|
11
+ format.html do
12
+ render component('orders/show/adjustments/index').new(
13
+ order: @order,
14
+ adjustments: @adjustments,
15
+ )
16
+ end
17
+ end
18
+ end
19
+
20
+ def lock
21
+ @adjustments = @order.all_adjustments.not_finalized.where(id: params[:id])
22
+ @adjustments.each(&:finalize!)
23
+ flash[:success] = t('.success')
24
+
25
+ redirect_to order_adjustments_path(@order), status: :see_other
26
+ end
27
+
28
+ def unlock
29
+ @adjustments = @order.all_adjustments.finalized.where(id: params[:id])
30
+ @adjustments.each(&:unfinalize!)
31
+ flash[:success] = t('.success')
32
+
33
+ redirect_to order_adjustments_path(@order), status: :see_other
34
+ end
35
+
36
+ def destroy
37
+ @adjustments = @order.all_adjustments.where(id: params[:id])
38
+ @adjustments.destroy_all
39
+ flash[:success] = t('.success')
40
+
41
+ redirect_to order_adjustments_path(@order), status: :see_other
42
+ end
43
+
44
+ private
45
+
46
+ def load_adjustments
47
+ @adjustments = @order
48
+ .all_adjustments
49
+ .order("adjustable_type ASC, created_at ASC")
50
+ .ransack(params[:q])
51
+ .result
52
+ end
53
+
54
+ def load_order
55
+ @order = Spree::Order.find_by!(number: params[:order_id])
56
+ end
57
+ end
@@ -4,7 +4,11 @@ class SolidusAdmin::CustomersController < SolidusAdmin::BaseController
4
4
  before_action :load_order, only: [:show, :destroy]
5
5
 
6
6
  def show
7
- render component('orders/show/email').new(order: @order)
7
+ respond_to do |format|
8
+ format.html do
9
+ render component('orders/show/email').new(order: @order)
10
+ end
11
+ end
8
12
  end
9
13
 
10
14
  def destroy
@@ -54,7 +54,11 @@ module SolidusAdmin
54
54
  flash[:error] = t('.error')
55
55
  end
56
56
 
57
- redirect_to spree.edit_admin_order_path(@order)
57
+ respond_to do |format|
58
+ format.html { redirect_to spree.edit_admin_order_path(@order) }
59
+
60
+ format.turbo_stream { render turbo_stream: '<turbo-stream action="refresh" />' }
61
+ end
58
62
  end
59
63
 
60
64
  def edit
@@ -11,6 +11,8 @@ module SolidusAdmin
11
11
  search_scope(:in_stock) { _1.where(id: Spree::Variant.in_stock.distinct.select(:product_id)) }
12
12
  search_scope(:out_of_stock) { _1.where.not(id: Spree::Variant.in_stock.distinct.select(:product_id)) }
13
13
 
14
+ before_action :split_params, only: [:update]
15
+
14
16
  def index
15
17
  products = apply_search_to(
16
18
  Spree::Product.includes(:master, :variants),
@@ -98,5 +100,14 @@ module SolidusAdmin
98
100
  flash[:notice] = t('.success')
99
101
  redirect_to products_path, status: :see_other
100
102
  end
103
+
104
+ def split_params
105
+ if params[:product][:taxon_ids].present?
106
+ params[:product][:taxon_ids] = params[:product][:taxon_ids].split(',')
107
+ end
108
+ if params[:product][:option_type_ids].present?
109
+ params[:product][:option_type_ids] = params[:product][:option_type_ids].split(',')
110
+ end
111
+ end
101
112
  end
102
113
  end
@@ -4,19 +4,86 @@ module SolidusAdmin
4
4
  class RefundReasonsController < SolidusAdmin::BaseController
5
5
  include SolidusAdmin::ControllerHelpers::Search
6
6
 
7
- def index
8
- refund_reasons = apply_search_to(
9
- Spree::RefundReason.unscoped.order(id: :desc),
10
- param: :q,
11
- )
7
+ before_action :set_refund_reason, only: %i[edit update]
12
8
 
13
- set_page_and_extract_portion_from(refund_reasons)
9
+ def index
10
+ set_index_page
14
11
 
15
12
  respond_to do |format|
16
13
  format.html { render component('refund_reasons/index').new(page: @page) }
17
14
  end
18
15
  end
19
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
+
20
87
  def destroy
21
88
  @refund_reason = Spree::RefundReason.find_by!(id: params[:id])
22
89
 
@@ -28,13 +95,21 @@ module SolidusAdmin
28
95
 
29
96
  private
30
97
 
31
- def load_refund_reason
32
- @refund_reason = Spree::RefundReason.find_by!(id: params[:id])
33
- authorize! action_name, @refund_reason
98
+ def set_refund_reason
99
+ @refund_reason = Spree::RefundReason.find(params[:id])
34
100
  end
35
101
 
36
102
  def refund_reason_params
37
- params.require(:refund_reason).permit(:refund_reason_id, permitted_refund_reason_attributes)
103
+ params.require(:refund_reason).permit(:name, :code, :active)
104
+ end
105
+
106
+ def set_index_page
107
+ refund_reasons = apply_search_to(
108
+ Spree::RefundReason.unscoped.order(id: :desc),
109
+ param: :q,
110
+ )
111
+
112
+ set_page_and_extract_portion_from(refund_reasons)
38
113
  end
39
114
  end
40
115
  end
@@ -19,11 +19,6 @@ module SolidusAdmin
19
19
 
20
20
  private
21
21
 
22
- def load_reimbursement_type
23
- @reimbursement_type = Spree::ReimbursementType.find_by!(id: params[:id])
24
- authorize! action_name, @reimbursement_type
25
- end
26
-
27
22
  def reimbursement_type_params
28
23
  params.require(:reimbursement_type).permit(:reimbursement_type_id, permitted_reimbursement_type_attributes)
29
24
  end