Browse Source

fixes #185: group tickets by email

Davide Alberani 7 years ago
parent
commit
dd23db6462
3 changed files with 39 additions and 7 deletions
  1. 26 1
      angular_app/js/controllers.js
  2. 11 5
      angular_app/tickets-list.html
  3. 2 1
      static/i18n/it_IT.json

+ 26 - 1
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();
         });

+ 11 - 5
angular_app/tickets-list.html

@@ -11,7 +11,7 @@
             <form class="form-inline">
                 <div class="form-group">
                     <label for="query-tickets">{{'Search:' | translate}}</label>
-                    <input eventman-focus type="text" id="query-tickets" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query" ng-model-options="{debounce: 350}">
+                    <input eventman-focus type="text" id="query-tickets" class="form-control" placeholder="{{'Name or email' | translate}}" ng-model="query" ng-model-options="{debounce: 350}">&nbsp;<label>&nbsp;<input type="checkbox" ng-model="groupByEmail" /> {{'group by email' | translate}}</label>
                 </div>
             </form>
 
@@ -23,7 +23,7 @@
                     <tr>
                         <th class="text-right nowrap">#</th>
                         <th class="nowrap"><a ng-click="updateOrded('name')" href=""><i class="fa fa-caret-up"></i></a>{{'Name' | translate}}<a ng-click="updateOrded('-name')" href=""><i class="fa fa-caret-down"></i></a> <a ng-click="updateOrded('surname')" href=""><i class="fa fa-caret-up"></i></a>{{'Surname' | translate}}<a ng-click="updateOrded('-surname')" href=""><i class="fa fa-caret-down"></i></a> <a ng-click="updateOrded('email')" href=""><i class="fa fa-caret-up"></i></a>{{'Email' | translate}}<a ng-click="updateOrded('-email')" href=""><i class="fa fa-caret-down"></i></a></th>
-                        <th class="text-center nowrap"><strong>{{'Event' | translate}}</strong></th>
+                        <th class="text-center nowrap"><strong>{{'Ticket' | translate}}</strong></th>
                         <th class="text-center nowrap"><strong>{{'Attended' | translate}}</strong></th>
                     </tr>
                 </thead>
@@ -31,14 +31,20 @@
                 <tr ng-repeat="ticket in shownItems">
                     <td class="text-right">{{$index+1}}</td>
                     <td>
-                        <span><strong><a ui-sref="event.ticket.edit({id: ticket.event_id, ticket_id: ticket._id})"><span>{{ticket.name}}</span>&nbsp;<span>{{ticket.surname}}</span></a></strong></span><span ng-if="ticket.email">&nbsp;&lt;{{ticket.email}}&gt;</span>
+                        <span><strong><span>{{ticket.name}}</span>&nbsp;<span>{{ticket.surname}}</span></strong></span><span ng-if="ticket.email">&nbsp;&lt;{{ticket.email}}&gt;</span>
                         <p ng-if="ticket.company || ticket['job title']"><i ng-if="ticket['job title']">{{ticket['job title']}}</i><span ng-if="ticket.company && ticket['job title']">&nbsp;@&nbsp;</span><i ng-if="ticket.company">{{ticket.company}}</i></p>
                     </td>
                     <td class="text-center">
-                        <a ui-sref="event.view({id: ticket.event_id})">{{ticket.event_title}}</a>
+                        <a ng-if="!ticket.tickets" ui-sref="event.ticket.edit({id: ticket.event_id, ticket_id: ticket._id})">{{ticket.event_title}}</a>
+                        <div ng-if="ticket.tickets" ng-repeat="t in ticket.tickets">
+                            <a ui-sref="event.ticket.edit({id: t.event_id, ticket_id: t._id})">{{t.event_title}}</a>
+                        </div>
                     </td>
                     <td class="text-center">
-                        <span class="fa {{(ticket.attended) && 'fa-check-circle text-success' || 'fa-times-circle text-danger'}}"></span>
+                        <span ng-if="!ticket.tickets" class="fa {{(ticket.attended) && 'fa-check-circle text-success' || 'fa-times-circle text-danger'}}"></span>
+                        <div ng-if="ticket.tickets" ng-repeat="t in ticket.tickets">
+                            <span class="fa {{(t.attended) && 'fa-check-circle text-success' || 'fa-times-circle text-danger'}}"></span>
+                        </div>
                     </td>
                 </tr>
                 </tbody>

+ 2 - 1
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)",