Merge pull request #92 from alberanid/master

fixes #86: only the changed person is returned, updating an attendee status
This commit is contained in:
Davide Alberani 2016-04-10 17:24:00 +02:00
commit 6548d7bb77
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

@ -128,7 +128,7 @@ _ws_clients = {}
class CollectionHandler(BaseHandler): class CollectionHandler(BaseHandler):
"""Base class for handlers that need to interact with the database backend. """Base class for handlers that need to interact with the database backend.
Introduce basic CRUD operations.""" Introduce basic CRUD operations."""
# set of documents we're managing (a collection in MongoDB or a table in a SQL database) # set of documents we're managing (a collection in MongoDB or a table in a SQL database)
collection = None collection = None
@ -155,11 +155,11 @@ class CollectionHandler(BaseHandler):
def _filter_results(self, results, params): def _filter_results(self, results, params):
"""Filter a list using keys and values from a dictionary. """Filter a list using keys and values from a dictionary.
:param results: the list to be filtered :param results: the list to be filtered
:type results: list :type results: list
:param params: a dictionary of items that must all be present in an original list item to be included in the return :param params: a dictionary of items that must all be present in an original list item to be included in the return
:return: list of items that have all the keys with the same values as params :return: list of items that have all the keys with the same values as params
:rtype: list""" :rtype: list"""
if not params: if not params:
@ -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.