diff --git a/backend/app/controllers/concerns/spree/admin/breadcrumbs.rb b/backend/app/controllers/concerns/spree/admin/breadcrumbs.rb new file mode 100644 index 00000000000..a50e1646836 --- /dev/null +++ b/backend/app/controllers/concerns/spree/admin/breadcrumbs.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Spree + module Admin + module Breadcrumbs + def add_breadcrumb(name, path = nil) + @admin_breadcrumbs ||= [] + @admin_breadcrumbs << [name, path] + end + + # Shared breadcrumbs + + def set_user_breadcrumbs + add_breadcrumb plural_resource_name(Spree::LegacyUser), spree.admin_users_path + add_breadcrumb @user.email, edit_admin_user_url(@user) if @user && !@user.new_record? + end + + def set_order_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Order), spree.admin_orders_path + add_breadcrumb "##{@order.number}", spree.edit_admin_order_path(@order) if @order && !@order.new_record? + end + + def set_product_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Product), spree.admin_products_path + add_breadcrumb @product.name, spree.admin_product_path(@product) if @product && !@product.new_record? + end + end + end +end diff --git a/backend/app/controllers/spree/admin/adjustment_reasons_controller.rb b/backend/app/controllers/spree/admin/adjustment_reasons_controller.rb index c55fcd7abbc..310dc6c4357 100644 --- a/backend/app/controllers/spree/admin/adjustment_reasons_controller.rb +++ b/backend/app/controllers/spree/admin/adjustment_reasons_controller.rb @@ -3,6 +3,17 @@ module Spree module Admin class AdjustmentReasonsController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.checkout') + add_breadcrumb plural_resource_name(Spree::AdjustmentReason), spree.admin_adjustment_reasons_path + add_breadcrumb @adjustment_reason.name if params[:id].present? + add_breadcrumb t('spree.new_adjustment_reason') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/adjustments_controller.rb b/backend/app/controllers/spree/admin/adjustments_controller.rb index 991a48374dc..ae81c6a1ac4 100644 --- a/backend/app/controllers/spree/admin/adjustments_controller.rb +++ b/backend/app/controllers/spree/admin/adjustments_controller.rb @@ -12,6 +12,7 @@ class AdjustmentsController < ResourceController skip_before_action :load_resource, only: [:toggle_state, :edit, :update, :destroy] before_action :find_adjustment, only: [:destroy, :edit, :update] + before_action :set_breadcrumbs helper_method :reasons_for @@ -42,6 +43,13 @@ def reasons_for(_adjustment) @adjustment.adjustment_reason ].flatten.compact.uniq.sort_by { |r| r.name.downcase } end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Adjustment), spree.admin_order_adjustments_path(@order) + add_breadcrumb t('spree.new_adjustment') if action_name == 'new' + add_breadcrumb "#{t('spree.actions.edit')} #{Spree::Adjustment.model_name.human}" if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/base_controller.rb b/backend/app/controllers/spree/admin/base_controller.rb index 008ca95ff05..398c3fa7fd2 100644 --- a/backend/app/controllers/spree/admin/base_controller.rb +++ b/backend/app/controllers/spree/admin/base_controller.rb @@ -3,6 +3,8 @@ module Spree module Admin class BaseController < Spree::BaseController + include Spree::Admin::Breadcrumbs + helper 'spree/admin/navigation' layout '/spree/layouts/admin' diff --git a/backend/app/controllers/spree/admin/cancellations_controller.rb b/backend/app/controllers/spree/admin/cancellations_controller.rb index 3e7ac13e19b..30e1ff279ef 100644 --- a/backend/app/controllers/spree/admin/cancellations_controller.rb +++ b/backend/app/controllers/spree/admin/cancellations_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class CancellationsController < Spree::Admin::BaseController before_action :load_order, only: [:index, :short_ship] + before_action :set_breadcrumbs def index @inventory_units = @order.inventory_units.cancelable @@ -41,6 +42,11 @@ def load_order def model_class Spree::OrderCancellations end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb t('spree.cancel_inventory') + end end end end diff --git a/backend/app/controllers/spree/admin/customer_returns_controller.rb b/backend/app/controllers/spree/admin/customer_returns_controller.rb index cd477915a9c..f13ba2c060d 100644 --- a/backend/app/controllers/spree/admin/customer_returns_controller.rb +++ b/backend/app/controllers/spree/admin/customer_returns_controller.rb @@ -9,6 +9,7 @@ class CustomerReturnsController < ResourceController before_action :parent # ensure order gets loaded to support our pseudo parent-child relationship before_action :load_form_data, only: [:new, :edit] before_action :build_return_items_from_params, only: [:create] + before_action :set_breadcrumbs create.fails :load_form_data def edit @@ -71,6 +72,13 @@ def build_return_items_from_params return_item end.compact end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb plural_resource_name(Spree::CustomerReturn), spree.admin_order_customer_returns_url(@order) + add_breadcrumb @customer_return.number if params[:id].present? + add_breadcrumb t('spree.new_customer_return') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/images_controller.rb b/backend/app/controllers/spree/admin/images_controller.rb index 13a2df3d64e..0070280d48a 100644 --- a/backend/app/controllers/spree/admin/images_controller.rb +++ b/backend/app/controllers/spree/admin/images_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class ImagesController < ResourceController before_action :load_data + before_action :set_breadcrumbs create.before :set_viewable update.before :set_viewable @@ -30,6 +31,12 @@ def set_viewable @image.viewable_type = 'Spree::Variant' @image.viewable_id = params[:image][:viewable_id] end + + def set_breadcrumbs + set_product_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Image), admin_product_images_path(@product) + add_breadcrumb @image.filename if params[:id].present? + end end end end diff --git a/backend/app/controllers/spree/admin/log_entries_controller.rb b/backend/app/controllers/spree/admin/log_entries_controller.rb index d64f542761b..ade9538cbd0 100644 --- a/backend/app/controllers/spree/admin/log_entries_controller.rb +++ b/backend/app/controllers/spree/admin/log_entries_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class LogEntriesController < Spree::Admin::BaseController before_action :find_order_and_payment + before_action :set_breadcrumbs def index Spree::Deprecation.warn 'Using a dedicated route for payment log entries ' \ @@ -18,6 +19,12 @@ def find_order_and_payment @order = Spree::Order.where(number: params[:order_id]).first! @payment = @order.payments.find(params[:payment_id]) end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb Spree::Payment.model_name.human + add_breadcrumb plural_resource_name(Spree::LogEntry) + end end end end diff --git a/backend/app/controllers/spree/admin/option_types_controller.rb b/backend/app/controllers/spree/admin/option_types_controller.rb index ce422e8682d..3dafd89fcc0 100644 --- a/backend/app/controllers/spree/admin/option_types_controller.rb +++ b/backend/app/controllers/spree/admin/option_types_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class OptionTypesController < ResourceController before_action :setup_new_option_value, only: :edit + before_action :set_breadcrumb def update_values_positions params[:positions].each do |id, index| @@ -36,6 +37,12 @@ def set_available_option_types Spree::OptionType.all end end + + def set_breadcrumb + add_breadcrumb plural_resource_name(Spree::Product), spree.admin_products_path + add_breadcrumb plural_resource_name(Spree::OptionType), spree.admin_option_types_path + add_breadcrumb @option_type.name if params[:id].present? + end end end end diff --git a/backend/app/controllers/spree/admin/orders/customer_details_controller.rb b/backend/app/controllers/spree/admin/orders/customer_details_controller.rb index 37f74502cc0..b6cf5b3a89c 100644 --- a/backend/app/controllers/spree/admin/orders/customer_details_controller.rb +++ b/backend/app/controllers/spree/admin/orders/customer_details_controller.rb @@ -7,6 +7,7 @@ class CustomerDetailsController < Spree::Admin::BaseController rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error before_action :load_order + before_action :set_breadcrumbs def show edit @@ -75,6 +76,11 @@ def insufficient_stock_error flash[:error] = t('spree.insufficient_stock_for_order') redirect_to edit_admin_order_customer_url(@order) end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb t('spree.customer_details') + end end end end diff --git a/backend/app/controllers/spree/admin/orders_controller.rb b/backend/app/controllers/spree/admin/orders_controller.rb index 3f4c22ca2d1..aba10acded0 100644 --- a/backend/app/controllers/spree/admin/orders_controller.rb +++ b/backend/app/controllers/spree/admin/orders_controller.rb @@ -8,6 +8,7 @@ class OrdersController < Spree::Admin::BaseController before_action :initialize_order_events before_action :load_order, only: [:edit, :update, :complete, :advance, :cancel, :resume, :approve, :resend, :unfinalize_adjustments, :finalize_adjustments, :cart, :confirm] around_action :lock_order, only: [:update, :advance, :complete, :confirm, :cancel, :resume, :approve, :resend] + before_action :set_breadcrumbs rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error @@ -186,6 +187,13 @@ def require_ship_address redirect_to edit_admin_order_customer_url(@order) end end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb t('spree.cart') if action_name == 'cart' + add_breadcrumb t('spree.confirm_order') if action_name == 'confirm' + add_breadcrumb plural_resource_name(Spree::Shipment) if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/payment_methods_controller.rb b/backend/app/controllers/spree/admin/payment_methods_controller.rb index e2c470df574..fd76ecc2320 100644 --- a/backend/app/controllers/spree/admin/payment_methods_controller.rb +++ b/backend/app/controllers/spree/admin/payment_methods_controller.rb @@ -6,6 +6,7 @@ class PaymentMethodsController < ResourceController skip_before_action :load_resource, only: :create before_action :load_payment_method_types, except: [:index] before_action :validate_payment_method_type, only: [:create, :update] + before_action :set_breadcrumbs respond_to :html @@ -81,6 +82,14 @@ def validate_payment_method_type def payment_method_params params.require(:payment_method).permit! end + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb plural_resource_name(Spree::Payment) + add_breadcrumb plural_resource_name(Spree::PaymentMethod), spree.admin_payment_methods_path + add_breadcrumb t('spree.new_payment_method') if action_name == 'new' + add_breadcrumb @payment_method.name if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/payments_controller.rb b/backend/app/controllers/spree/admin/payments_controller.rb index c386e27cf39..ac825a976c4 100644 --- a/backend/app/controllers/spree/admin/payments_controller.rb +++ b/backend/app/controllers/spree/admin/payments_controller.rb @@ -10,6 +10,7 @@ class PaymentsController < Spree::Admin::BaseController before_action :load_payment_for_fire, only: :fire before_action :load_data before_action :require_bill_address, only: [:index] + before_action :set_breadcrumbs respond_to :html @@ -118,6 +119,13 @@ def insufficient_stock_error flash[:error] = t('spree.insufficient_stock_for_order') redirect_to new_admin_order_payment_url(@order) end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Payment), spree.admin_order_payments_path(@order) + add_breadcrumb t('spree.new_payment') if action_name == 'new' + add_breadcrumb @payment.payment_method.name if action_name == 'show' + end end end end diff --git a/backend/app/controllers/spree/admin/prices_controller.rb b/backend/app/controllers/spree/admin/prices_controller.rb index 254fbb00fda..ee6029908fc 100644 --- a/backend/app/controllers/spree/admin/prices_controller.rb +++ b/backend/app/controllers/spree/admin/prices_controller.rb @@ -5,6 +5,8 @@ module Admin class PricesController < ResourceController belongs_to 'spree/product', find_by: :slug + before_action :set_breadcrumbs + def index params[:q] ||= {} @@ -23,6 +25,15 @@ def index def edit end + + private + + def set_breadcrumbs + set_product_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Price), spree.admin_product_prices_url(@product) + add_breadcrumb t('spree.actions.edit') if action_name == 'edit' + add_breadcrumb t('spree.actions.new') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/product_properties_controller.rb b/backend/app/controllers/spree/admin/product_properties_controller.rb index fe4a34da151..9995d6c5096 100644 --- a/backend/app/controllers/spree/admin/product_properties_controller.rb +++ b/backend/app/controllers/spree/admin/product_properties_controller.rb @@ -7,6 +7,7 @@ class ProductPropertiesController < ResourceController before_action :find_properties before_action :setup_property, only: :index, if: -> { can?(:create, model_class) } before_action :setup_variant_property_rules, only: :index + before_action :set_breadcrumbs private @@ -24,6 +25,11 @@ def setup_variant_property_rules @variant_property_rule = @product.find_variant_property_rule(@option_value_ids) || @product.variant_property_rules.build @variant_property_rule.values.build if can?(:create, Spree::VariantPropertyRuleValue) end + + def set_breadcrumbs + set_product_breadcrumbs + add_breadcrumb plural_resource_name(Spree::ProductProperty) + end end end end diff --git a/backend/app/controllers/spree/admin/products_controller.rb b/backend/app/controllers/spree/admin/products_controller.rb index ffffde186a7..d074eb5814d 100644 --- a/backend/app/controllers/spree/admin/products_controller.rb +++ b/backend/app/controllers/spree/admin/products_controller.rb @@ -9,6 +9,7 @@ class ProductsController < ResourceController update.before :update_before helper_method :clone_object_url before_action :split_params, only: [:create, :update] + before_action :set_breadcrumbs def show redirect_to action: :edit @@ -138,6 +139,12 @@ def variant_scope def updating_variant_property_rules? params[:product][:variant_property_rules_attributes].present? end + + def set_breadcrumbs + set_product_breadcrumbs + add_breadcrumb t('spree.product_details') if action_name == 'edit' + add_breadcrumb t('spree.new_product') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/promotion_categories_controller.rb b/backend/app/controllers/spree/admin/promotion_categories_controller.rb index dc01568228d..780a61e5ee0 100644 --- a/backend/app/controllers/spree/admin/promotion_categories_controller.rb +++ b/backend/app/controllers/spree/admin/promotion_categories_controller.rb @@ -3,6 +3,16 @@ module Spree module Admin class PromotionCategoriesController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Promotion), spree.admin_promotions_path + add_breadcrumb plural_resource_name(Spree::PromotionCategory), spree.admin_promotion_categories_path + add_breadcrumb @promotion_category.name if action_name == 'edit' + add_breadcrumb t('spree.new_promotion_category') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/promotion_code_batches_controller.rb b/backend/app/controllers/spree/admin/promotion_code_batches_controller.rb index fd52a797e1e..dd75181f2bd 100644 --- a/backend/app/controllers/spree/admin/promotion_code_batches_controller.rb +++ b/backend/app/controllers/spree/admin/promotion_code_batches_controller.rb @@ -5,6 +5,7 @@ module Admin class PromotionCodeBatchesController < ResourceController belongs_to 'spree/promotion' + before_action :set_breadcrumbs create.after :build_promotion_code_batch def download @@ -25,6 +26,13 @@ def download def build_promotion_code_batch @promotion_code_batch.process end + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Promotion), spree.admin_promotions_path + add_breadcrumb @promotion.name, spree.edit_admin_promotion_path(@promotion.id) if action_name == 'index' + add_breadcrumb @promotion.name, spree.admin_promotion_path(@promotion.id) if action_name == 'new' + add_breadcrumb plural_resource_name(Spree::PromotionCodeBatch) + end end end end diff --git a/backend/app/controllers/spree/admin/promotion_codes_controller.rb b/backend/app/controllers/spree/admin/promotion_codes_controller.rb index 6c19fa51ff6..a617c95af2e 100644 --- a/backend/app/controllers/spree/admin/promotion_codes_controller.rb +++ b/backend/app/controllers/spree/admin/promotion_codes_controller.rb @@ -5,8 +5,10 @@ module Spree module Admin class PromotionCodesController < Spree::Admin::ResourceController + before_action :load_promotion + before_action :set_breadcrumbs + def index - @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) @promotion_codes = @promotion.promotion_codes.order(:value) respond_to do |format| @@ -22,12 +24,10 @@ def index end def new - @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) @promotion_code = @promotion.promotion_codes.build end def create - @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) @promotion_code = @promotion.promotion_codes.build(value: params[:promotion_code][:value]) if @promotion_code.save @@ -38,6 +38,18 @@ def create render_after_create_error end end + + private + + def load_promotion + @promotion = Spree::Promotion.accessible_by(current_ability, :read).find(params[:promotion_id]) + end + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Promotion), spree.admin_promotions_path + add_breadcrumb @promotion.name, spree.edit_admin_promotion_path(@promotion) + add_breadcrumb plural_resource_name(Spree::PromotionCode) + end end end end diff --git a/backend/app/controllers/spree/admin/promotions_controller.rb b/backend/app/controllers/spree/admin/promotions_controller.rb index 01ece74c5b3..0a3af164ab6 100644 --- a/backend/app/controllers/spree/admin/promotions_controller.rb +++ b/backend/app/controllers/spree/admin/promotions_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class PromotionsController < ResourceController before_action :load_data + before_action :set_breadcrumbs helper 'spree/promotion_rules' @@ -62,6 +63,12 @@ def promotion_code_batch_params def promotion_includes [:promotion_actions] end + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Promotion), spree.admin_promotions_path + add_breadcrumb @promotion.name if action_name == 'edit' + add_breadcrumb t('spree.new_promotion') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/properties_controller.rb b/backend/app/controllers/spree/admin/properties_controller.rb index aab13303dc7..8afe55a52a0 100644 --- a/backend/app/controllers/spree/admin/properties_controller.rb +++ b/backend/app/controllers/spree/admin/properties_controller.rb @@ -3,6 +3,8 @@ module Spree module Admin class PropertiesController < ResourceController + before_action :set_breadcrumbs + def index respond_with(@collection) end @@ -22,6 +24,12 @@ def collection @collection end + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Product), spree.admin_products_path + add_breadcrumb plural_resource_name(Spree::Property), spree.admin_properties_path + add_breadcrumb @property.name if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/refund_reasons_controller.rb b/backend/app/controllers/spree/admin/refund_reasons_controller.rb index 004eada6589..79c2bf6e305 100644 --- a/backend/app/controllers/spree/admin/refund_reasons_controller.rb +++ b/backend/app/controllers/spree/admin/refund_reasons_controller.rb @@ -3,6 +3,17 @@ module Spree module Admin class RefundReasonsController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.checkout') + add_breadcrumb plural_resource_name(Spree::RefundReason), spree.admin_refund_reasons_path + add_breadcrumb @refund_reason.name if action_name == 'edit' + add_breadcrumb t('spree.new_refund_reason') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/refunds_controller.rb b/backend/app/controllers/spree/admin/refunds_controller.rb index 0ae91c2e741..e694570bd84 100644 --- a/backend/app/controllers/spree/admin/refunds_controller.rb +++ b/backend/app/controllers/spree/admin/refunds_controller.rb @@ -5,6 +5,7 @@ module Admin class RefundsController < ResourceController belongs_to 'spree/payment' before_action :load_order + before_action :set_breadcrumbs helper_method :refund_reasons @@ -35,6 +36,14 @@ def spree_core_gateway_error(error) flash[:error] = error.message render :new end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Payment), spree.admin_order_payments_path(@order) + add_breadcrumb "#{Spree::Payment.model_name.human} #{@refund.payment.id}", admin_order_payment_path(@refund.payment.order, @refund.payment) + add_breadcrumb "#{t('spree.editing_refund')} #{@refund.id}" if action_name == 'edit' + add_breadcrumb t('spree.new_refund') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/reimbursement_types_controller.rb b/backend/app/controllers/spree/admin/reimbursement_types_controller.rb index bb6e7e1b599..cb70a584a9e 100644 --- a/backend/app/controllers/spree/admin/reimbursement_types_controller.rb +++ b/backend/app/controllers/spree/admin/reimbursement_types_controller.rb @@ -3,6 +3,15 @@ module Spree module Admin class ReimbursementTypesController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.checkout') + add_breadcrumb plural_resource_name(Spree::ReimbursementType) + end end end end diff --git a/backend/app/controllers/spree/admin/reimbursements_controller.rb b/backend/app/controllers/spree/admin/reimbursements_controller.rb index e9680cda09c..0c9e5b9a514 100644 --- a/backend/app/controllers/spree/admin/reimbursements_controller.rb +++ b/backend/app/controllers/spree/admin/reimbursements_controller.rb @@ -9,6 +9,7 @@ class ReimbursementsController < ResourceController before_action :load_stock_locations, only: :edit before_action :load_simulated_refunds, only: :edit + before_action :set_breadcrumbs create.after :recalculate_order rescue_from Spree::Core::GatewayError, with: :spree_core_gateway_error @@ -69,6 +70,13 @@ def spree_core_gateway_error(error) flash[:error] = error.message redirect_to edit_admin_order_reimbursement_path(parent, @reimbursement) end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Reimbursement) if action_name == 'index' + add_breadcrumb "#{t('spree.editing_reimbursement')} #{@reimbursement.number}" if action_name == 'edit' + add_breadcrumb "#{Spree::Reimbursement.model_name.human} #{@reimbursement.number}" if action_name == 'show' + end end end end diff --git a/backend/app/controllers/spree/admin/return_authorizations_controller.rb b/backend/app/controllers/spree/admin/return_authorizations_controller.rb index df85dd7370a..ac4654615bc 100644 --- a/backend/app/controllers/spree/admin/return_authorizations_controller.rb +++ b/backend/app/controllers/spree/admin/return_authorizations_controller.rb @@ -6,6 +6,7 @@ class ReturnAuthorizationsController < ResourceController belongs_to 'spree/order', find_by: :number before_action :load_form_data, only: [:new, :edit] + before_action :set_breadcrumbs create.fails :load_form_data update.fails :load_form_data @@ -57,6 +58,13 @@ def load_return_reasons def load_stock_locations @stock_locations = Spree::StockLocation.order_default.active end + + def set_breadcrumbs + set_order_breadcrumbs + add_breadcrumb plural_resource_name(Spree::ReturnAuthorization), spree.admin_order_return_authorizations_url + add_breadcrumb t('spree.new_return_authorization') if action_name == 'new' + add_breadcrumb @return_authorization.number if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/return_reasons_controller.rb b/backend/app/controllers/spree/admin/return_reasons_controller.rb index 1cc94e0b4ce..b870f97f2f7 100644 --- a/backend/app/controllers/spree/admin/return_reasons_controller.rb +++ b/backend/app/controllers/spree/admin/return_reasons_controller.rb @@ -3,6 +3,17 @@ module Spree module Admin class ReturnReasonsController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.checkout') + add_breadcrumb plural_resource_name(Spree::ReturnReason), spree.admin_return_reasons_path + add_breadcrumb t('spree.new_rma_reason') if action_name == 'new' + add_breadcrumb @object.name if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/shipping_categories_controller.rb b/backend/app/controllers/spree/admin/shipping_categories_controller.rb index 2366c308a40..767508a3cb8 100644 --- a/backend/app/controllers/spree/admin/shipping_categories_controller.rb +++ b/backend/app/controllers/spree/admin/shipping_categories_controller.rb @@ -3,6 +3,17 @@ module Spree module Admin class ShippingCategoriesController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.shipping') + add_breadcrumb plural_resource_name(Spree::ShippingCategory), spree.admin_shipping_categories_path + add_breadcrumb t('spree.editing_shipping_category') if action_name == 'edit' + add_breadcrumb t('spree.new_shipping_category') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/shipping_methods_controller.rb b/backend/app/controllers/spree/admin/shipping_methods_controller.rb index 85bbd548f30..d782fa034d3 100644 --- a/backend/app/controllers/spree/admin/shipping_methods_controller.rb +++ b/backend/app/controllers/spree/admin/shipping_methods_controller.rb @@ -6,6 +6,7 @@ class ShippingMethodsController < ResourceController before_action :load_data, except: :index before_action :set_shipping_category, only: [:create, :update] before_action :set_zones, only: [:create, :update] + before_action :set_breadcrumbs def destroy @object.discard @@ -43,6 +44,14 @@ def load_data @tax_categories = Spree::TaxCategory.order(:name) @calculators = Rails.application.config.spree.calculators.shipping_methods end + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.shipping') + add_breadcrumb plural_resource_name(Spree::ShippingMethod), spree.admin_shipping_methods_path + add_breadcrumb t('spree.new_shipping_method') if action_name == 'new' + add_breadcrumb @shipping_method.name if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/stock_items_controller.rb b/backend/app/controllers/spree/admin/stock_items_controller.rb index ae4d480f331..96a61c28163 100644 --- a/backend/app/controllers/spree/admin/stock_items_controller.rb +++ b/backend/app/controllers/spree/admin/stock_items_controller.rb @@ -11,6 +11,7 @@ class StockItemsController < ResourceController update.before :determine_backorderable before_action :load_product, :load_stock_management_data, only: :index + before_action :set_breadcrumbs private @@ -58,6 +59,15 @@ def variant_scope def collection [] end + + def set_breadcrumbs + if @product + set_product_breadcrumbs + add_breadcrumb t('spree.manage_stock') + else + add_breadcrumb t('spree.stock') + end + end end end end diff --git a/backend/app/controllers/spree/admin/stock_locations_controller.rb b/backend/app/controllers/spree/admin/stock_locations_controller.rb index 907eb59d07a..e900c537b35 100644 --- a/backend/app/controllers/spree/admin/stock_locations_controller.rb +++ b/backend/app/controllers/spree/admin/stock_locations_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class StockLocationsController < ResourceController before_action :set_country, only: :new + before_action :set_breadcrumbs private @@ -13,6 +14,14 @@ def set_country flash[:error] = t('spree.stock_locations_need_a_default_country') redirect_to(admin_stock_locations_path) && return end + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.shipping') + add_breadcrumb plural_resource_name(Spree::StockLocation), spree.admin_stock_locations_path + add_breadcrumb @stock_location.name if action_name == 'edit' + add_breadcrumb t('spree.new_stock_location') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/stock_movements_controller.rb b/backend/app/controllers/spree/admin/stock_movements_controller.rb index 91b67a74412..91662206f95 100644 --- a/backend/app/controllers/spree/admin/stock_movements_controller.rb +++ b/backend/app/controllers/spree/admin/stock_movements_controller.rb @@ -5,6 +5,7 @@ module Admin class StockMovementsController < ResourceController belongs_to 'spree/stock_location' before_action :parent + before_action :set_breadcrumbs private @@ -18,6 +19,22 @@ def collection includes(stock_item: { variant: :product }). page(params[:page]) end + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.shipping') + if can?(:display, Spree::StockLocation) + add_breadcrumb plural_resource_name(Spree::StockLocation), spree.admin_stock_locations_path + else + add_breadcrumb plural_resource_name(Spree::StockLocation) + end + if can?(:update, @stock_location) + add_breadcrumb helpers.admin_stock_location_display_name(@stock_location), spree.edit_admin_stock_location_path(@stock_location.id) + else + add_breadcrumb helpers.admin_stock_location_display_name(@stock_location) + end + add_breadcrumb plural_resource_name(Spree::StockMovement) + end end end end diff --git a/backend/app/controllers/spree/admin/store_credit_reasons_controller.rb b/backend/app/controllers/spree/admin/store_credit_reasons_controller.rb index 19bd4735e29..684c5f92b75 100644 --- a/backend/app/controllers/spree/admin/store_credit_reasons_controller.rb +++ b/backend/app/controllers/spree/admin/store_credit_reasons_controller.rb @@ -3,6 +3,17 @@ module Spree module Admin class StoreCreditReasonsController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.checkout') + add_breadcrumb plural_resource_name(Spree::StoreCreditReason), spree.admin_store_credit_reasons_path + add_breadcrumb t('spree.new_store_credit_reason') if action_name == 'new' + add_breadcrumb @object.name if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/store_credits_controller.rb b/backend/app/controllers/spree/admin/store_credits_controller.rb index 8e645a36422..0323f4d745b 100644 --- a/backend/app/controllers/spree/admin/store_credits_controller.rb +++ b/backend/app/controllers/spree/admin/store_credits_controller.rb @@ -7,6 +7,7 @@ class StoreCreditsController < ResourceController before_action :load_categories, only: [:new] before_action :load_reasons, only: [:edit_amount, :edit_validity] before_action :ensure_store_credit_reason, only: [:update_amount, :invalidate] + before_action :set_breadcrumbs helper Spree::Admin::StoreCreditEventsHelper @@ -113,6 +114,20 @@ def build_resource currency: Spree::Config[:currency] ) end + + def set_breadcrumbs + set_user_breadcrumbs + + if ['edit_validity', 'edit_amount'].include? action_name + add_breadcrumb plural_resource_name(Spree::StoreCredit), spree.admin_user_store_credits_path(@user) + add_breadcrumb Spree::StoreCredit.model_name.human, admin_user_store_credit_path(@user, @store_credit) + add_breadcrumb t('spree.edit') + else + add_breadcrumb Spree::StoreCredit.model_name.human, spree.admin_user_store_credits_path(@user) + add_breadcrumb @store_credit.display_amount.to_html if action_name == 'show' + add_breadcrumb t('spree.new_store_credit') if action_name == 'new' + end + end end end end diff --git a/backend/app/controllers/spree/admin/stores_controller.rb b/backend/app/controllers/spree/admin/stores_controller.rb index 6c78c6f8752..0ee9c01c951 100644 --- a/backend/app/controllers/spree/admin/stores_controller.rb +++ b/backend/app/controllers/spree/admin/stores_controller.rb @@ -3,6 +3,8 @@ module Spree module Admin class StoresController < Spree::Admin::ResourceController + before_action :set_breadcrumbs + def index if Spree::Store.count == 1 redirect_to edit_admin_store_path(Spree::Store.first) @@ -20,6 +22,12 @@ def store_params def permitted_params Spree::PermittedAttributes.store_attributes end + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Store), admin_stores_path + add_breadcrumb t('spree.new_store') if action_name == 'new' + add_breadcrumb @store.name if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/tax_categories_controller.rb b/backend/app/controllers/spree/admin/tax_categories_controller.rb index 4e8f93b5ef5..60b017dacd8 100644 --- a/backend/app/controllers/spree/admin/tax_categories_controller.rb +++ b/backend/app/controllers/spree/admin/tax_categories_controller.rb @@ -3,6 +3,17 @@ module Spree module Admin class TaxCategoriesController < ResourceController + before_action :set_breadcrumbs + + private + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.taxes') + add_breadcrumb plural_resource_name(Spree::TaxCategory), spree.admin_tax_categories_path + add_breadcrumb @tax_category.name if action_name == 'edit' + add_breadcrumb t('spree.new_tax_category') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/tax_rates_controller.rb b/backend/app/controllers/spree/admin/tax_rates_controller.rb index 4e58b938c0a..b3416ff4125 100644 --- a/backend/app/controllers/spree/admin/tax_rates_controller.rb +++ b/backend/app/controllers/spree/admin/tax_rates_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class TaxRatesController < ResourceController before_action :load_data + before_action :set_breadcrumbs private @@ -12,6 +13,14 @@ def load_data @available_categories = Spree::TaxCategory.order(:name) @calculators = Rails.application.config.spree.calculators.tax_rates end + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb t('spree.admin.tab.taxes') + add_breadcrumb plural_resource_name(Spree::TaxRate), spree.admin_tax_rates_path + add_breadcrumb @tax_rate.name if action_name == 'edit' + add_breadcrumb t('spree.new_tax_rate') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/taxonomies_controller.rb b/backend/app/controllers/spree/admin/taxonomies_controller.rb index 77c99bdf151..b5b77de9339 100644 --- a/backend/app/controllers/spree/admin/taxonomies_controller.rb +++ b/backend/app/controllers/spree/admin/taxonomies_controller.rb @@ -3,6 +3,8 @@ module Spree module Admin class TaxonomiesController < ResourceController + before_action :set_breadcrumbs + private def location_after_save @@ -12,6 +14,13 @@ def location_after_save admin_taxonomies_url end end + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Product), spree.admin_products_path + add_breadcrumb plural_resource_name(Spree::Taxonomy), spree.admin_taxonomies_path + add_breadcrumb @taxonomy.name if action_name == 'edit' + add_breadcrumb t('spree.new_taxonomy') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/taxons_controller.rb b/backend/app/controllers/spree/admin/taxons_controller.rb index 3831269f60c..5dfbb275696 100644 --- a/backend/app/controllers/spree/admin/taxons_controller.rb +++ b/backend/app/controllers/spree/admin/taxons_controller.rb @@ -5,6 +5,8 @@ module Admin class TaxonsController < Spree::Admin::BaseController respond_to :html, :json, :js + before_action :set_breadcrumbs + def index end @@ -77,6 +79,12 @@ def destroy def taxon_params params.require(:taxon).permit(permitted_taxon_attributes) end + + def set_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Product), spree.admin_products_path if action_name == 'index' + add_breadcrumb t('spree.admin.taxons.display_order') if action_name == 'index' + add_breadcrumb t('spree.taxon_edit') if action_name == 'edit' + end end end end diff --git a/backend/app/controllers/spree/admin/users_controller.rb b/backend/app/controllers/spree/admin/users_controller.rb index a288a265045..e6c46517f2e 100644 --- a/backend/app/controllers/spree/admin/users_controller.rb +++ b/backend/app/controllers/spree/admin/users_controller.rb @@ -9,6 +9,7 @@ class UsersController < ResourceController before_action :load_roles, only: [:index, :edit, :new] before_action :load_stock_locations, only: [:edit, :new] + before_action :set_breadcrumbs def index respond_with(@collection) do |format| @@ -166,6 +167,14 @@ def set_roles def set_stock_locations @user.stock_locations = Spree::StockLocation.where(id: (params[:user][:stock_location_ids] || [])) end + + def set_breadcrumbs + set_user_breadcrumbs + add_breadcrumb t('spree.new_user') if action_name == 'new' + add_breadcrumb plural_resource_name(Spree::Address) if action_name == 'addresses' + add_breadcrumb t('spree.admin.user.items_purchased') if action_name == 'items' + add_breadcrumb t('spree.admin.user.order_history') if action_name == 'orders' + end end end end diff --git a/backend/app/controllers/spree/admin/variants_controller.rb b/backend/app/controllers/spree/admin/variants_controller.rb index 97761e9d56a..81eee2f0838 100644 --- a/backend/app/controllers/spree/admin/variants_controller.rb +++ b/backend/app/controllers/spree/admin/variants_controller.rb @@ -9,6 +9,7 @@ class VariantsController < ResourceController new_action.before :new_before before_action :redirect_on_empty_option_values, only: [:new] before_action :load_data, only: [:new, :create, :edit, :update] + before_action :set_breadcrumbs private @@ -46,6 +47,13 @@ def parent @parent ||= Spree::Product.with_deleted.find_by(slug: params[:product_id]) @product = @parent end + + def set_breadcrumbs + set_product_breadcrumbs + add_breadcrumb plural_resource_name(Spree::Variant), admin_product_variants_path(@product) + add_breadcrumb @variant.options_text if action_name == 'edit' + add_breadcrumb t('spree.new_variant') if action_name == 'new' + end end end end diff --git a/backend/app/controllers/spree/admin/zones_controller.rb b/backend/app/controllers/spree/admin/zones_controller.rb index 96136762b87..633c1c1155b 100644 --- a/backend/app/controllers/spree/admin/zones_controller.rb +++ b/backend/app/controllers/spree/admin/zones_controller.rb @@ -4,6 +4,7 @@ module Spree module Admin class ZonesController < ResourceController before_action :load_data, except: :index + before_action :set_breadcrumbs def new @zone.zone_members.build @@ -23,6 +24,13 @@ def load_data @states = Spree::State.order(:name) @zones = Spree::Zone.order(:name) end + + def set_breadcrumbs + add_breadcrumb t('spree.settings') + add_breadcrumb plural_resource_name(Spree::Zone), spree.admin_zones_path + add_breadcrumb @zone.name if action_name == 'edit' + add_breadcrumb t('spree.new_zone') if action_name == 'new' + end end end end diff --git a/backend/app/helpers/spree/admin/navigation_helper.rb b/backend/app/helpers/spree/admin/navigation_helper.rb index 35a9d8f39d1..078f5ecb061 100644 --- a/backend/app/helpers/spree/admin/navigation_helper.rb +++ b/backend/app/helpers/spree/admin/navigation_helper.rb @@ -4,24 +4,32 @@ module Spree module Admin module NavigationHelper def admin_breadcrumbs - @admin_breadcrumbs ||= [] + @admin_breadcrumbs || [] end - # Add items to current page breadcrumb heirarchy def admin_breadcrumb(*ancestors, &block) - admin_breadcrumbs.concat(ancestors) if ancestors.present? + Spree::Deprecation.warn 'admin_breadcrumb method is deprecated and ' \ + 'will be removed in Soldius 3.0. Breadcrumbs should be set at ' \ + 'controller level using the add_breadcrumb method, see #3191', caller + + ancestors.each do |ancestor| + unless admin_breadcrumbs.flatten.include?(strip_tags(ancestor)) + admin_breadcrumbs.concat(Array.wrap(ancestor)) + end + end admin_breadcrumbs.push(capture(&block)) if block_given? end # Render Bootstrap style breadcrumbs def render_admin_breadcrumbs - if content_for?(:page_title) - admin_breadcrumb(content_for(:page_title)) - end - content_tag :ol, class: 'breadcrumb' do - segments = admin_breadcrumbs.map do |level| - content_tag(:li, level, class: "breadcrumb-item #{level == admin_breadcrumbs.last ? 'active' : ''}") + segments = admin_breadcrumbs.map.with_index do |(text, path), index| + last = index == admin_breadcrumbs.size - 1 + + content_tag(:li, class: "breadcrumb-item #{last ? 'active' : ''}") do + render partial: 'spree/admin/shared/breadcrumb_item', + locals: { text: text, path: path, last: last } + end end safe_join(segments) end @@ -33,7 +41,7 @@ def admin_page_title elsif content_for?(:page_title) content_for(:page_title) elsif admin_breadcrumbs.any? - admin_breadcrumbs.map{ |x| strip_tags(x) }.reverse.join(' - ') + admin_breadcrumbs.map{ |text, _, _| strip_tags(text) }.reverse.join(' - ') else t(controller.controller_name, default: controller.controller_name.titleize, scope: 'spree') end diff --git a/backend/app/views/spree/admin/adjustment_reasons/edit.html.erb b/backend/app/views/spree/admin/adjustment_reasons/edit.html.erb index c1c42b9b115..d7e81b93509 100644 --- a/backend/app/views/spree/admin/adjustment_reasons/edit.html.erb +++ b/backend/app/views/spree/admin/adjustment_reasons/edit.html.erb @@ -1,10 +1,5 @@ <%= render 'spree/admin/shared/settings_checkout_tabs' %> -<% admin_breadcrumb t('spree.settings') %> -<% admin_breadcrumb t('spree.admin.tab.checkout') %> -<% admin_breadcrumb link_to plural_resource_name(Spree::AdjustmentReason), spree.admin_adjustment_reasons_path %> -<% admin_breadcrumb @object.name %> - <%= render partial: 'spree/shared/error_messages', locals: { target: @object } %> <%= form_for [:admin, @adjustment_reason] do |f| %> diff --git a/backend/app/views/spree/admin/adjustment_reasons/index.html.erb b/backend/app/views/spree/admin/adjustment_reasons/index.html.erb index 965f2f1f9f6..407f2f194e6 100644 --- a/backend/app/views/spree/admin/adjustment_reasons/index.html.erb +++ b/backend/app/views/spree/admin/adjustment_reasons/index.html.erb @@ -1,9 +1,5 @@ <%= render 'spree/admin/shared/settings_checkout_tabs' %> -<% admin_breadcrumb(t('spree.settings')) %> -<% admin_breadcrumb(t('spree.admin.tab.checkout')) %> -<% admin_breadcrumb(plural_resource_name(Spree::AdjustmentReason)) %> - <% content_for :page_actions do %>