show message if it came from the same user

This commit is contained in:
Davide Alberani 2017-04-01 18:43:42 +02:00
parent f43a429deb
commit 79278d57a7
5 changed files with 26 additions and 15 deletions

View file

@ -114,7 +114,7 @@ Users can register, but are not forced to do so: tickets can also be issued to u
License and copyright
=====================
Copyright 2015-2016 Davide Alberani <da@erlug.linux.it>, RaspiBO <info@raspibo.org>
Copyright 2015-2017 Davide Alberani <da@erlug.linux.it>, RaspiBO <info@raspibo.org>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View file

@ -52,7 +52,7 @@
</head>
<!--
Copyright 2015-2016 Davide Alberani <da@erlug.linux.it>
Copyright 2015-2017 Davide Alberani <da@erlug.linux.it>
RaspiBO <info@raspibo.org>
Licensed under the Apache License, Version 2.0 (the "License");

View file

@ -1,6 +1,6 @@
'use strict';
/*
Copyright 2015-2016 Davide Alberani <da@erlug.linux.it>
Copyright 2015-2017 Davide Alberani <da@erlug.linux.it>
RaspiBO <info@raspibo.org>
Licensed under the Apache License, Version 2.0 (the "License");

View file

@ -248,6 +248,12 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
}
if (data.action == 'update' && ticket_idx != -1 && $scope.event.tickets[ticket_idx] != data.ticket) {
// if we're updating the 'attended' key and the action came from us (same user, possibly on
// a different station), also show a message.
if (data.ticket.attended != $scope.event.tickets[ticket_idx].attended &&
$scope.info.user.username == data.username) {
$scope.showAttendedMessage(data.ticket, data.ticket.attended);
}
$scope.event.tickets[ticket_idx] = data.ticket;
} else if (data.action == 'add' && ticket_idx == -1) {
$scope._localAddTicket(data.ticket);
@ -406,20 +412,24 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
}
if (key === 'attended' && !hideMessage) {
var msg = {};
var name = $scope.buildTicketLabel(data.ticket);
if (value) {
msg.message = name + ' successfully added to event ' + $scope.event.title;
} else {
msg.message = name + ' successfully removed from event ' + $scope.event.title;
msg.isError = true;
}
$scope.showMessage(msg);
$scope.showAttendedMessage(data.ticket, value);
}
});
};
$scope.showAttendedMessage = function(ticket, attends) {
var msg = {};
var name = $scope.buildTicketLabel(ticket);
if (attends) {
msg.message = name + ' successfully added to event ' + $scope.event.title;
} else {
msg.message = name + ' successfully removed from event ' + $scope.event.title;
msg.isError = true;
}
$scope.showMessage(msg);
};
$scope.setTicketAttributeAndRefocus = function(ticket, key, value) {
$scope.setTicketAttribute(ticket, key, value);
$scope.query = '';
@ -649,7 +659,7 @@ eventManControllers.controller('UsersCtrl', ['$scope', '$rootScope', '$state', '
User.login(loginData, function(data) {
if (!data.error) {
$rootScope.readInfo(function(info) {
$log.debug('logged in user: ' + info.user.username);
$log.debug('logged in user: ' + $scope.info.user.username);
$rootScope.clearError();
$state.go('events');
});

View file

@ -810,7 +810,8 @@ class EventsHandler(CollectionHandler):
if new_ticket_data.get('attended'):
self.run_triggers('attends', stdin_data=stdin_data, env=env)
ret = {'action': 'update', '_id': ticket_id, 'ticket': new_ticket_data, 'uuid': uuid}
ret = {'action': 'update', '_id': ticket_id, 'ticket': new_ticket_data,
'uuid': uuid, 'username': self.current_user_info.get('username', '')}
if old_ticket_data != new_ticket_data:
self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret))
return ret