From 701b5aceb4731ba2feaab388b372a0e72d4cf413 Mon Sep 17 00:00:00 2001 From: Rob H Date: Sat, 18 Jan 2014 14:26:07 +0800 Subject: [PATCH] Add 'All' option to supplier and distributor filters --- .../admin/bulk_order_management.js.coffee | 26 +++++++++++++------ app/assets/stylesheets/admin/orders.css.scss | 3 +++ .../admin/orders/bulk_management.html.haml | 13 ++++++---- .../admin/bulk_order_management_spec.rb | 18 +++++++++++++ .../unit/bulk_order_management_spec.js.coffee | 14 +++++++--- 5 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 app/assets/stylesheets/admin/orders.css.scss diff --git a/app/assets/javascripts/admin/bulk_order_management.js.coffee b/app/assets/javascripts/admin/bulk_order_management.js.coffee index 15f8eee81d..d573dd6197 100644 --- a/app/assets/javascripts/admin/bulk_order_management.js.coffee +++ b/app/assets/javascripts/admin/bulk_order_management.js.coffee @@ -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 \ No newline at end of file +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 +] \ No newline at end of file diff --git a/app/assets/stylesheets/admin/orders.css.scss b/app/assets/stylesheets/admin/orders.css.scss new file mode 100644 index 0000000000..787b76a78d --- /dev/null +++ b/app/assets/stylesheets/admin/orders.css.scss @@ -0,0 +1,3 @@ +.filter_select { + margin-bottom: 10px; +} \ No newline at end of file diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index ea40e2951a..77a9099b26 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -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 diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 755e908f4a..ada2e788b9 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -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 diff --git a/spec/javascripts/unit/bulk_order_management_spec.js.coffee b/spec/javascripts/unit/bulk_order_management_spec.js.coffee index 0347902a1d..746fbe8aee 100644 --- a/spec/javascripts/unit/bulk_order_management_spec.js.coffee +++ b/spec/javascripts/unit/bulk_order_management_spec.js.coffee @@ -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", ->