Skip to content

Commit

Permalink
Merge pull request #1000 from ushahidi/master
Browse files Browse the repository at this point in the history
Master to production -release
  • Loading branch information
rowasc authored Feb 19, 2018
2 parents d600d19 + 11ec498 commit d9e0e4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions app/settings/users/users.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function (
};

$scope.itemsPerPageChanged = function (count) {
$scope.itemsPerPage = count;
$scope.pagination.itemsPerPage = count;
$scope.getUsersForPagination();
};

Expand All @@ -131,14 +131,14 @@ function (
// --- start: definitions
$scope.getUsersForPagination = function () {
var filters = _.extend({
offset: ($scope.currentPage - 1) * $scope.itemsPerPage,
limit: $scope.itemsPerPage,
offset: ($scope.pagination.currentPage - 1) * $scope.pagination.itemsPerPage,
limit: $scope.pagination.itemsPerPage,
orderby: 'realname'
}, $scope.filters);
UserEndpoint.queryFresh(filters).$promise.then(function (usersResponse) {
$scope.users = usersResponse.results;
$scope.totalItems = usersResponse.total_count;
$scope.showPagination = $scope.totalItems > 0 ? $scope.totalItems / $scope.itemsPerPage > 1 : false;
$scope.pagination.totalItems = usersResponse.total_count;
$scope.showPagination = $scope.pagination.totalItems > 0 ? $scope.pagination.totalItems / $scope.pagination.itemsPerPage > 1 : false;
});
};

Expand All @@ -151,11 +151,12 @@ function (

// --- start: initialization
$scope.filteredRole = '';
$scope.currentPage = 1;
$scope.itemsPerPageOptions = [10, 20, 50];
$scope.itemsPerPage = $scope.itemsPerPageOptions[0];
// untill we have the correct total_count value from backend request:
$scope.totalItems = $scope.itemsPerPage;
$scope.pagination = {
currentPage : 1,
itemsPerPage : 10,
totalItems: 10
};

$scope.getUsersForPagination();
// --- end: initialization
$scope.$watch('filters', function () {
Expand Down
2 changes: 1 addition & 1 deletion app/settings/users/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h2 class="listing-item-title"><a ui-sref="settings.users.edit({id: user.id})">{
</listing-toolbar>
</div>
<nav class="pagination" ng-show="showPagination">
<ul uib-pagination ng-model="currentPage" items-per-page="itemsPerPage" total-items="totalItems" ng-change="pageChanged()" max-size="5" boundary-links="false" rotate="false"></ul>
<ul uib-pagination ng-model="pagination.currentPage" items-per-page="pagination.itemsPerPage" total-items="pagination.totalItems" ng-change="pageChanged()" max-size="5" boundary-links="false" rotate="false"></ul>
</nav>
</div>
</main>
Expand Down
2 changes: 1 addition & 1 deletion test/unit/settings/users/users-controller-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('setting users controller', function () {
spyOn($scope, 'getUsersForPagination');
$scope.itemsPerPageChanged(5);

expect($scope.itemsPerPage).toEqual(5);
expect($scope.pagination.itemsPerPage).toEqual(5);
expect($scope.getUsersForPagination).toHaveBeenCalled();
});

Expand Down

0 comments on commit d9e0e4c

Please sign in to comment.