Add 'All' option to supplier and distributor filters

This commit is contained in:
Rob H
2014-01-18 14:26:07 +08:00
parent 79631ebb8e
commit 701b5aceb4
5 changed files with 57 additions and 17 deletions

View File

@@ -6,9 +6,12 @@ orderManagementModule.config [
provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
]
orderManagementModule.value "blankEnterprise", ->
{ id: "", name: "All" }
orderManagementModule.controller "AdminOrderMgmtCtrl", [
"$scope", "$http", "dataFetcher"
($scope, $http, dataFetcher) ->
"$scope", "$http", "dataFetcher", "blankEnterprise"
($scope, $http, dataFetcher, blankEnterprise) ->
$scope.updateStatusMessage =
text: ""
style: {}
@@ -24,8 +27,12 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
$http.defaults.headers.common["X-Spree-Token"] = spree_api_key
dataFetcher("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").then (data) ->
$scope.suppliers = data
$scope.suppliers.unshift blankEnterprise()
$scope.supplierFilter = $scope.suppliers[0]
dataFetcher("/api/enterprises/managed?template=bulk_index&q[is_distributor_eq]=true").then (data) ->
$scope.distributors = data
$scope.distributors.unshift blankEnterprise()
$scope.distributorFilter = $scope.distributors[0]
$scope.fetchOrders()
else if authorise_api_reponse.hasOwnProperty("error")
$scope.api_error_msg = authorise_api_reponse("error")
@@ -62,9 +69,12 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
break
]
orderManagementModule.filter "selectFilter", ->
return (lineItems,selectedSupplier,selectedDistributor) ->
filtered = []
filtered.push line_item for line_item in lineItems when (selectedSupplier == undefined || line_item.supplier == selectedSupplier) &&
(selectedDistributor == undefined || line_item.order.distributor == selectedDistributor)
filtered
orderManagementModule.filter "selectFilter", [
"blankEnterprise"
(blankEnterprise) ->
return (lineItems,selectedSupplier,selectedDistributor) ->
filtered = []
filtered.push line_item for line_item in lineItems when (angular.equals(selectedSupplier,blankEnterprise()) || line_item.supplier == selectedSupplier) &&
(angular.equals(selectedDistributor,blankEnterprise()) || line_item.order.distributor == selectedDistributor)
filtered
]

View File

@@ -0,0 +1,3 @@
.filter_select {
margin-bottom: 10px;
}

View File

@@ -7,11 +7,14 @@
%div{ 'ng-show' => '!spree_api_key_ok' }
{{ api_error_msg }}
.filter_selects{ :class => "four columns alpha" }
.supplier_filter{ :class => "four columns alpha" }
%select.select2{ :class => "three columns alpha", :name => 'supplier_filter', 'ng-model' => 'supplierFilter', 'ng-options' => 's.name for s in suppliers'}
.distributor_filter{ :class => "four columns alpha" }
%select.select2{ :class => "three columns alpha", :name => 'distributor_filter', 'ng-model' => 'distributorFilter', 'ng-options' => 'd.name for d in distributors'}
.filter_select{ :class => "four columns alpha" }
Producer
%br
%select.select2{ :class => "four columns alpha", :id => 'supplier_filter', 'ng-model' => 'supplierFilter', 'ng-options' => 's.name for s in suppliers' }
.filter_select{ :class => "four columns alpha" }
Hub
%br
%select.select2{ :class => "four columns alpha", :id => 'distributor_filter', 'ng-model' => 'distributorFilter', 'ng-options' => 'd.name for d in distributors'}
%table.index#listing_orders.bulk
%thead

View File

@@ -108,6 +108,15 @@ feature %q{
page.should_not have_selector "td.id", text: li2.id.to_s, visible: true
end
it "displays all line items when 'All' is selected from supplier filter" do
select s1.name, from: "supplier_filter"
page.should have_selector "td.id", text: li1.id.to_s, visible: true
page.should_not have_selector "td.id", text: li2.id.to_s, visible: true
select "All", from: "supplier_filter"
page.should have_selector "td.id", text: li1.id.to_s, visible: true
page.should have_selector "td.id", text: li2.id.to_s, visible: true
end
it "displays a select box for distributors, which filters line items by the selected distributor" do
page.should have_select "distributor_filter", with_options: [d1.name,d2.name]
page.should have_selector "td.id", text: li1.id.to_s, visible: true
@@ -116,6 +125,15 @@ feature %q{
page.should have_selector "td.id", text: li1.id.to_s, visible: true
page.should_not have_selector "td.id", text: li2.id.to_s, visible: true
end
it "displays all line items when 'All' is selected from distributor filter" do
select d1.name, from: "distributor_filter"
page.should have_selector "td.id", text: li1.id.to_s, visible: true
page.should_not have_selector "td.id", text: li2.id.to_s, visible: true
select "All", from: "distributor_filter"
page.should have_selector "td.id", text: li1.id.to_s, visible: true
page.should have_selector "td.id", text: li2.id.to_s, visible: true
end
end
end
end

View File

@@ -13,15 +13,21 @@ describe "AdminOrderMgmtCtrl", ->
describe "loading data upon initialisation", ->
it "gets a list of suppliers and a list of distributors and then calls fetchOrders", ->
returnedSuppliers = ["list of suppliers"]
returnedDistributors = ["list of distributors"]
httpBackend.expectGET("/api/users/authorise_api?token=api_key").respond success: "Use of API Authorised"
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").respond "list of suppliers"
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_distributor_eq]=true").respond "list of distributors"
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").respond returnedSuppliers
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_distributor_eq]=true").respond returnedDistributors
spyOn(scope, "fetchOrders").andReturn "nothing"
spyOn(returnedSuppliers, "unshift")
spyOn(returnedDistributors, "unshift")
scope.initialise "api_key"
httpBackend.flush()
expect(scope.suppliers).toEqual "list of suppliers"
expect(scope.distributors).toEqual "list of distributors"
expect(scope.suppliers).toEqual ["list of suppliers"]
expect(scope.distributors).toEqual ["list of distributors"]
expect(scope.fetchOrders.calls.length).toEqual 1
expect(returnedSuppliers.unshift.calls.length).toEqual 1
expect(returnedDistributors.unshift.calls.length).toEqual 1
expect(scope.spree_api_key_ok).toEqual true
describe "fetching orders", ->