summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-08-13 18:06:19 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-08-13 18:06:19 -0400
commit39165a798408bc76e692e7c8a546e93fd550231d (patch)
tree85ad240485e12f99cb610c973e1f5b9fee1f1b92
parent46015f1a8482b5f605c8817befad4541f1046dde (diff)
Add package sorting.
* guix-packages.js (guix.Sorter): New data type. (guix.Soter.prototype.sort): New method. (guix.controller): Sort by name by default.
-rw-r--r--js/guix-packages.js12
1 files changed, 12 insertions, 0 deletions
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) {