Only show products that the chosen hub can add to an order cycle

This commit is contained in:
Rohan Mitchell
2014-11-26 11:51:52 +11:00
parent 500b5ce347
commit a3a3832c8d
4 changed files with 44 additions and 39 deletions

View File

@@ -1,9 +1,9 @@
angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, hubs, producers) ->
angular.module("ofn.admin").controller "AdminOverrideVariantsCtrl", ($scope, Indexer, SpreeApiAuth, PagedFetcher, hubs, producers, hubPermissions) ->
$scope.hubs = hubs
$scope.hub = null
$scope.products = []
$scope.producers = Indexer.index producers
$scope.hubPermissions = hubPermissions
$scope.initialise = ->
SpreeApiAuth.authorise()

View File

@@ -0,0 +1,4 @@
angular.module("ofn.admin").filter "hubPermissions", ($filter) ->
return (products, hubPermissions, hub_id) ->
return [] if !hub_id
return $filter('filter')(products, ((product) -> hubPermissions[hub_id].indexOf(product.producer_id) > -1), true)

View File

@@ -6,7 +6,7 @@
%th Price
%th On hand
%tbody
%tr{ng: {repeat: 'product in products'}}
%tr{ng: {repeat: 'product in products | hubPermissions:hubPermissions:hub.id'}}
%td {{ producers[product.producer_id].name }}
%td {{ product.name }}
%td {{ product.price }}

View File

@@ -9,10 +9,6 @@ feature %q{
include AuthenticationWorkflow
include WebHelper
before do
login_to_admin_section
end
use_short_wait
let!(:hub) { create(:distributor_enterprise) }
@@ -20,41 +16,46 @@ feature %q{
let!(:er) { create(:enterprise_relationship, parent: producer, child: hub,
permissions_list: [:add_to_order_cycle]) }
describe "selecting a hub" do
it "displays a list of hub choices" do
visit '/admin/products/override_variants'
page.should have_select2 'hub_id', options: ['', hub.name]
context "as an enterprise user" do
let(:user) { create_enterprise_user enterprises: [hub, producer] }
before { quick_login_as user }
describe "selecting a hub" do
it "displays a list of hub choices" do
visit '/admin/products/override_variants'
page.should have_select2 'hub_id', options: ['', hub.name]
end
it "displays the hub" do
visit '/admin/products/override_variants'
select2_select hub.name, from: 'hub_id'
click_button 'Go'
page.should have_selector 'h2', text: hub.name
end
end
it "displays the hub" do
visit '/admin/products/override_variants'
select2_select hub.name, from: 'hub_id'
click_button 'Go'
context "when a hub is selected" do
let!(:product) { create(:simple_product, supplier: producer, price: 1.23, on_hand: 12) }
let!(:producer2) { create(:supplier_enterprise) }
let!(:product2) { create(:simple_product, supplier: producer2, price: 1.23, on_hand: 12) }
page.should have_selector 'h2', text: hub.name
before do
visit '/admin/products/override_variants'
select2_select hub.name, from: 'hub_id'
click_button 'Go'
end
it "displays the list of products" do
page.should have_table_row ['PRODUCER', 'PRODUCT', 'PRICE', 'ON HAND']
page.should have_table_row [producer.name, product.name, '1.23', '12']
end
it "filters the products to those the hub can add to an order cycle" do
page.should_not have_table_row [producer2.name, product2.name, '1.23', '12']
end
it "products values are affected by overrides"
end
end
context "when a hub is selected" do
let!(:product) { create(:simple_product, supplier: producer, price: 1.23, on_hand: 12) }
let!(:producer2) { create(:supplier_enterprise) }
let!(:product2) { create(:simple_product, supplier: producer2, price: 1.23, on_hand: 12) }
before do
visit '/admin/products/override_variants'
select2_select hub.name, from: 'hub_id'
click_button 'Go'
end
it "displays the list of products" do
page.should have_table_row ['PRODUCER', 'PRODUCT', 'PRICE', 'ON HAND']
page.should have_table_row [producer.name, product.name, '1.23', '12']
end
it "filters the products to those the hub can add to an order cycle" do
page.should_not have_table_row [producer2.name, product2.name, '1.23', '12']
end
it "products values are affected by overrides"
end
end