summaryrefslogtreecommitdiff
path: root/js/model
diff options
context:
space:
mode:
Diffstat (limited to 'js/model')
-rw-r--r--js/model/packages.js54
1 files changed, 51 insertions, 3 deletions
diff --git a/js/model/packages.js b/js/model/packages.js
index 652d11a..1c61d25 100644
--- a/js/model/packages.js
+++ b/js/model/packages.js
@@ -15,9 +15,11 @@
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
-guix.packages = {};
-(function(packages) {
+
+(function() {
+ var packages = guix.packages = {};
+
packages.Packages = function() {
return m.request({
method: "GET",
@@ -45,9 +47,55 @@ guix.packages = {};
return Sorter;
})();
+ packages.Pager = (function() {
+ function Pager(items, pageSize) {
+ this.pageSize= pageSize;
+ this.pageIndex = 0;
+ this.pages = guix.chunk(items, pageSize);
+ }
+
+ Pager.prototype.currentPage = function() {
+ return this.pages[this.pageIndex];
+ };
+
+ Pager.prototype.pageCount = function() {
+ return this.pages.length;
+ };
+
+ Pager.prototype.isEmpty = function() {
+ return this.pageCount() === 0;
+ };
+
+ Pager.prototype.isFirstPage = function() {
+ return this.pageIndex === 0;
+ };
+
+ Pager.prototype.isLastPage = function() {
+ return this.pageIndex === this.pages.length - 1;
+ };
+
+ Pager.prototype.isCurrentPage = function(i) {
+ return this.pageIndex === i;
+ };
+
+ Pager.prototype.nextPage = function() {
+ this.pageIndex = Math.min(this.pageCount() - 1, this.pageIndex + 1);
+ };
+
+ Pager.prototype.previousPage = function() {
+ this.pageIndex = Math.max(0, this.pageIndex - 1);
+ };
+
+ Pager.prototype.gotoPage = function(page) {
+ this.pageIndex = guix.clamp(page, 0, this.pageCount() -1);
+ };
+
+ return Pager;
+ })();
+
packages.PHASE_NONE = 0;
packages.PHASE_PROMPT = 1;
packages.PHASE_DERIVATION = 2;
packages.PHASE_SUCCESS = 3;
packages.PHASE_ERROR = 4;
-})(guix.packages);
+})();