Skip to content

Commit

Permalink
Configure backend only if available
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielePalombo committed Dec 6, 2024
1 parent b967e83 commit 920672c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
37 changes: 21 additions & 16 deletions app/controllers/spree/admin/prototypes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@

module Spree
module Admin
class PrototypesController < ResourceController
def show
if request.xhr?
render layout: false
else
redirect_to admin_prototypes_path
if defined? ::Spree::Backend
class PrototypesController < ResourceController
def show
if request.xhr?
render layout: false
else
redirect_to admin_prototypes_path
end
end
end

def available
@prototypes = Prototype.order('name asc')
respond_with(@prototypes) do |format|
format.html { render layout: !request.xhr? }
format.js
def available
@prototypes = Prototype.order('name asc')
respond_with(@prototypes) do |format|
format.html { render layout: !request.xhr? }
format.js
end
end
end

def select
@prototype ||= Prototype.find(params[:id])
@prototype_properties = @prototype.properties
def select
@prototype ||= Prototype.find(params[:id])
@prototype_properties = @prototype.properties
end
end
else
class PrototypesController
end
end
end
Expand Down
28 changes: 15 additions & 13 deletions config/initializers/spree.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
Rails.application.config.to_prepare do
Spree::PermittedAttributes.product_attributes << :prototype_id
Spree::Backend::Config.configure do |config|
product_tab = config.menu_items.detect { |menu_item|
menu_item.label == :products
}
if product_tab.respond_to?(:children)
product_tab.children << Spree::BackendConfiguration::MenuItem.new(
condition: -> { can?(:admin, Spree::Prototype) },
url: :admin_prototypes_path,
label: :prototypes,
match_path: '/prototypes'
)
else
product_tab.sections << :prototypes
if defined?(Spree::Backend)
Spree::Backend::Config.configure do |config|
product_tab = config.menu_items.detect { |menu_item|
menu_item.label == :products
}
if product_tab.respond_to?(:children)
product_tab.children << Spree::BackendConfiguration::MenuItem.new(
condition: -> { can?(:admin, Spree::Prototype) },
url: :admin_prototypes_path,
label: :prototypes,
match_path: '/prototypes'
)
else
product_tab.sections << :prototypes
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def load_prototype
@prototype = Spree::Prototype.find(params[resource][:prototype_id])
end

::Spree::Admin::ProductsController.prepend self
::Spree::Admin::ProductsController.prepend self if defined? ::Spree::Admin::ProductsController
end
end
end

0 comments on commit 920672c

Please sign in to comment.