WIP: Add basic page nav controls to BPE

This commit is contained in:
Rob H
2013-12-23 09:22:31 +08:00
parent 06995bd3c6
commit ffbfbffb28
4 changed files with 43 additions and 0 deletions

View File

@@ -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 = []

View File

@@ -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); } }

View File

@@ -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&nbsp;&rsaquo;
%span.last
%a{ 'ng-click' => "currentPage = totalPages()", 'ng-show' => "currentPage < totalPages()" }
Last&nbsp;&raquo;
%table.index#listing_products.bulk
%colgroup
%col

View File

@@ -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