WIP: Extract variant overrides to own controller - route, controller, views

This commit is contained in:
Rohan Mitchell
2014-12-10 12:25:57 +11:00
parent 9ee44e9aef
commit 531b35bbc6
8 changed files with 32 additions and 23 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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'

View File

@@ -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'

View File

@@ -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'

View File

@@ -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]

View File

@@ -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