feat(super-user): paginate orgs

This commit is contained in:
EvB 2016-12-20 18:29:30 -05:00
parent d25051a953
commit 577db4abc3
2 changed files with 52 additions and 6 deletions

View file

@ -10,7 +10,7 @@
})
}]);
function SuperuserCtrl($scope, ApiService, Features, UserService, ContainerService, AngularPollChannel, CoreDialog) {
function SuperuserCtrl($scope, ApiService, Features, UserService, ContainerService, AngularPollChannel, CoreDialog, TableService) {
if (!Features.SUPER_USERS) {
return;
}
@ -31,6 +31,14 @@
$scope.serviceKeysActive = false;
$scope.globalMessagesActive = false;
$scope.manageUsersActive = false;
$scope.orderedOrgs = [];
$scope.orgsPerPage = 10;
$scope.options = {
'predicate': 'name',
'reverse': false,
'filter': null,
'page': 0,
}
$scope.loadMessageOfTheDay = function () {
$scope.globalMessagesActive = true;
@ -106,9 +114,16 @@
$scope.loadOrganizationsInternal();
};
var sortOrgs = function() {
if (!$scope.organizations) {return;}
$scope.orderedOrgs = TableService.buildOrderedItems($scope.organizations, $scope.options,
['name', 'email'], []);
};
$scope.loadOrganizationsInternal = function() {
$scope.organizationsResource = ApiService.listAllOrganizationsAsResource().get(function(resp) {
$scope.organizations = resp['organizations'];
sortOrgs();
return $scope.organizations;
});
};
@ -117,6 +132,21 @@
$scope.manageUsersActive = true;
};
$scope.tablePredicateClass = function(name, predicate, reverse) {
if (name != predicate) {
return '';
}
return 'current ' + (reverse ? 'reversed' : '');
};
$scope.orderBy = function(predicate) {
if (predicate == $scope.options.predicate) {
$scope.options.reverse = !$scope.options.reverse;
return;
}
$scope.options.reverse = false;
$scope.options.predicate = predicate;
};
$scope.askDeleteOrganization = function(org) {
bootbox.confirm('Are you sure you want to delete this organization? Its data will be deleted with it.',
function(result) {
@ -185,5 +215,9 @@
// Load the initial status.
$scope.checkStatus();
$scope.$watch('options.predicate', sortOrgs);
$scope.$watch('options.reverse', sortOrgs);
$scope.$watch('options.filter', sortOrgs);
}
}());