Pagination Directive for clients and roles in admin console

This commit is contained in:
Mohit Suman 2016-09-07 14:50:44 +05:30 committed by Stan Silvert
parent c4f0053dd9
commit 0e33e4035f
6 changed files with 102 additions and 8 deletions

View file

@ -2678,3 +2678,44 @@ module.directive('kcOnReadFile', function ($parse) {
}
};
});
module.controller('PagingCtrl', function ($scope) {
$scope.isLastPage = function()
{
if ($scope.currentPage === $scope.numberOfPages) {
return true;
}
return false;
};
$scope.isFirstPage = function()
{
if ($scope.currentPage === 1) {
return true;
}
return false;
};
});
module.directive('kcPaging', function () {
return {
scope: {
currentPage: '=',
numberOfPages: '='
},
restrict: 'A',
replace: true,
controller: 'PagingCtrl',
templateUrl: resourceUrl + '/templates/kc-paging.html'
}
});
module.filter('startFrom', function () {
return function (input, start) {
if (input) {
start = +start;
return input.slice(start);
}
return [];
};
});

View file

@ -731,9 +731,19 @@ module.controller('ClientImportCtrl', function($scope, $location, $upload, realm
});
module.controller('ClientListCtrl', function($scope, realm, clients, Client, serverInfo, $route, Dialog, Notifications) {
module.controller('ClientListCtrl', function($scope, realm, clients, Client, serverInfo, $route, Dialog, Notifications, filterFilter) {
$scope.realm = realm;
$scope.clients = clients;
$scope.currentPage = 1;
$scope.pageSize = 20;
$scope.numberOfPages = Math.ceil($scope.clients.length/$scope.pageSize);
$scope.$watch('search', function (newVal, oldVal) {
$scope.filtered = filterFilter($scope.clients, newVal);
$scope.totalItems = $scope.filtered.length;
$scope.numberOfPages = Math.ceil($scope.totalItems/$scope.pageSize);
$scope.currentPage = 1;
}, true);
$scope.removeClient = function(client) {
Dialog.confirmDelete(client.clientId, 'client', function() {

View file

@ -1223,9 +1223,19 @@ module.controller('RealmRevocationCtrl', function($scope, Realm, RealmPushRevoca
});
module.controller('RoleListCtrl', function($scope, $route, Dialog, Notifications, realm, roles, RoleById) {
module.controller('RoleListCtrl', function($scope, $route, Dialog, Notifications, realm, roles, RoleById, filterFilter) {
$scope.realm = realm;
$scope.roles = roles;
$scope.currentPage = 1;
$scope.pageSize = 20;
$scope.numberOfPages = Math.ceil($scope.roles.length/$scope.pageSize);
$scope.$watch('searchQuery', function (newVal, oldVal) {
$scope.filtered = filterFilter($scope.roles, newVal);
$scope.totalItems = $scope.filtered.length;
$scope.numberOfPages = Math.ceil($scope.totalItems/$scope.pageSize);
$scope.currentPage = 1;
}, true);
$scope.removeRole = function (role) {
Dialog.confirmDelete(role.name, 'role', function () {

View file

@ -32,8 +32,15 @@
<th colspan="3">{{:: 'actions' | translate}}</th>
</tr>
</thead>
<tfoot data-ng-hide="(clients | filter:search).length == 0">
<tr>
<td class="kc-action-cell" colspan="6">
<div kc-paging current-page='currentPage' number-of-pages='numberOfPages'></div>
</td>
</tr>
</tfoot>
<tbody>
<tr ng-repeat="client in clients | filter:search | orderBy:'clientId'">
<tr ng-repeat="client in clients | filter:search | orderBy:'clientId' | startFrom:(currentPage-1)*pageSize | limitTo:pageSize">
<td><a href="#/realms/{{realm.realm}}/clients/{{client.id}}">{{client.clientId}}</a></td>
<td translate="{{client.enabled}}"></td>
<td ng-class="{'text-muted': !client.baseUrl}">
@ -45,8 +52,8 @@
<td class="kc-action-cell" data-ng-show="access.manageClients" data-ng-click="removeClient(client)">{{:: 'delete' | translate}}</td>
</tr>
<tr data-ng-show="(clients | filter:search).length == 0">
<td class="text-muted" colspan="3" data-ng-show="search.clientId">{{:: 'no-results' | translate}}</td>
<td class="text-muted" colspan="3" data-ng-hide="search.clientId">{{:: 'no-clients-available' | translate}}</td>
<td class="text-muted" colspan="4" data-ng-show="search.clientId">{{:: 'no-results' | translate}}</td>
<td class="text-muted" colspan="4" data-ng-hide="search.clientId">{{:: 'no-clients-available' | translate}}</td>
</tr>
</tbody>
</table>

View file

@ -33,8 +33,15 @@
<th colspan="2">{{:: 'actions' | translate}}</th>
</tr>
</thead>
<tfoot data-ng-hide="(roles | filter:{name: searchQuery}).length == 0">
<tr>
<td class="kc-action-cell" colspan="6">
<div kc-paging current-page='currentPage' number-of-pages='numberOfPages'></div>
</td>
</tr>
</tfoot>
<tbody>
<tr ng-repeat="role in roles | orderBy:'name' | filter:{name: searchQuery}">
<tr ng-repeat="role in roles | filter:{name: searchQuery} | orderBy:'name'| startFrom:(currentPage-1)*pageSize | limitTo:pageSize">
<td><a href="#/realms/{{realm.realm}}/roles/{{role.id}}">{{role.name}}</a></td>
<td translate="{{role.composite}}"></td>
<td>{{role.description}}</td>
@ -42,8 +49,8 @@
<td class="kc-action-cell" data-ng-click="removeRole(role)">{{:: 'delete' | translate}}</td>
</tr>
<tr data-ng-show="(roles | filter:{name: searchQuery}).length == 0">
<td class="text-muted" colspan="3" data-ng-show="searchQuery">{{:: 'no-results' | translate}}</td>
<td class="text-muted" colspan="3" data-ng-hide="searchQuery">{{:: 'no-realm-roles-available' | translate}}</td>
<td class="text-muted" colspan="4" data-ng-show="searchQuery">{{:: 'no-results' | translate}}</td>
<td class="text-muted" colspan="4" data-ng-hide="searchQuery">{{:: 'no-realm-roles-available' | translate}}</td>
</tr>
</tbody>
</table>

View file

@ -0,0 +1,19 @@
<div class="pull-right">
<ul class="pagination">
<li ng-class="{disabled: currentPage === 1}" ng-click="currentPage=1">
<span class="i fa fa-angle-double-left"></span>
</li>
<li ng-class="{disabled: currentPage === 1}" ng-click="isFirstPage() || (currentPage=currentPage-1)">
<span class="i fa fa-angle-left"></span>
</li>
<li>
<span style="padding: 1px 15px 0;"><input ng-model="currentPage" ng-max="numberOfPages" class="kc-pagination"> of&nbsp;&nbsp;{{numberOfPages}}</span>
</li>
<li ng-class="{disabled: currentPage === numberOfPages}" ng-click="isLastPage() || (currentPage=currentPage+1)">
<span class="i fa fa-angle-right" ></span>
</li>
<li ng-class="{disabled: currentPage === numberOfPages}" ng-click="currentPage=numberOfPages">
<span class="i fa fa-angle-double-right"></span>
</li>
</ul>
</div>