add pagination and filter panel to users view

This commit is contained in:
Johannes Zellner
2019-01-15 13:30:37 +01:00
parent a8b79055ef
commit 342538358d
3 changed files with 114 additions and 60 deletions

View File

@@ -4,6 +4,7 @@
/* global Clipboard:false */
/* global asyncForEach:false */
/* global asyncSeries:false */
/* global $:false */
angular.module('Application').controller('UsersController', ['$scope', '$location', '$timeout', 'Client', function ($scope, $location, $timeout, Client) {
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
@@ -16,6 +17,15 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$scope.config = Client.getConfig();
$scope.userInfo = Client.getUserInfo();
$scope.currentPage = 1;
$scope.pageItemCount = [
{ name: 'Show 20 per page', value: 20 },
{ name: 'Show 50 per page', value: 50 },
{ name: 'Show 100 per page', value: 100 }
];
$scope.pageItems = $scope.pageItemCount[0];
$scope.userRefreshBusy = false;
$scope.groupMembers = function (group) {
return group.userIds.filter(function (uid) { return !!$scope.usersById[uid]; }).map(function (uid) { return $scope.usersById[uid].username || $scope.usersById[uid].email; }).join(' ');
};
@@ -442,7 +452,7 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
function getUsers(callback) {
var users = [ ];
Client.getUsers(function (error, results) {
Client.getUsers($scope.currentPage, $scope.pageItems.value, function (error, results) {
if (error) return console.error(error);
asyncForEach(results, function (result, iteratorDone) {
@@ -479,6 +489,23 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
});
}
function refreshUsers() {
$scope.userRefreshBusy = true;
getUsers(function (error, result) {
if (error) return console.error('Unable to get user listing.', error);
angular.copy(result, $scope.users);
$scope.usersById = { };
for (var i = 0; i < result.length; i++) {
$scope.usersById[result[i].id] = result[i];
}
$scope.ready = true;
$scope.userRefreshBusy = false;
});
}
function refresh() {
getGroups(function (error, result) {
if (error) return console.error('Unable to get group listing.', error);
@@ -489,20 +516,26 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$scope.groupsById[result[i].id] = result[i];
}
getUsers(function (error, result) {
if (error) return console.error('Unable to get user listing.', error);
angular.copy(result, $scope.users);
$scope.usersById = { };
for (var i = 0; i < result.length; i++) {
$scope.usersById[result[i].id] = result[i];
}
$scope.ready = true;
});
refreshUsers();
});
}
$scope.showNextPage = function () {
$scope.currentPage++;
refreshUsers();
};
$scope.showPrevPage = function () {
if ($scope.currentPage > 1) $scope.currentPage--;
else $scope.currentPage = 1;
refreshUsers();
};
$scope.updateFilter = function (fresh) {
if (fresh) $scope.currentPage = 1;
refreshUsers();
};
Client.onReady(refresh);
// setup all the dialog focus handling