diff --git a/app/assets/javascripts/admin/services/dirty_variant_overrides.js.coffee b/app/assets/javascripts/admin/services/dirty_variant_overrides.js.coffee index 72455326a2..82e7772982 100644 --- a/app/assets/javascripts/admin/services/dirty_variant_overrides.js.coffee +++ b/app/assets/javascripts/admin/services/dirty_variant_overrides.js.coffee @@ -24,6 +24,6 @@ angular.module("ofn.admin").factory "DirtyVariantOverrides", ($http) -> save: -> $http method: "POST" - url: "/admin/products/variant_overrides" + url: "/admin/variant_overrides/bulk_update" data: variant_overrides: @all() diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb new file mode 100644 index 0000000000..8d32e62b9d --- /dev/null +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -0,0 +1,17 @@ +require 'open_food_network/spree_api_key_loader' + +module Admin + class VariantOverridesController < ResourceController + include OpenFoodNetwork::SpreeApiKeyLoader + include OrderCyclesHelper + before_filter :load_spree_api_key, only: :index + + def index + @hubs = order_cycle_hub_enterprises(without_validation: true) + @producers = order_cycle_producer_enterprises + @hub_permissions = OpenFoodNetwork::Permissions.new(spree_current_user). + order_cycle_enterprises_per_hub + @variant_overrides = VariantOverride.for_hubs(@hubs) + end + end +end diff --git a/app/controllers/spree/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb index feb64ecf9b..c0e1f8b948 100644 --- a/app/controllers/spree/admin/products_controller_decorator.rb +++ b/app/controllers/spree/admin/products_controller_decorator.rb @@ -49,14 +49,6 @@ Spree::Admin::ProductsController.class_eval do end end - def variant_overrides - @hubs = order_cycle_hub_enterprises(without_validation: true) - @producers = order_cycle_producer_enterprises - @hub_permissions = OpenFoodNetwork::Permissions.new(spree_current_user). - order_cycle_enterprises_per_hub - @variant_overrides = VariantOverride.for_hubs(@hubs) - end - protected def location_after_save diff --git a/app/overrides/spree/admin/shared/_product_sub_menu/add_variant_overrides_tab.html.haml.deface b/app/overrides/spree/admin/shared/_product_sub_menu/add_variant_overrides_tab.html.haml.deface index 88e720fd07..1c61c06a0c 100644 --- a/app/overrides/spree/admin/shared/_product_sub_menu/add_variant_overrides_tab.html.haml.deface +++ b/app/overrides/spree/admin/shared/_product_sub_menu/add_variant_overrides_tab.html.haml.deface @@ -1,4 +1,4 @@ / insert_bottom "[data-hook='admin_product_sub_tabs']" -# Commented out until this feature is ready --#= tab :overrides, url: variant_overrides_admin_products_path, match_path: '/products/variant_overrides' +-#= tab :overrides, url: main_app.admin_variant_overrides_path, match_path: '/variant_overrides' diff --git a/app/views/admin/variant_overrides/_products.html.haml b/app/views/admin/variant_overrides/_products.html.haml index fa6f3fdb32..cf11e8ac5d 100644 --- a/app/views/admin/variant_overrides/_products.html.haml +++ b/app/views/admin/variant_overrides/_products.html.haml @@ -6,6 +6,5 @@ %th Price %th On hand %tbody{ng: {repeat: 'product in products | hubPermissions:hubPermissions:hub.id'}} - = render 'spree/admin/products/variant_overrides/products_product' - = render 'spree/admin/products/variant_overrides/products_variants' - + = render 'admin/variant_overrides/products_product' + = render 'admin/variant_overrides/products_variants' diff --git a/app/views/admin/variant_overrides/index.html.haml b/app/views/admin/variant_overrides/index.html.haml index 0297e6c985..8d7fc4e0b1 100644 --- a/app/views/admin/variant_overrides/index.html.haml +++ b/app/views/admin/variant_overrides/index.html.haml @@ -1,11 +1,11 @@ -= render 'spree/admin/products/variant_overrides/header' -= render 'spree/admin/products/variant_overrides/data' += render 'admin/variant_overrides/header' += render 'admin/variant_overrides/data' %div{ ng: { app: 'ofn.admin', controller: 'AdminVariantOverridesCtrl', init: 'initialise()' } } - = render 'spree/admin/products/variant_overrides/hub_choice' + = render 'admin/variant_overrides/hub_choice' %div{ng: {show: 'hub'}} %h2 {{ hub.name }} - = render 'spree/admin/products/variant_overrides/actions' + = render 'admin/variant_overrides/actions' - = render 'spree/admin/products/variant_overrides/products' + = render 'admin/variant_overrides/products' diff --git a/config/routes.rb b/config/routes.rb index 9cea328411..daccbbbe64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -68,6 +68,8 @@ Openfoodnetwork::Application.routes.draw do get :move_up get :move_down end + + resources :variant_overrides end namespace :api do @@ -118,7 +120,6 @@ Spree::Core::Engine.routes.prepend do match '/admin/reports/orders_and_fulfillment' => 'admin/reports#orders_and_fulfillment', :as => "orders_and_fulfillment_admin_reports", :via => [:get, :post] match '/admin/reports/users_and_enterprises' => 'admin/reports#users_and_enterprises', :as => "users_and_enterprises_admin_reports", :via => [:get, :post] match '/admin/products/bulk_edit' => 'admin/products#bulk_edit', :as => "bulk_edit_admin_products" - match '/admin/products/variant_overrides' => 'admin/products#variant_overrides', :as => "variant_overrides_admin_products" match '/admin/orders/bulk_management' => 'admin/orders#bulk_management', :as => "admin_bulk_order_management" match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post] match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post] diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 0067683a8d..c5ea4d6d0b 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -23,12 +23,12 @@ feature %q{ describe "selecting a hub" do it "displays a list of hub choices" do - visit '/admin/products/variant_overrides' + visit '/admin/variant_overrides' page.should have_select2 'hub_id', options: ['', hub.name, hub2.name] end it "displays the hub" do - visit '/admin/products/variant_overrides' + visit '/admin/variant_overrides' select2_select hub.name, from: 'hub_id' click_button 'Go' @@ -51,7 +51,7 @@ feature %q{ context "with no overrides" do before do - visit '/admin/products/variant_overrides' + visit '/admin/variant_overrides' select2_select hub.name, from: 'hub_id' click_button 'Go' end @@ -73,7 +73,7 @@ feature %q{ let!(:override) { create(:variant_override, variant: variant, hub: hub, price: 77.77, count_on_hand: 11111) } before do - visit '/admin/products/variant_overrides' + visit '/admin/variant_overrides' select2_select hub.name, from: 'hub_id' click_button 'Go' end