From dd23db646253c65748cdb6b347c062babb4170d3 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Mon, 29 May 2017 18:02:55 +0200 Subject: [PATCH] fixes #185: group tickets by email --- angular_app/js/controllers.js | 27 ++++++++++++++++++++++++++- angular_app/tickets-list.html | 16 +++++++++++----- static/i18n/it_IT.json | 3 ++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index e26018c..ae05be0 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -71,6 +71,7 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', 'EventTicke $scope.eventsOrderProp = "-begin_date"; $scope.ticketsOrderProp = ["name", "surname"]; + $scope.groupByEmail = false; $scope.shownItems = []; $scope.currentPage = 1; $scope.itemsPerPage = 10; @@ -92,7 +93,27 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', 'EventTicke }); $scope.filterTickets = function() { - var tickets = $scope.tickets || []; + var tickets = angular.copy($scope.tickets || []); + if ($scope.groupByEmail) { + var newDict = {}; + var newList = []; + angular.forEach(tickets, function(item, idx) { + if (!newDict[item.email]) { + newDict[item.email] = {}; + newDict[item.email]['name'] = item.name; + newDict[item.email]['surname'] = item.surname; + newDict[item.email]['email'] = item.email; + newDict[item.email]['job title'] = item.job; + newDict[item.email]['company'] = item.company; + newDict[item.email]['tickets'] = []; + } + newDict[item.email]['tickets'].push(item); + }); + angular.forEach(newDict, function(value, key) { + newList.push(value); + }); + tickets = newList; + } tickets = $filter('splittedFilter')(tickets, $scope.query); tickets = $filter('orderBy')(tickets, $scope.ticketsOrderProp); $scope.filteredLength = tickets.length; @@ -107,6 +128,10 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', 'EventTicke $scope.filterTickets(); }); + $scope.$watch('groupByEmail', function() { + $scope.filterTickets(); + }); + $scope.$watch('currentPage + itemsPerPage', function() { $scope.filterTickets(); }); diff --git a/angular_app/tickets-list.html b/angular_app/tickets-list.html index 3a35442..5a3f61a 100644 --- a/angular_app/tickets-list.html +++ b/angular_app/tickets-list.html @@ -11,7 +11,7 @@
- +  
@@ -23,7 +23,7 @@ # {{'Name' | translate}} {{'Surname' | translate}} {{'Email' | translate}} - {{'Event' | translate}} + {{'Ticket' | translate}} {{'Attended' | translate}} @@ -31,14 +31,20 @@ {{$index+1}} - {{ticket.name}} {{ticket.surname}} <{{ticket.email}}> + {{ticket.name}} {{ticket.surname}} <{{ticket.email}}>

{{ticket['job title']}} @ {{ticket.company}}

- {{ticket.event_title}} + {{ticket.event_title}} +
+ {{t.event_title}} +
- + +
+ +
diff --git a/static/i18n/it_IT.json b/static/i18n/it_IT.json index a35d606..7184dbf 100644 --- a/static/i18n/it_IT.json +++ b/static/i18n/it_IT.json @@ -92,13 +92,14 @@ "All Tickets": "Tutti i biglietti", "Tickets:": "Biglietti", "Name or email": "Nome o email", + "group by email": "raggruppa per email", + "Ticket": "Biglietto", "update user information": "aggiorna le informazioni dell'utente", "Old password": "Vecchia password", "New password": "Nuova password", "is admin": "รจ un amministratore", "update": "aggiorna", "Sort by:": "Ordina per:", - "Ticket": "Biglietto", "Add user": "Aggiungi utente", "Username (descending)": "Username (ordine inverso)", "Email (descending)": "Email (ordine inverso)",