mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
WIP Move non-admin non-Spree controllers out of Spree namespace
This commit is contained in:
10
app/controllers/base_controller.rb
Normal file
10
app/controllers/base_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
class BaseController < ApplicationController
|
||||
include Spree::Core::ControllerHelpers
|
||||
include Spree::Core::RespondWith
|
||||
|
||||
helper 'spree/base'
|
||||
|
||||
# Spree::Core::ControllerHelpers declares helper_method get_taxonomies, so we need to
|
||||
# include Spree::ProductsHelper so that method is available on the controller
|
||||
include Spree::ProductsHelper
|
||||
end
|
||||
35
app/controllers/distributors_controller.rb
Normal file
35
app/controllers/distributors_controller.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
class DistributorsController < BaseController
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@distributor = Distributor.find params[:id]
|
||||
|
||||
@searcher = Spree::Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
|
||||
def select
|
||||
distributor = Distributor.find params[:id]
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = distributor
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to distributor
|
||||
end
|
||||
|
||||
def deselect
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = nil
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
@@ -1,39 +0,0 @@
|
||||
module Spree
|
||||
class DistributorsController < BaseController
|
||||
helper 'spree/products'
|
||||
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@distributor = Distributor.find params[:id]
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
|
||||
def select
|
||||
distributor = Distributor.find params[:id]
|
||||
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = distributor
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to distributor
|
||||
end
|
||||
|
||||
def deselect
|
||||
order = current_order(true)
|
||||
|
||||
if order.can_change_distributor?
|
||||
order.distributor = nil
|
||||
order.save!
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,19 +0,0 @@
|
||||
module Spree
|
||||
class SuppliersController < BaseController
|
||||
helper 'spree/products'
|
||||
|
||||
def index
|
||||
@suppliers = Supplier.all
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:supplier_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@supplier = Supplier.find params[:id]
|
||||
|
||||
@searcher = Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/controllers/suppliers_controller.rb
Normal file
15
app/controllers/suppliers_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class SuppliersController < BaseController
|
||||
def index
|
||||
@suppliers = Supplier.all
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:supplier_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@supplier = Supplier.find params[:id]
|
||||
|
||||
@searcher = Spree::Config.searcher_class.new(options)
|
||||
@products = @searcher.retrieve_products
|
||||
end
|
||||
end
|
||||
@@ -4,4 +4,15 @@ module ApplicationHelper
|
||||
cms_page_content(:content, Cms::Page.find_by_full_path('/'))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Pass URL helper calls on to spree where applicable so that we don't need to use
|
||||
# spree.foo_path in any view rendered from non-spree-namespaced controllers.
|
||||
def method_missing(method, *args, &block)
|
||||
if (method.to_s.end_with?('_path') || method.to_s.end_with?('_url')) && spree.respond_to?(method)
|
||||
spree.send(method, *args)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
%ul.filter_choices
|
||||
- @suppliers.each do |supplier|
|
||||
- if supplier.has_products_on_hand?
|
||||
%li.nowrap= link_to supplier.name, supplier
|
||||
= button_to 'Browse All Suppliers', suppliers_path, :method => :get
|
||||
%li.nowrap= link_to supplier.name, [main_app, supplier]
|
||||
= button_to 'Browse All Suppliers', main_app.suppliers_path, :method => :get
|
||||
|
||||
%h6.filter_name Shop by Distributor
|
||||
%ul.filter_choices
|
||||
@@ -12,10 +12,10 @@
|
||||
- @distributors.each do |distributor|
|
||||
%li.nowrap
|
||||
- if order.nil? || order.can_change_distributor?
|
||||
= link_to distributor.name, select_distributor_path(distributor)
|
||||
= link_to distributor.name, main_app.select_distributor_path(distributor)
|
||||
- elsif order.distributor == distributor
|
||||
= link_to distributor.name, distributor
|
||||
= link_to distributor.name, [main_app, distributor]
|
||||
- else
|
||||
%span.inactive= distributor.name
|
||||
- if current_distributor && order.can_change_distributor?
|
||||
= button_to 'Browse All Distributors', deselect_distributors_path, :method => :get
|
||||
= button_to 'Browse All Distributors', main_app.deselect_distributors_path, :method => :get
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
Openfoodweb::Application.routes.draw do
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
end
|
||||
root :to => 'spree/home#index'
|
||||
|
||||
|
||||
Spree::Core::Engine.routes.prepend do
|
||||
resources :suppliers
|
||||
resources :distributors do
|
||||
get :select, :on => :member
|
||||
get :deselect, :on => :collection
|
||||
end
|
||||
|
||||
# Mount Spree's routes
|
||||
mount Spree::Core::Engine, :at => '/'
|
||||
end
|
||||
|
||||
|
||||
Spree::Core::Engine.routes.prepend do
|
||||
namespace :admin do
|
||||
resources :distributors do
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
@@ -20,5 +22,4 @@ Spree::Core::Engine.routes.prepend do
|
||||
|
||||
match '/admin/reports/orders_and_distributors' => 'admin/reports#orders_and_distributors', :as => "orders_and_distributors_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/group_buys' => 'admin/reports#group_buys', :as => "group_buys_admin_reports", :via => [:get, :post]
|
||||
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
require 'spree/core/current_order'
|
||||
|
||||
describe Spree::DistributorsController do
|
||||
describe DistributorsController do
|
||||
include Spree::Core::CurrentOrder
|
||||
|
||||
before :each do
|
||||
|
||||
Reference in New Issue
Block a user