This commit is contained in:
Tobe O 2017-05-27 10:23:51 -04:00
parent 83cdcf5083
commit b16472fcd8
4 changed files with 23 additions and 4 deletions

View file

@ -1,5 +1,5 @@
# paginate # paginate
[![version 1.0.0+1](https://img.shields.io/badge/pub-v1.0.0+1-brightgreen.svg)](https://pub.dartlang.org/packages/angel_paginate) [![version 1.0.0+2](https://img.shields.io/badge/pub-v1.0.0+2-brightgreen.svg)](https://pub.dartlang.org/packages/angel_paginate)
[![build status](https://travis-ci.org/angel-dart/paginate.svg)](https://travis-ci.org/angel-dart/paginate) [![build status](https://travis-ci.org/angel-dart/paginate.svg)](https://travis-ci.org/angel-dart/paginate)
![coverage: 100%](https://img.shields.io/badge/coverage-100%25-green.svg) ![coverage: 100%](https://img.shields.io/badge/coverage-100%25-green.svg)
@ -90,3 +90,6 @@ in the `paginate` call.
Ex. `http://mysite.com/api/todos?$limit=25` Ex. `http://mysite.com/api/todos?$limit=25`
You can use these pagination functions to provide powerful search experiences on your websites. You can use these pagination functions to provide powerful search experiences on your websites.
**NOTE**: If the paginated data is empty, expect `start_index` and `end_index`
to both be `-1`.

View file

@ -55,7 +55,7 @@ class Paginator<T> {
currentPage: _page + 1, currentPage: _page + 1,
previousPage: _page <= 0 ? -1 : _page, previousPage: _page <= 0 ? -1 : _page,
nextPage: _page >= last - 1 ? -1 : _page + 2, nextPage: _page >= last - 1 ? -1 : _page + 2,
startIndex: offset, startIndex: it.isEmpty ? -1 : offset,
endIndex: offset + it.length - 1, endIndex: offset + it.length - 1,
itemsPerPage: itemsPerPage, itemsPerPage: itemsPerPage,
total: len); total: len);

View file

@ -1,5 +1,5 @@
name: angel_paginate name: angel_paginate
version: 1.0.0+1 version: 1.0.0+2
description: Platform-agnostic pagination library, with custom support for the Angel framework. description: Platform-agnostic pagination library, with custom support for the Angel framework.
author: Tobe O <thosakwe@gmail.com> author: Tobe O <thosakwe@gmail.com>
homepage: https://github.com/angel-dart/paginate homepage: https://github.com/angel-dart/paginate

View file

@ -110,4 +110,20 @@ main() {
paginator.next(); paginator.next();
} while(paginator.canGoForward); } while(paginator.canGoForward);
}); });
test('empty collection', () {
var paginator = new Paginator([]);
var page = paginator.current;
print(page.toJson());
expect(page.total, 0);
expect(page.previousPage, -1);
expect(page.nextPage, -1);
expect(page.currentPage, 1);
expect(page.startIndex, -1);
expect(page.endIndex, -1);
expect(page.data, isEmpty);
expect(paginator.canGoBack, isFalse);
expect(paginator.canGoForward, isFalse);
});
} }