From 39165a798408bc76e692e7c8a546e93fd550231d Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 13 Aug 2014 18:06:19 -0400 Subject: Add package sorting. * guix-packages.js (guix.Sorter): New data type. (guix.Soter.prototype.sort): New method. (guix.controller): Sort by name by default. --- js/guix-packages.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'js') diff --git a/js/guix-packages.js b/js/guix-packages.js index 3a3518a..1f57f1e 100644 --- a/js/guix-packages.js +++ b/js/guix-packages.js @@ -35,6 +35,17 @@ guix.Packages = function() { return m.request({ method: "GET", url: "packages.json" }); }; +guix.Sorter = function(field, isDescending) { + this.field = field; + this.isDescending = _.isUndefined(isDescending) ? false : isDescending; +}; + +guix.Sorter.prototype.sort = function(array) { + var result = _.sortBy(array, this.field); + + return this.isDescending ? result.reverse() : result; +}; + guix.controller = function() { var self = this; @@ -43,6 +54,7 @@ guix.controller = function() { this.currentPageIndex = 0; this.pageSize = 20; this.searchTerm = m.prop(""); + this.sorter = new guix.Sorter("name"); // All packages are visible initially this.packages.then(function(packages) { -- cgit v1.2.3