Commit 77a4d27f authored by Glaucia S. Santos's avatar Glaucia S. Santos
Browse files

Fix pagination

parent 439a5012
......@@ -22,7 +22,7 @@
ctrl.keyword = '';
ctrl.filteredUsers = [];
ctrl.nte = '';
ctrl.page = 1;
ctrl.page = null;
ctrl.paginatedUsers = [];
ctrl.role = '';
ctrl.users = [];
......@@ -48,12 +48,9 @@
ctrl.$doCheck = function() {
if (ctrl.city !== ctrl.old.city || ctrl.classroom !== ctrl.old.classroom || ctrl.nte !== ctrl.old.nte || ctrl.role !== ctrl.old.role) {
fetchUserReportPage();
fetchUserReportPage(1);
}
if (ctrl.users !== ctrl.old.users) {
filterUsers();
paginateUsers();
} else if (ctrl.page !== ctrl.old.page) {
paginateUsers();
}
ctrl.old.city = ctrl.city;
......@@ -66,7 +63,7 @@
};
function fetchUserReportPage(page) {
const params = { page: ctrl.page };
const params = { page: page };
let filteredRequest = false;
if (ctrl.city) {
......@@ -91,6 +88,7 @@
ctrl.users = data.results;
ctrl.filteredUsers = ctrl.users;
ctrl.totalUsers = data.count;
ctrl.page = page;
// if (page === 1) {
// const totalPages = Math.ceil(data.count / 50);
// for (let extraPage = 2; (filteredRequest && extraPage <= totalPages) || (extraPage <= 20); extraPage++) {
......@@ -100,13 +98,12 @@
});
}
function filterUsers() {
ctrl.page = 1;
ctrl.filteredUsers = ctrl.users;
}
function paginateUsers() {
ctrl.paginatedUsers = ctrl.filteredUsers.slice((ctrl.page - 1) * 100, (ctrl.page * 100));
ctrl.paginatedUsers = ctrl.filteredUsers;
}
$scope.filter_page = function() {
fetchUserReportPage(ctrl.page);
};
}
})();
......@@ -33,7 +33,7 @@
<div class="classroom-reports--list">
<user-report ng-repeat="user in $ctrl.paginatedUsers track by user.id" user="user"></user-report>
</div>
<ul uib-pagination boundary-links="true" total-items="$ctrl.totalUsers" ng-model="$ctrl.page" rotate="false" force-ellipses="true" max-size="20" items-per-page="50" class="pagination pagination-md" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="primeira" last-text="última" ng-if="$ctrl.totalUsers > 50"></ul>
<ul uib-pagination boundary-links="true" total-items="$ctrl.totalUsers" ng-model="$ctrl.page" rotate="false" force-ellipses="true" max-size="20" items-per-page="50" ng-change="filter_page()" class="pagination pagination-md" previous-text="&lsaquo;" next-text="&rsaquo;" first-text="primeira" last-text="última" ng-if="$ctrl.totalUsers > 50"></ul>
</div>
</div>
......
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