fixes #86: only the changed person is returned, updating an attendee status

This commit is contained in:
Davide Alberani 2016-04-10 17:21:46 +02:00
parent 52df401082
commit 08aef28d0d
5 changed files with 36 additions and 16 deletions

View file

@ -62,7 +62,7 @@ By default, authentication is required; default username and password are *admin
License and copyright License and copyright
===================== =====================
Copyright 2015 Davide Alberani <da@erlug.linux.it> Copyright 2015-2016 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

@ -124,10 +124,20 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event',
$scope.$watchCollection(function() { $scope.$watchCollection(function() {
return $scope.EventUpdates.data; return $scope.EventUpdates.data;
}, function(prev, old) { }, function(prev, old) {
if (!($scope.EventUpdates.data && $scope.EventUpdates.data.persons)) { if (!($scope.EventUpdates.data && $scope.EventUpdates.data.update)) {
return; return;
} }
$scope.event.persons = $scope.EventUpdates.data.persons; var data = $scope.EventUpdates.data.update;
var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
return data.person_id == el.person_id;
});
if (person_idx == -1) {
$log.warn('unable to find person_id ' + person_id);
return;
}
if ($scope.event.persons[person_idx] != data.person) {
$scope.event.persons[person_idx] = data.person;
}
} }
); );
} }
@ -229,7 +239,19 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event',
data[key] = value; data[key] = value;
Event.updatePerson(data, Event.updatePerson(data,
function(data) { function(data) {
$scope.event.persons = data; if (!(data && data.person_id && data.person)) {
return;
}
var person_idx = $scope.event.persons.findIndex(function(el, idx, array) {
return data.person_id == el.person_id;
});
if (person_idx == -1) {
$log.warn('unable to find person_id ' + person_id);
return;
}
if ($scope.event.persons[person_idx] != data.person) {
$scope.event.persons[person_idx] = data.person;
}
if (callback) { if (callback) {
callback(data); callback(data);
} }

View file

@ -3,7 +3,6 @@
eventManApp.config(['$translateProvider', function ($translateProvider) { eventManApp.config(['$translateProvider', function ($translateProvider) {
console.log($translateProvider);
$translateProvider.useStaticFilesLoader({ $translateProvider.useStaticFilesLoader({
prefix: '/static/i18n/', prefix: '/static/i18n/',
suffix: '.json' suffix: '.json'

View file

@ -33,10 +33,10 @@ eventManServices.factory('Event', ['$resource',
updatePerson: { updatePerson: {
method: 'PUT', method: 'PUT',
isArray: true, isArray: false,
url: 'events/:id/persons/:person_id', url: 'events/:id/persons/:person_id',
transformResponse: function(data, headers) { transformResponse: function(data, headers) {
return angular.fromJson(data).event.persons; return angular.fromJson(data);
} }
}, },
@ -156,9 +156,8 @@ eventManApp.factory('EventUpdates', ['$websocket', '$location', '$log',
'/ws/' + $location.path() + '/updates'); '/ws/' + $location.path() + '/updates');
dataStream.onMessage(function(message) { dataStream.onMessage(function(message) {
$log.debug('EventUpdates message received'); $log.debug('EventUpdates message received');
data.persons = angular.fromJson(message.data); data.update = angular.fromJson(message.data);
}); });
} }
}; };

View file

@ -433,10 +433,10 @@ class EventsHandler(CollectionHandler):
if new_person_data.get('attended'): if new_person_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', 'person_id': person_id, 'person': new_person_data}
if old_person_data != new_person_data: if old_person_data != new_person_data:
self.send_ws_message('event/%s/updates' % id_, self.send_ws_message('event/%s/updates' % id_, json.dumps(ret))
json.dumps(doc.get('persons') or [])) return ret
return {'event': doc}
def handle_delete_persons(self, id_, person_id): def handle_delete_persons(self, id_, person_id):
# Remove a specific person from the list of persons registered at this event. # Remove a specific person from the list of persons registered at this event.