Commit b2a90531 authored by Robert Knight's avatar Robert Knight

Sort groups in lexicographical order

Card 87
parent f49b6d3c
......@@ -23,6 +23,15 @@ function GroupsListController($scope) {
$scope.shouldShowShareLink = function (groupId) {
return $scope.expandedGroupId === groupId;
}
$scope.sortedGroups = function () {
return $scope.groups.all().concat().sort(function (a, b) {
if (a.public !== b.public) {
return a.public ? -1 : 1;
}
return a.name.localeCompare(b.name);
});
}
}
/**
......
......@@ -31,6 +31,27 @@ describe('GroupsListController', function () {
assert.equal($scope.shouldShowShareLink('group-a'), false);
assert.equal($scope.shouldShowShareLink('group-b'), true);
});
it('sorts groups', function () {
$scope.groups = {
all: function () {
return [{
id: 'c',
name: 'Zebrafish Study Group'
},{
id: 'a',
name: 'Antimatter Research'
},{
public: true
}];
}
};
var sorted = $scope.sortedGroups();
assert.ok(sorted[0].public);
assert.equal(sorted[1].name, 'Antimatter Research');
assert.equal(sorted[2].name, 'Zebrafish Study Group');
});
});
// returns true if a jQuery-like element has
......
......@@ -10,7 +10,7 @@
<i class="h-icon-arrow-drop-down"></i>
</span>
<ul class="dropdown-menu pull-right" role="menu">
<li ng-repeat="group in groups.all()">
<li ng-repeat="group in sortedGroups()">
<div ng-class="{'group-item': true, selected: group.id == groups.focused().id}"
ng-click="groups.focus(group.id)">
<!-- the group icon !-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment