mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
BPE pagination works with filtering
This commit is contained in:
@@ -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) ->
|
||||
|
||||
@@ -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)' }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user