From 2095977fe82d1713df47d3a76648ba9c832e29ce Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sun, 2 Apr 2017 12:48:24 +0200 Subject: [PATCH] pagination for All tickets page --- angular_app/js/controllers.js | 30 +++++++++++++++++++++++++++--- angular_app/tickets-list.html | 8 +++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index e5341c0..9b41558 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -66,8 +66,8 @@ eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$uibModal ); -eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope', '$state', - function ($scope, Event, $uibModal, $log, $translate, $rootScope, $state) { +eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope', '$state', '$filter', + function ($scope, Event, $uibModal, $log, $translate, $rootScope, $state, $filter) { $scope.tickets = []; $scope.events = Event.all(function(events) { if (events && $state.is('tickets')) { @@ -79,11 +79,35 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal' }); $scope.tickets.push.apply($scope.tickets, evt_tickets || []); }); + $scope.filterTickets(); } }); $scope.eventsOrderProp = "-begin_date"; $scope.ticketsOrderProp = ["name", "surname"]; + $scope.shownItems = []; + $scope.currentPage = 1; + $scope.itemsPerPage = 20; + $scope.filteredLength = 0; + $scope.maxPaginationSize = 5; + + $scope.filterTickets = function() { + var tickets = $scope.tickets || []; + tickets = $filter('splittedFilter')(tickets, $scope['query-tickets']); + tickets = $filter('orderBy')(tickets, $scope.ticketsOrderProp); + $scope.filteredLength = tickets.length; + tickets = $filter('pagination')(tickets, $scope.currentPage, $scope.itemsPerPage); + $scope.shownItems = tickets; + }; + + $scope.$watch('query-tickets', function() { + $scope.filterTickets(); + }); + + $scope.$watch('currentPage + itemsPerPage', function() { + $scope.filterTickets(); + }); + $scope.confirm_delete = 'Do you really want to delete this event?'; $rootScope.$on('$translateChangeSuccess', function () { $translate('Do you really want to delete this event?').then(function (translation) { @@ -123,8 +147,8 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal' } ); $scope.ticketsOrderProp = new_order; + $scope.filterTickets(); }; - }] ); diff --git a/angular_app/tickets-list.html b/angular_app/tickets-list.html index a8812d1..2d8f205 100644 --- a/angular_app/tickets-list.html +++ b/angular_app/tickets-list.html @@ -15,6 +15,9 @@ + + @@ -25,7 +28,7 @@ - +
{{$index+1}} {{ticket.name}} {{ticket.surname}} <{{ticket.email}}> @@ -40,6 +43,9 @@
+ +