diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index d7fc63504d..d1be7ef2a2 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -142,8 +142,11 @@ productsApp.controller "AdminBulkProductsCtrl", [ $scope.currentPage = 1 $scope.products = [] $scope.totalCount = -> $scope.products.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) + $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.initialise = (spree_api_key) -> authorise_api_reponse = "" @@ -375,6 +378,10 @@ productsApp.factory "dataFetcher", [ deferred.promise ] +productsApp.filter "rangeArray", -> + return (input,start,end) -> + input.push(i) for i in [start..end] + input filterSubmitProducts = (productsToFilter) -> filteredProducts = [] diff --git a/app/assets/stylesheets/admin/products.css.scss b/app/assets/stylesheets/admin/products.css.scss index 923b6b6867..59eed87aea 100644 --- a/app/assets/stylesheets/admin/products.css.scss +++ b/app/assets/stylesheets/admin/products.css.scss @@ -2,6 +2,16 @@ display: block; } +div.pagination { + div.pagenav { + margin: 0px; + span.first, span.prev, span.next, span.last { + padding: 5px 0px; + display:inline-block; + } + } +} + tbody.odd { tr.product { td { background-color: white; } } tr.variant.odd { td { background-color: lighten(#eff5fc, 3); } } diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index 65aaf6e620..2d6e7dd096 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -33,6 +33,26 @@  per page %br %span Displaying {{firstVisibleProduct()}}-{{lastVisibleProduct()}} of {{totalCount()}} products + %div.pagination{ :class => "seven columns" } + %div.pagenav{ :class => "two columns alpha" } + %span.first + %a{ 'ng-click' => "currentPage = 1", 'ng-show' => "currentPage > 1" } + « First + %span.prev + %a{ 'ng-click' => "currentPage = currentPage - 1", 'ng-show' => "currentPage > 1" } + ‹ Prev + %div.pagenav{ :class => "columns omega" } + %span.page{ 'ng-repeat' => "page in [] | rangeArray:minPage():maxPage()", 'ng-class' => "{current: currentPage==page}" } + %a{ 'ng-click' => "setPage(page)" } + {{page}} + %span{ 'ng-show' => "maxPage() < totalPages()" } ... + %div.pagenav{ :class => "two columns omega" } + %span.next + %a{ 'ng-click' => "currentPage = currentPage + 1", 'ng-show' => "currentPage < totalPages()" } + Next › + %span.last + %a{ 'ng-click' => "currentPage = totalPages()", 'ng-show' => "currentPage < totalPages()" } + Last » %table.index#listing_products.bulk %colgroup %col diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 4dbc029796..8ec49fea8c 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -500,11 +500,17 @@ feature %q{ describe "using pagination controls" do it "shows pagination controls" do + 27.times { FactoryGirl.create(:product) } login_to_admin_section visit '/admin/products/bulk_edit' page.should have_select 'perPage', :selected => '25' + within '.pagination' do + page.should have_text "1 2" + page.should have_text "Next" + page.should have_text "Last" + end end it "allows the number of visible products to be altered" do