summaryrefslogtreecommitdiff
path: root/js/controller
diff options
context:
space:
mode:
Diffstat (limited to 'js/controller')
-rw-r--r--js/controller/packages.js47
1 files changed, 15 insertions, 32 deletions
diff --git a/js/controller/packages.js b/js/controller/packages.js
index db94d72..89f01e9 100644
--- a/js/controller/packages.js
+++ b/js/controller/packages.js
@@ -15,14 +15,19 @@
// License along with this program. If not, see
// <http://www.gnu.org/licenses/>.
-(function(packages) {
+(function() {
+ var packages = guix.packages;
+
packages.controller = (function() {
+ var PAGE_SIZE = 20;
+
+ function Pager(items) {
+ return new packages.Pager(items, PAGE_SIZE);
+ }
+
function controller() {
var self = this;
- this.pages = m.prop([]);
- this.currentPageIndex = 0;
- this.pageSize = 20;
this.searchTerm = m.prop("");
this.columns = [
{ header: "Name", sortField: "name" },
@@ -43,40 +48,20 @@
}
];
this.sorter = m.prop(new packages.Sorter("name"));
+ this.pager = m.prop(Pager([]));
this.phase = m.prop(packages.PHASE_NONE);
this.selectedPackage = m.prop(null);
this.packages = packages.Packages()
.then(function(packages) {
// All packages are visible initially
- self.pages(self.paginate(packages, self.pageSize));
+ self.pager(Pager(packages));
})
.then(m.redraw);
};
-
- controller.prototype.paginate = function(array, pageSize) {
- return guix.chunk(this.sorter().sort(array), pageSize);
- };
-
- controller.prototype.currentPage = function() {
- return this.pages()[this.currentPageIndex] || [];
- };
-
- controller.prototype.isFirstPage = function() {
- return this.currentPageIndex === 0;
- };
-
- controller.prototype.isLastPage = function() {
- return this.currentPageIndex === this.pages().length - 1;
- };
-
- controller.prototype.isCurrentPage = function(i) {
- return this.currentPageIndex === i;
- };
-
controller.prototype.packageCount = function() {
- return this.pages().reduce(function(memo, page) {
+ return this.pager().pages.reduce(function(memo, page) {
return memo + page.length;
}, 0);
};
@@ -84,12 +69,10 @@
controller.prototype.doSearch = function() {
var regexp = new RegExp(this.searchTerm(), "i");
- this.pages(this.paginate(this.packages().filter(function(package) {
+ this.pager(Pager(this.packages().filter(function(package) {
return regexp.test(package.name) ||
regexp.test(package.synopsis);
- }), this.pageSize));
- // Reset pagination
- this.currentPageIndex = 0;
+ })));
};
controller.prototype.sortBy = function(field) {
@@ -122,4 +105,4 @@
return controller;
})();
-})(guix.packages);
+})();