From ac8cdc24b4597d5e1b1fb7f10f7d805b22aba13e Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sun, 2 Apr 2017 00:35:12 +0200 Subject: [PATCH] basic pagination for tickets --- angular_app/event-tickets.html | 5 ++++- angular_app/js/controllers.js | 30 ++++++++++++++++++++++++++++-- angular_app/js/filters.js | 12 ++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/angular_app/event-tickets.html b/angular_app/event-tickets.html index 1ca8889..01d96fd 100644 --- a/angular_app/event-tickets.html +++ b/angular_app/event-tickets.html @@ -43,7 +43,7 @@ - + {{$index+1}} @@ -71,6 +71,9 @@ + + diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index b3ca300..e5341c0 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -166,13 +166,15 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', ); -eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', '$uibModal', - function ($scope, $state, Event, EventTicket, Setting, $log, $translate, $rootScope, EventUpdates, $uibModal) { +eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', '$uibModal', '$filter', + function ($scope, $state, Event, EventTicket, Setting, $log, $translate, $rootScope, EventUpdates, $uibModal, $filter) { $scope.ticketsOrder = ["name", "surname"]; $scope.countAttendees = 0; $scope.message = {}; + $scope.query = ''; $scope.event = {}; $scope.event.tickets = []; + $scope.shownItems = []; $scope.ticket = {}; // current ticket, for the event.ticket.* states $scope.tickets = []; // list of all tickets, for the 'tickets' state $scope.formSchema = {}; @@ -181,6 +183,29 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.customFields = Setting.query({setting: 'ticket_custom_field', in_event_details: true}); $scope.registeredFilterOptions = {all: false}; + $scope.currentPage = 1; + $scope.itemsPerPage = 20; + $scope.filteredLength = 0; + $scope.maxPaginationSize = 5; + + $scope.filterTickets = function() { + var tickets = $scope.event.tickets || []; + tickets = $filter('splittedFilter')(tickets, $scope.query); + tickets = $filter('registeredFilter')(tickets, $scope.registeredFilterOptions); + tickets = $filter('orderBy')(tickets, $scope.ticketsOrder); + $scope.filteredLength = tickets.length; + tickets = $filter('pagination')(tickets, $scope.currentPage, $scope.itemsPerPage); + $scope.shownItems = tickets; + }; + + $scope.$watch('query', function() { + $scope.filterTickets(); + }); + + $scope.$watch('currentPage + itemsPerPage', function() { + $scope.filterTickets(); + }); + $scope.formFieldsMap = {}; $scope.formFieldsMapRev = {}; @@ -190,6 +215,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', return $scope.event.tickets; }, function(new_collection, old_collection) { $scope.calcAttendees(); + $scope.filterTickets(); } ); diff --git a/angular_app/js/filters.js b/angular_app/js/filters.js index d415bf7..5dc883b 100644 --- a/angular_app/js/filters.js +++ b/angular_app/js/filters.js @@ -68,6 +68,18 @@ eventManApp.filter('registeredFilter', ['$filter', ); +/* Filter that implements a generic pagination. */ +eventManApp.filter('pagination', ['$filter', + function($filter) { + return function(inputArray, page, itemsPerPage) { + var begin = (page - 1) * itemsPerPage; + var end = begin + itemsPerPage; + return inputArray.slice(begin, end);; + }; + }] +); + + /* Filter that returns only the attendees at an event. */ eventManApp.filter('attendeesFilter', ['$filter', function($filter) {