partial implementation of an All Tickets page

This commit is contained in:
Davide Alberani 2016-07-05 21:30:12 +02:00
parent 7d79d35992
commit bee15ca088
6 changed files with 51 additions and 29 deletions

View file

@ -73,7 +73,8 @@
<div ng-if="logo.imgURL" class="navbar-brand"><a ng-if="logo.link" href="{{logo.link}}" target="_blank"><img src="{{logo.imgURL}}" /></a></div>
<ul class="nav navbar-nav">
<li ng-class="{active: isActive('/events') || isActive('/event')}"><a ui-sref="events">{{'Events' | translate}}</a></li>
<li ng-if="hasPermission('persons|read')" ng-class="{active: isActive('/persons') || isActive('/person') || isActive('/import/persons')}"><a ui-sref="persons">{{'Persons' | translate}}</a></li>
<li ng-if="hasPermission('admin|all')" ng-class="{active: isActive('/tickets')}"><a ui-sref="tickets">{{'Tickets' | translate}}</a></li>
<li ng-if="hasPermission('admin|all')" ng-class="{active: isActive('/import/persons')}"><a ui-sref="import.persons">{{'Import persons' | translate}}</a></li>
</ul>
</div>
<div class="collapse navbar-collapse">

27
angular_app/js/app.js vendored
View file

@ -145,29 +145,10 @@ eventManApp.config(['$stateProvider', '$urlRouterProvider',
templateUrl: 'ticket-edit.html',
controller: 'EventTicketsCtrl'
})
.state('persons', {
url: '/persons',
templateUrl: 'persons-list.html',
controller: 'PersonsListCtrl'
})
.state('person', {
url: '/person',
templateUrl: 'person-main.html'
})
.state('person.new', {
url: '/new',
templateUrl: 'person-edit.html',
controller: 'PersonDetailsCtrl'
})
.state('person.edit', {
url: '/:id/edit',
templateUrl: 'person-edit.html',
controller: 'PersonDetailsCtrl'
})
.state('person.info', {
url: '/:id',
templateUrl: 'person-info.html',
controller: 'PersonDetailsCtrl'
.state('tickets', {
url: '/tickets',
templateUrl: 'tickets-list.html',
controller: 'EventTicketsCtrl'
})
.state('import', {
url: '/import',

View file

@ -142,6 +142,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
$scope.message = {};
$scope.event = {};
$scope.ticket = {}; // current ticket, for the event.ticket.* states
$scope.tickets = []; // list of all tickets, for the 'tickets' state
$scope.formSchema = {};
$scope.formData = {};
$scope.guiOptions = {dangerousActionsEnabled: false};
@ -219,6 +220,8 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
}
);
}
} else if ($state.is('tickets')) {
$scope.tickets = EventTicket.all();
}
$scope.calcAttendees = function() {

View file

@ -88,6 +88,20 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope',
}
},
all: {
method: 'GET',
url: '/tickets',
interceptor : {responseError: $rootScope.errorHandler},
isArray: true,
transformResponse: function(data, headers) {
data = angular.fromJson(data);
if (data.error) {
return data;
}
return data.persons;
}
},
add: {
method: 'POST',
interceptor : {responseError: $rootScope.errorHandler},

View file

@ -45,7 +45,7 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="person in persons | splittedFilter:query | orderBy:personsOrder">
<tr ng-repeat="person in tickets | splittedFilter:query | orderBy:personsOrder">
<td class="text-right">{{$index+1}}</td>
<td>
<span><strong><a ui-sref="person.info({id: person._id})"><span>{{person.name}}</span>&nbsp;<span>{{person.surname}}</span></a></strong></span><span ng-if="person.email">&nbsp;&lt;{{person.email}}&gt;</span>

View file

@ -522,10 +522,30 @@ class CollectionHandler(BaseHandler):
self.logger.error('Error yielding WebSocket message: %s', e)
class TicketsHandler(CollectionHandler):
"""Handle requests for Tickes."""
@gen.coroutine
@authenticated
def get(self, id_=None, resource=None, resource_id=None, acl=True, **kwargs):
query = {}
events = self.db.query('events', {})
persons = {}
for event in events:
id_ = str(event['_id'])
title = event['title']
for person in (event.get('persons') or []):
email = person.get('email')
if not email:
continue
if email not in persons:
persons[email] = person
persons[email].setdefault('events', {})[id_] = title
self.write({'persons': persons.values()})
class PersonsHandler(CollectionHandler):
"""Handle requests for Persons."""
document = 'person'
collection = 'persons'
def handle_get_events(self, id_, resource_id=None, **kwargs):
# Get a list of events attended by this person.
@ -605,7 +625,7 @@ class EventsHandler(CollectionHandler):
all_query = {'group_id': group_id}
events = self.db.query('events', all_query)
for event in events:
if str(event.get('_id')) == id_:
if id_ is not None and str(event.get('_id')) == id_:
continue
persons += [p for p in (event.get('persons') or []) if p.get('email') and p.get('email') not in this_emails]
return {'persons': persons}
@ -837,7 +857,7 @@ class SettingsHandler(BaseHandler):
class InfoHandler(BaseHandler):
"""Handle requests for Info."""
"""Handle requests for information about the logged in user."""
@gen.coroutine
@authenticated
def get(self, **kwds):
@ -998,6 +1018,7 @@ def run():
_persons_path = r"/persons/?(?P<id_>[\w\d_-]+)?/?(?P<resource>[\w\d_-]+)?/?(?P<resource_id>[\w\d_-]+)?"
_events_path = r"/events/?(?P<id_>[\w\d_-]+)?/?(?P<resource>[\w\d_-]+)?/?(?P<resource_id>[\w\d_-]+)?"
_users_path = r"/users/?(?P<id_>[\w\d_-]+)?/?(?P<resource>[\w\d_-]+)?/?(?P<resource_id>[\w\d_-]+)?"
_tickets_path = r"/tickets"
application = tornado.web.Application([
(_persons_path, PersonsHandler, init_params),
(r'/v%s%s' % (API_VERSION, _persons_path), PersonsHandler, init_params),
@ -1005,6 +1026,8 @@ def run():
(r'/v%s%s' % (API_VERSION, _events_path), EventsHandler, init_params),
(_users_path, UsersHandler, init_params),
(r'/v%s%s' % (API_VERSION, _users_path), UsersHandler, init_params),
(_tickets_path, TicketsHandler, init_params),
(r'/v%s%s' % (API_VERSION, _tickets_path), TicketsHandler, init_params),
(r"/(?:index.html)?", RootHandler, init_params),
(r"/ebcsvpersons", EbCSVImportPersonsHandler, init_params),
(r"/settings", SettingsHandler, init_params),