#145: remove Person controller and service
This commit is contained in:
parent
5fc0ff0723
commit
4e7123d4bb
3 changed files with 5 additions and 222 deletions
145
angular_app/js/controllers.js
vendored
145
angular_app/js/controllers.js
vendored
|
@ -167,8 +167,8 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event',
|
|||
);
|
||||
|
||||
|
||||
eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', '$uibModal',
|
||||
function ($scope, $state, Event, EventTicket, Person, Setting, $log, $translate, $rootScope, EventUpdates, $uibModal) {
|
||||
eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', '$uibModal',
|
||||
function ($scope, $state, Event, EventTicket, Setting, $log, $translate, $rootScope, EventUpdates, $uibModal) {
|
||||
$scope.personsOrder = ["name", "surname"];
|
||||
$scope.countAttendees = 0;
|
||||
$scope.message = {};
|
||||
|
@ -341,6 +341,9 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
|
|||
if (removed_person.length) {
|
||||
person = removed_person[0];
|
||||
}
|
||||
if (!$scope.allPersons) {
|
||||
$scope.allPersons = [];
|
||||
}
|
||||
var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) {
|
||||
return person._id == el._id;
|
||||
});
|
||||
|
@ -517,144 +520,6 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event',
|
|||
);
|
||||
|
||||
|
||||
eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting', '$uibModal', '$translate', '$rootScope',
|
||||
function ($scope, Person, Setting, $uibModal, $translate, $rootScope) {
|
||||
$scope.persons = Person.all();
|
||||
$scope.personsOrder = ["name", "surname"];
|
||||
$scope.customFields = Setting.query({setting: 'person_custom_field',
|
||||
in_persons_list: true});
|
||||
|
||||
$scope.confirm_delete = 'Do you really want to delete this person?';
|
||||
$rootScope.$on('$translateChangeSuccess', function () {
|
||||
$translate('Do you really want to delete this person?').then(function (translation) {
|
||||
$scope.confirm_delete = translation;
|
||||
});
|
||||
});
|
||||
|
||||
$scope.updateOrded = function(key) {
|
||||
var new_order = [key];
|
||||
var inv_key;
|
||||
if (key && key[0] === '-') {
|
||||
inv_key = key.substring(1);
|
||||
} else {
|
||||
inv_key = '-' + key;
|
||||
}
|
||||
angular.forEach($scope.personsOrder,
|
||||
function(value, idx) {
|
||||
if (value !== key && value !== inv_key) {
|
||||
new_order.push(value);
|
||||
}
|
||||
}
|
||||
);
|
||||
$scope.personsOrder = new_order;
|
||||
};
|
||||
|
||||
$scope.setAttribute = function(person, key, value) {
|
||||
var data = {_id: person._id};
|
||||
data[key] = value;
|
||||
Person.update(data, function() {
|
||||
$scope.persons = Person.all();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.remove = function(_id) {
|
||||
var modalInstance = $uibModal.open({
|
||||
scope: $scope,
|
||||
templateUrl: 'modal-confirm-action.html',
|
||||
controller: 'ModalConfirmInstanceCtrl',
|
||||
resolve: {
|
||||
message: function() { return $scope.confirm_delete; }
|
||||
}
|
||||
});
|
||||
modalInstance.result.then(function() {
|
||||
Person.remove({'id': _id}, function() {
|
||||
$scope.persons = Person.all();
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
}]
|
||||
);
|
||||
|
||||
|
||||
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$state', 'Person', 'Event', 'Setting', '$log',
|
||||
function ($scope, $state, Person, Event, Setting, $log) {
|
||||
$scope.personsOrderProp = 'name';
|
||||
$scope.eventsOrderProp = '-begin_date';
|
||||
$scope.addToEvent = '';
|
||||
$scope.customFields = Setting.query({setting: 'person_custom_field',
|
||||
in_persons_list: true});
|
||||
|
||||
if ($state.params.id) {
|
||||
$scope.person = Person.get($state.params);
|
||||
$scope.events = Person.getEvents({_id: $state.arams.id, all: true});
|
||||
} else {
|
||||
$scope.events = Event.all();
|
||||
}
|
||||
|
||||
// store a new Person or update an existing one
|
||||
$scope.save = function() {
|
||||
if ($scope.person._id === undefined) {
|
||||
$scope.person = new Person($scope.person);
|
||||
$scope.person.$save(function(person) {
|
||||
if ($scope.addToEvent) {
|
||||
var data = angular.copy(person);
|
||||
data.person_id = data._id;
|
||||
data._id = $scope.addToEvent;
|
||||
data.attended = false;
|
||||
Event.addPerson(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$scope.person = Person.update($scope.person, function(data) {
|
||||
if ($scope.addToEvent) {
|
||||
var data = angular.copy($scope.person);
|
||||
data._id = $scope.addToEvent;
|
||||
data.person_id = $scope.person._id;
|
||||
data.attended = false;
|
||||
Event.addPerson(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
$scope.personForm.$setPristine(false);
|
||||
};
|
||||
|
||||
$scope.setTicketAttributeAtEvent = function(evnt, key, value) {
|
||||
var attrs = {_id: evnt._id, person_id: $state.params.id};
|
||||
attrs[key] = value;
|
||||
Event.updatePerson(attrs,
|
||||
function(data) {
|
||||
$scope.events = Person.getEvents({_id: $state.params.id, all: true});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
$scope.switchRegistered = function(evnt, person, add) {
|
||||
$log.debug('PersonDetailsCtrl.switchRegistered.event_id: ' + evnt._id);
|
||||
$log.debug('PersonDetailsCtrl.switchRegistered.person_id: ' + person._id);
|
||||
$log.debug('PersonDetailsCtrl.switchRegistered.add: ' + add);
|
||||
if (add) {
|
||||
var data = angular.copy(person);
|
||||
data._id = evnt._id;
|
||||
data.person_id = person._id;
|
||||
data.attended = false;
|
||||
Event.addPerson(data,
|
||||
function(data) {
|
||||
$scope.events = Person.getEvents({_id: $state.params.id, all: true});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
Event.deletePerson({_id: evnt._id, person_id: person._id},
|
||||
function(data) {
|
||||
$scope.events = Person.getEvents({_id: $state.params.id, all: true});
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}]
|
||||
);
|
||||
|
||||
|
||||
eventManControllers.controller('UsersCtrl', ['$scope', '$rootScope', '$state', '$log', 'User', '$uibModal',
|
||||
function ($scope, $rootScope, $state, $log, User, $uibModal) {
|
||||
$scope.loginData = {};
|
||||
|
|
45
angular_app/js/services.js
vendored
45
angular_app/js/services.js
vendored
|
@ -140,51 +140,6 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope',
|
|||
);
|
||||
|
||||
|
||||
eventManServices.factory('Person', ['$resource', '$rootScope',
|
||||
function($resource, $rootScope) {
|
||||
return $resource('persons/:id', {id: '@_id'}, {
|
||||
|
||||
all: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
isArray: true,
|
||||
transformResponse: function(data, headers) {
|
||||
// TODO: REMOVE!
|
||||
return [];
|
||||
data = angular.fromJson(data);
|
||||
if (data.error) {
|
||||
return data;
|
||||
}
|
||||
return data.persons;
|
||||
}
|
||||
},
|
||||
|
||||
update: {
|
||||
method: 'PUT',
|
||||
interceptor : {responseError: $rootScope.errorHandler}
|
||||
},
|
||||
|
||||
getEvents: {
|
||||
method: 'GET',
|
||||
interceptor : {responseError: $rootScope.errorHandler},
|
||||
url: 'persons/:_id/events',
|
||||
isArray: true,
|
||||
transformResponse: function(data, headers) {
|
||||
data = angular.fromJson(data);
|
||||
if (data.error) {
|
||||
return data;
|
||||
}
|
||||
angular.forEach(data.events || [], function(event_, event_idx) {
|
||||
convert_dates(event_);
|
||||
});
|
||||
return data.events;
|
||||
}
|
||||
}
|
||||
});
|
||||
}]
|
||||
);
|
||||
|
||||
|
||||
eventManServices.factory('Setting', ['$resource', '$rootScope',
|
||||
function($resource, $rootScope) {
|
||||
return $resource('settings/', {}, {
|
||||
|
|
|
@ -550,40 +550,6 @@ class CollectionHandler(BaseHandler):
|
|||
self.logger.error('Error yielding WebSocket message: %s', e)
|
||||
|
||||
|
||||
class PersonsHandler(CollectionHandler):
|
||||
"""Handle requests for Persons."""
|
||||
|
||||
def handle_get_events(self, id_, resource_id=None, **kwargs):
|
||||
# Get a list of events attended by this person.
|
||||
# Inside the data of each event, a 'person_data' dictionary is
|
||||
# created, duplicating the entry for the current person (so that
|
||||
# there's no need to parse the 'persons' list on the client).
|
||||
#
|
||||
# If resource_id is given, only the specified event is considered.
|
||||
#
|
||||
# If the 'all' parameter is given, every event (also unattended ones) is returned.
|
||||
args = self.request.arguments
|
||||
query = {}
|
||||
if id_ and not self.tobool(args.get('all')):
|
||||
query = {'persons.person_id': id_}
|
||||
if resource_id:
|
||||
query['_id'] = resource_id
|
||||
|
||||
events = self.db.query('events', query)
|
||||
for event in events:
|
||||
person_data = {}
|
||||
for persons in event.get('persons') or []:
|
||||
if str(persons.get('person_id')) == id_:
|
||||
person_data = persons
|
||||
break
|
||||
if 'persons' in event:
|
||||
del event['persons']
|
||||
event['person_data'] = person_data
|
||||
if resource_id and events:
|
||||
return events[0]
|
||||
return {'events': events}
|
||||
|
||||
|
||||
class EventsHandler(CollectionHandler):
|
||||
"""Handle requests for Events."""
|
||||
document = 'event'
|
||||
|
@ -1045,12 +1011,9 @@ def run():
|
|||
{'setting': 'server_cookie_secret', 'cookie_secret': cookie_secret})
|
||||
|
||||
_ws_handler = (r"/ws/+event/+(?P<event_id>[\w\d_-]+)/+tickets/+updates/?", WebSocketEventUpdatesHandler)
|
||||
_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_-]+)?"
|
||||
application = tornado.web.Application([
|
||||
(_persons_path, PersonsHandler, init_params),
|
||||
(r'/v%s%s' % (API_VERSION, _persons_path), PersonsHandler, init_params),
|
||||
(_events_path, EventsHandler, init_params),
|
||||
(r'/v%s%s' % (API_VERSION, _events_path), EventsHandler, init_params),
|
||||
(_users_path, UsersHandler, init_params),
|
||||
|
|
Loading…
Reference in a new issue