From c6222f2180cfb964a036335b9275dbd607e8f232 Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 2 Jan 2014 15:22:10 +0800 Subject: [PATCH] BPE pagination works with filtering --- .../admin/bulk_product_update.js.coffee | 7 +++-- .../spree/admin/products/bulk_edit.html.haml | 4 +-- .../admin/bulk_product_update_spec.rb | 28 +++++++++++++++++-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 63261a7df4..9c8119ec16 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -141,7 +141,8 @@ productsApp.controller "AdminBulkProductsCtrl", [ $scope.perPage = 25 $scope.currentPage = 1 $scope.products = [] - $scope.totalCount = -> $scope.products.length + $scope.filteredProducts = [] + $scope.totalCount = -> $scope.filteredProducts.length $scope.totalPages = -> Math.ceil($scope.totalCount()/$scope.perPage) $scope.firstVisibleProduct = -> ($scope.currentPage-1)*$scope.perPage+1 $scope.lastVisibleProduct = -> Math.min($scope.totalCount(),$scope.currentPage*$scope.perPage) @@ -149,7 +150,9 @@ productsApp.controller "AdminBulkProductsCtrl", [ $scope.minPage = -> Math.max(1,Math.min($scope.totalPages()-4,$scope.currentPage-2)) $scope.maxPage = -> Math.min($scope.totalPages(),Math.max(5,$scope.currentPage+2)) - $scope.$watch 'perPage', (newVal, oldVal) -> + $scope.$watch -> + $scope.totalPages() + , (newVal, oldVal) -> $scope.currentPage = $scope.totalPages() if newVal != oldVal && $scope.totalPages() < $scope.currentPage $scope.initialise = (spree_api_key) -> diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index 2d6e7dd096..6e4d626e69 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -19,7 +19,7 @@ %div %div.options Filter Results: - %input.search{ 'ng-model' => 'query', :type => 'text', 'placeholder' => 'Search Value' } + %input.search{ 'ng-model' => 'query', :name => "quick_filter", :type => 'text', 'placeholder' => 'Search Value' } %input{ :type => 'button', :value => 'Toggle Columns', 'ofn-toggle-column-list' => true } %div{ :style => 'display: none;' } %ul.column-list{ style: 'border: 1px solid darkgray; background-color: white;' } @@ -74,7 +74,7 @@ %th{ 'ng-show' => 'columns.on_hand.visible' } On Hand %th{ 'ng-show' => 'columns.available_on.visible' } Av. On %th.actions - %tbody{ 'ng-repeat' => 'product in products | filter:query', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", 'ng-show' => "$index >= perPage*(currentPage-1) && $index < perPage*currentPage" } + %tbody{ 'ng-repeat' => 'product in filteredProducts = (products | filter:query)', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", 'ng-show' => "$index >= perPage*(currentPage-1) && $index < perPage*currentPage" } %tr.product %td.left-actions %a{ 'ofn-toggle-variants' => 'true', :class => "view-variants icon-chevron-right", 'ng-show' => 'hasVariants(product)' } diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 5ea1a3ebe1..1b9413aea5 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -565,8 +565,9 @@ feature %q{ page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page2product" }.should == true end - it "moves the user to the last available page when changing perPage value causes user to become orphaned" do - 51.times { FactoryGirl.create(:product) } + it "moves the user to the last available page when changing the number of pages in any way causes user to become orphaned" do + 50.times { FactoryGirl.create(:product) } + FactoryGirl.create(:product, :name => "fancy_product_name") login_to_admin_section visit '/admin/products/bulk_edit' @@ -575,7 +576,28 @@ feature %q{ click_link "3" select '50', :from => 'perPage' page.first("div.pagenav span.page.current").should have_text "2" - page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 1 + page.all("input[name='product_name']", :visible => true).length.should == 1 + + select '25', :from => 'perPage' + fill_in "quick_filter", :with => "fancy_product_name" + page.first("div.pagenav span.page.current").should have_text "1" + page.all("input[name='product_name']", :visible => true).length.should == 1 + end + + it "paginates the filtered product list rather than all products" do + 25.times { FactoryGirl.create(:product, :name => "product_name") } + 3.times { FactoryGirl.create(:product, :name => "test_product_name") } + login_to_admin_section + + visit '/admin/products/bulk_edit' + + select '25', :from => 'perPage' + page.should have_text "1 2" + fill_in "quick_filter", :with => "test_product_name" + page.all("input[name='product_name']", :visible => true).length.should == 3 + page.all("input[name='product_name']", :visible => true).all?{ |e| e.value == "test_product_name" }.should == true + page.should_not have_text "1 2" + page.should have_text "1" end end end