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 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"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.

View file

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

View file

@ -1,6 +1,6 @@
'use strict'; 'use strict';
/* /*
Copyright 2015-2016 Davide Alberani <da@erlug.linux.it> Copyright 2015-2017 Davide Alberani <da@erlug.linux.it>
RaspiBO <info@raspibo.org> RaspiBO <info@raspibo.org>
Licensed under the Apache License, Version 2.0 (the "License"); 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 (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; $scope.event.tickets[ticket_idx] = data.ticket;
} else if (data.action == 'add' && ticket_idx == -1) { } else if (data.action == 'add' && ticket_idx == -1) {
$scope._localAddTicket(data.ticket); $scope._localAddTicket(data.ticket);
@ -406,18 +412,22 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
} }
if (key === 'attended' && !hideMessage) { if (key === 'attended' && !hideMessage) {
var msg = {}; $scope.showAttendedMessage(data.ticket, value);
var name = $scope.buildTicketLabel(data.ticket); }
});
};
if (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; msg.message = name + ' successfully added to event ' + $scope.event.title;
} else { } else {
msg.message = name + ' successfully removed from event ' + $scope.event.title; msg.message = name + ' successfully removed from event ' + $scope.event.title;
msg.isError = true; msg.isError = true;
} }
$scope.showMessage(msg); $scope.showMessage(msg);
}
});
}; };
$scope.setTicketAttributeAndRefocus = function(ticket, key, value) { $scope.setTicketAttributeAndRefocus = function(ticket, key, value) {
@ -649,7 +659,7 @@ eventManControllers.controller('UsersCtrl', ['$scope', '$rootScope', '$state', '
User.login(loginData, function(data) { User.login(loginData, function(data) {
if (!data.error) { if (!data.error) {
$rootScope.readInfo(function(info) { $rootScope.readInfo(function(info) {
$log.debug('logged in user: ' + info.user.username); $log.debug('logged in user: ' + $scope.info.user.username);
$rootScope.clearError(); $rootScope.clearError();
$state.go('events'); $state.go('events');
}); });

View file

@ -810,7 +810,8 @@ class EventsHandler(CollectionHandler):
if new_ticket_data.get('attended'): if new_ticket_data.get('attended'):
self.run_triggers('attends', stdin_data=stdin_data, env=env) 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: if old_ticket_data != new_ticket_data:
self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret))
return ret return ret