From fee4458be1855e4d8e0e8d4bb71791c1f4074585 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 2 Jul 2016 00:05:50 +0200 Subject: [PATCH 01/34] fixes #139: quick add using the custom form --- angular_app/event-tickets.html | 39 +++------------------ angular_app/js/controllers.js | 46 +++++++++++++++++-------- angular_app/modal-quick-add-ticket.html | 19 ++++++++++ 3 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 angular_app/modal-quick-add-ticket.html diff --git a/angular_app/event-tickets.html b/angular_app/event-tickets.html index 86723bb..771109b 100644 --- a/angular_app/event-tickets.html +++ b/angular_app/event-tickets.html @@ -9,6 +9,11 @@ {{'Edit' | translate}} +   +
@@ -77,40 +82,6 @@
- -
-
{{'Quick add' | translate}}
-
-
-
- {{'Name' | translate}} - -
-
- {{'Surname' | translate}} - -
-
- {{'Email' | translate}} - -
-
- {{'Company' | translate}} - -
-
- {{'Job' | translate}} - -
- - -
-
-
-
{{'Unregistered persons' | translate}}
diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index a721ffe..6cc759b 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -51,23 +51,23 @@ eventManControllers.controller('DatetimePickerCtrl', ['$scope', /* Controller for modals. */ -eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$modalInstance', 'message', - function ($scope, $modalInstance, message) { +eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$uibModalInstance', 'message', + function ($scope, $uibModalInstance, message) { $scope.message = message; $scope.ok = function () { - $modalInstance.close($scope); + $uibModalInstance.close($scope); }; $scope.cancel = function () { - $modalInstance.dismiss('cancel'); + $uibModalInstance.dismiss('cancel'); }; }] ); -eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$modal', '$log', '$translate', '$rootScope', - function ($scope, Event, $modal, $log, $translate, $rootScope) { +eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope', + function ($scope, Event, $uibModal, $log, $translate, $rootScope) { $scope.events = Event.all(); $scope.personsOrderProp = 'name'; $scope.eventsOrderProp = "-begin_date"; @@ -80,7 +80,7 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$modal', ' }); $scope.remove = function(_id) { - var modalInstance = $modal.open({ + var modalInstance = $uibModal.open({ scope: $scope, templateUrl: 'modal-confirm-action.html', controller: 'ModalConfirmInstanceCtrl', @@ -99,8 +99,8 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$modal', ' ); -eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', 'easyFormSteWayConfig', - function ($scope, $state, Event, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope, easyFormSteWayConfig) { +eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', 'easyFormSteWayConfig', '$uibModal', + function ($scope, $state, Event, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope, easyFormSteWayConfig, $uibModal) { $scope.personsOrder = ["name", "surname"]; $scope.countAttendees = 0; $scope.message = {}; @@ -265,6 +265,16 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', } }; + $scope.openQuickAddTicket = function(_id) { + var modalInstance = $uibModal.open({ + templateUrl: 'modal-quick-add-ticket.html', + controller: 'EventTicketsCtrl' + }); + modalInstance.result.then(function(x) { + $scope.event = Event.get($stateParams); + }); + }; + $scope.addRegisteredPerson = function(person) { $scope.fastAddAttendee(person, true); }; @@ -425,7 +435,11 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', person._id = $state.params.id; // that's the id of the event, not the person. EventTicket.add(person, function(ticket) { $log.debug(ticket); - $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); + if (!$state.is('event.tickets')) { + $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); + } else if ($scope.$close) { + $scope.$close(); + } }); }); }; @@ -464,14 +478,18 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }; $scope.cancelForm = function() { - $state.go('events'); + if (!$state.is('event.tickets')) { + $state.go('events'); + } else if ($scope.$close) { + $scope.$close(); + } }; }] ); -eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting', '$modal', '$translate', '$rootScope', - function ($scope, Person, Setting, $modal, $translate, $rootScope) { +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', @@ -511,7 +529,7 @@ eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting' }; $scope.remove = function(_id) { - var modalInstance = $modal.open({ + var modalInstance = $uibModal.open({ scope: $scope, templateUrl: 'modal-confirm-action.html', controller: 'ModalConfirmInstanceCtrl', diff --git a/angular_app/modal-quick-add-ticket.html b/angular_app/modal-quick-add-ticket.html new file mode 100644 index 0000000..1153024 --- /dev/null +++ b/angular_app/modal-quick-add-ticket.html @@ -0,0 +1,19 @@ +
+ + + + + +
+ From 9642bfa3b7f4fbf81d59599cc2cd547bff7bf2af Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 2 Jul 2016 13:46:39 +0200 Subject: [PATCH 02/34] partial renaming of person_id parameter --- angular_app/js/controllers.js | 100 ++++++++++++++++++---------------- angular_app/js/services.js | 20 ++++--- eventman_server.py | 23 ++++---- 3 files changed, 73 insertions(+), 70 deletions(-) diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 6cc759b..c7824cb 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -99,8 +99,8 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal' ); -eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', 'easyFormSteWayConfig', '$uibModal', - function ($scope, $state, Event, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope, easyFormSteWayConfig, $uibModal) { +eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', '$uibModal', + function ($scope, $state, Event, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope, $uibModal) { $scope.personsOrder = ["name", "surname"]; $scope.countAttendees = 0; $scope.message = {}; @@ -146,12 +146,13 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope.event.persons = []; } var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return data.person_id == el.person_id; + return data._id == el._id; }); + $log.debug(data); if (person_idx != -1) { - $log.debug('person_id ' + data.person_id + ' found'); + $log.debug('_id ' + data._id + ' found'); } else { - $log.debug('person_id ' + data.person_id + ' not found'); + $log.debug('_id ' + data._id + ' not found'); } if (data.action == 'update' && person_idx != -1 && $scope.event.persons[person_idx] != data.person) { @@ -159,7 +160,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', } else if (data.action == 'add' && person_idx == -1) { $scope._localAddAttendee(data.person, true); } else if (data.action == 'delete' && person_idx != -1) { - $scope._localRemoveAttendee({person_id: data.person_id}); + $scope._localRemoveAttendee({_id: data._id}); } } ); @@ -214,12 +215,12 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', }; /* Stuff to do when an attendee is added locally. */ - $scope._localAddAttendee = function(person, hideMessage) { + $scope._localAddAttendee = function(person) { if (!$scope.event.persons) { $scope.event.persons = []; } var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return person.person_id == el.person_id; + return person._id == el._id; }); if (person_idx != -1) { $log.debug('person already present: not added'); @@ -228,8 +229,25 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope.event.persons.push(person); }; + $rootScope.$on('event.ticket.new', function(evt, ticket) { + $scope._localAddAttendee(ticket); + }); + + $rootScope.$on('event.ticket.update', function(evt, ticket) { + if (!$scope.event.persons) { + $scope.event.persons = []; + } + var ticket_idx = $scope.event.persons.findIndex(function(el, idx, array) { + return ticket._id == el._id; + }); + if (ticket_idx == -1) { + $log.debug('person not present: not updated'); + return false; + } + $scope.event.persons[ticket_idx] = ticket; + }); + $scope._addAttendee = function(person) { - person.person_id = person._id; person._id = $stateParams.id; // that's the id of the event, not the person. Event.addPerson(person, function() { $scope._localAddAttendee(person); @@ -241,7 +259,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope._setAttended = function(person) { $scope.setPersonAttribute(person, 'attended', true, function() { var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { - return person.person_id == el.person_id; + return person._id == el._id; }); if (all_person_idx != -1) { $scope.allPersons.splice(all_person_idx, 1); @@ -249,20 +267,11 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', }, true); }; - $scope.fastAddAttendee = function(person, isNew) { + $scope.fastAddAttendee = function(person) { $log.debug('EventDetailsCtrl.fastAddAttendee.person:'); $log.debug(person); - if (isNew) { - var personObj = new Person(person); - personObj.$save(function(p) { - person = $scope._addAttendee(angular.copy(p)); - $scope._setAttended(person); - $scope.newPerson = {}; - }); - } else { - person = $scope._addAttendee(angular.copy(person)); - $scope._setAttended(person); - } + person = $scope._addAttendee(angular.copy(person)); + $scope._setAttended(person); }; $scope.openQuickAddTicket = function(_id) { @@ -271,7 +280,6 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', controller: 'EventTicketsCtrl' }); modalInstance.result.then(function(x) { - $scope.event = Event.get($stateParams); }); }; @@ -281,9 +289,9 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope.setPersonAttribute = function(person, key, value, callback, hideMessage) { $log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $stateParams.id); - $log.debug('EventDetailsCtrl.setPersonAttribute.person_id: ' + person.person_id); + $log.debug('EventDetailsCtrl.setPersonAttribute._id: ' + person._id); $log.debug('EventDetailsCtrl.setPersonAttribute.key: ' + key + ' value: ' + value); - var data = {_id: $stateParams.id, person_id: person.person_id}; + var data = {_id: $stateParams.id, ticket_id: person._id}; data[key] = value; Event.updatePerson(data, function(data) { @@ -291,10 +299,10 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', return; } var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return data.person_id == el.person_id; + return data._id == el._id; }); if (person_idx == -1) { - $log.warn('unable to find person_id ' + person_id); + $log.warn('unable to find _id ' + _id); return; } if ($scope.event.persons[person_idx] != data.person) { @@ -325,14 +333,14 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope._localRemoveAttendee = function(person) { $log.debug('_localRemoveAttendee'); $log.debug(person); - if (!(person && person.person_id && $scope.event.persons)) { + if (!(person && person._id && $scope.event.persons)) { return; } var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return person.person_id == el.person_id; + return person._id == el._id; }); if (person_idx == -1) { - $log.warn('unable to find and delete person_id ' + person.person_id); + $log.warn('unable to find and delete _id ' + person._id); return; } var removed_person = $scope.event.persons.splice(person_idx, 1); @@ -343,7 +351,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { return person.person_id == el._id; }); - if (all_person_idx == -1 && person.person_id) { + if (all_person_idx == -1 && person._id) { $scope.allPersons.push(person); } }; @@ -351,7 +359,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope.removeAttendee = function(person) { Event.deletePerson({ _id: $stateParams.id, - person_id: person.person_id + ticket_id: person._id }, function() { $scope._localRemoveAttendee(person); }); @@ -429,26 +437,22 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }; $scope.addTicket = function(person) { - var personObj = new Person(person); - personObj.$save(function(p) { - person.person_id = p._id; - person._id = $state.params.id; // that's the id of the event, not the person. - EventTicket.add(person, function(ticket) { - $log.debug(ticket); - if (!$state.is('event.tickets')) { - $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); - } else if ($scope.$close) { - $scope.$close(); - } - }); + person.event_id = $state.params.id; + EventTicket.add(person, function(ticket) { + $log.debug(ticket); + $rootScope.$emit('event.ticket.new', ticket); + if (!$state.is('event.tickets')) { + $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); + } else if ($scope.$close) { + $scope.$close(); + } }); }; $scope.updateTicket = function(ticket, cb) { - var data = angular.copy(ticket); - data.ticket_id = data._id; - data._id = $state.params.id; - EventTicket.update(data, function(t) { + ticket.event_id = $state.params.id; + EventTicket.update(ticket, function(t) { + $rootScope.$emit('event.ticket.update', ticket); if (cb) { cb(t); } diff --git a/angular_app/js/services.js b/angular_app/js/services.js index 118af9d..e137b59 100644 --- a/angular_app/js/services.js +++ b/angular_app/js/services.js @@ -18,7 +18,7 @@ function convert_dates(obj) { eventManServices.factory('Event', ['$resource', '$rootScope', function($resource, $rootScope) { - return $resource('events/:id', {id: '@_id', person_id: '@person_id'}, { + return $resource('events/:id', {id: '@_id', ticket_id: '@_id'}, { all: { method: 'GET', @@ -64,7 +64,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope', method: 'PUT', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, - url: 'events/:id/persons/:person_id', + url: 'events/:id/tickets/:ticket_id', params: {uuid: $rootScope.app_uuid}, transformResponse: function(data, headers) { return angular.fromJson(data); @@ -75,7 +75,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope', method: 'POST', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, - url: 'events/:id/persons/:person_id', + url: 'events/:id/tickets', params: {uuid: $rootScope.app_uuid}, transformResponse: function(data, headers) { return angular.fromJson(data); @@ -86,7 +86,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope', method: 'DELETE', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, - url: 'events/:_id/persons/:person_id', + url: 'events/:_id/persons/:ticket_id', params: {uuid: $rootScope.app_uuid}, transformResponse: function(data, headers) { return angular.fromJson(data); @@ -99,7 +99,7 @@ eventManServices.factory('Event', ['$resource', '$rootScope', eventManServices.factory('EventTicket', ['$resource', '$rootScope', function($resource, $rootScope) { - return $resource('events/:id/tickets', {id: '@_id', ticket_id: '@ticket_id'}, { + return $resource('events/:id/tickets', {event_id: '@event_id', ticket_id: '@_id'}, { get: { method: 'GET', @@ -115,7 +115,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', method: 'POST', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, - url: 'events/:id/tickets/:ticket_id', + url: 'events/:event_id/tickets', params: {uuid: $rootScope.app_uuid}, transformResponse: function(data, headers) { data = angular.fromJson(data); @@ -123,11 +123,11 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', } }, - update: { + updateTicket: { method: 'PUT', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, - url: 'events/:id/tickets/:ticket_id', + url: 'events/:event_id/tickets/:ticket_id', params: {uuid: $rootScope.app_uuid}, transformResponse: function(data, headers) { return angular.fromJson(data); @@ -138,7 +138,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', method: 'DELETE', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, - url: 'events/:_id/tickets/:ticket_id', + url: 'events/:event_id/tickets/:ticket_id', params: {uuid: $rootScope.app_uuid}, transformResponse: function(data, headers) { return angular.fromJson(data); @@ -158,6 +158,8 @@ eventManServices.factory('Person', ['$resource', '$rootScope', interceptor : {responseError: $rootScope.errorHandler}, isArray: true, transformResponse: function(data, headers) { + // TODO: REMOVE! + return []; data = angular.fromJson(data); if (data.error) { return data; diff --git a/eventman_server.py b/eventman_server.py index 06693bc..66fe5a7 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -592,7 +592,7 @@ class EventsHandler(CollectionHandler): if all(person.get(k) == v for k, v in person_id_or_query.iteritems()): return person else: - if str(person.get('person_id')) == person_id_or_query: + if str(person.get('_id')) == person_id_or_query: return person return {} @@ -622,8 +622,8 @@ class EventsHandler(CollectionHandler): if person_id is None: doc = {} else: - doc = self.db.query('events', {'_id': id_, 'persons.person_id': person_id}) - ret = {'action': 'add', 'person_id': person_id, 'person': data, 'uuid': uuid} + doc = self.db.query('events', {'_id': id_, 'persons._id': person_id}) + ret = {'action': 'add', '_id': person_id, 'person': data, 'uuid': uuid} if '_id' in data: del data['_id'] self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) @@ -644,12 +644,9 @@ class EventsHandler(CollectionHandler): uuid, arguments = self.uuid_arguments query = dict([('persons.%s' % k, v) for k, v in arguments.iteritems()]) query['_id'] = id_ - if ticket: + if person_id is not None: query['persons._id'] = person_id person_query = {'_id': person_id} - elif person_id is not None: - query['persons.person_id'] = person_id - person_query = person_id else: person_query = self.arguments old_person_data = {} @@ -667,8 +664,8 @@ class EventsHandler(CollectionHandler): env = self._dict2env(new_person_data) # always takes the person_id from the new person (it may have # been a ticket_id). - person_id = str(new_person_data.get('person_id')) - env.update({'PERSON_ID': person_id, 'EVENT_ID': id_, + ticket_id = str(new_person_data.get('_id')) + env.update({'PERSON_ID': ticket_id, 'TICKED_ID': ticket_id, 'EVENT_ID': id_, 'EVENT_TITLE': doc.get('title', ''), 'WEB_USER': self.current_user, 'WEB_REMOTE_IP': self.request.remote_ip}) stdin_data = {'old': old_person_data, @@ -681,7 +678,7 @@ class EventsHandler(CollectionHandler): if new_person_data.get('attended'): self.run_triggers('attends', stdin_data=stdin_data, env=env) - ret = {'action': 'update', 'person_id': person_id, 'person': new_person_data, 'uuid': uuid} + ret = {'action': 'update', '_id': ticket_id, 'person': new_person_data, 'uuid': uuid} if old_person_data != new_person_data: self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) return ret @@ -693,12 +690,12 @@ class EventsHandler(CollectionHandler): # Remove a specific person from the list of persons registered at this event. uuid, arguments = self.uuid_arguments doc = self.db.query('events', - {'_id': id_, 'persons.person_id': person_id}) - ret = {'action': 'delete', 'person_id': person_id, 'uuid': uuid} + {'_id': id_, 'persons._id': person_id}) + ret = {'action': 'delete', '_id': person_id, 'uuid': uuid} if doc: merged, doc = self.db.update('events', {'_id': id_}, - {'persons': {'person_id': person_id}}, + {'persons': {'_id': person_id}}, operation='delete', create=False) self.send_ws_message('event/%s/tickets/updates' % id_, json.dumps(ret)) From a5c510de0d8552ffa8c762b20960d644e6cd7377 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 2 Jul 2016 14:49:39 +0200 Subject: [PATCH 03/34] unify services --- angular_app/js/app.js | 2 +- angular_app/js/controllers.js | 292 ++++++++++++++++------------------ angular_app/js/services.js | 37 +---- 3 files changed, 144 insertions(+), 187 deletions(-) diff --git a/angular_app/js/app.js b/angular_app/js/app.js index 25ba094..fae6b3b 100644 --- a/angular_app/js/app.js +++ b/angular_app/js/app.js @@ -129,7 +129,7 @@ eventManApp.config(['$stateProvider', '$urlRouterProvider', .state('event.tickets', { url: '/:id/tickets', templateUrl: 'event-tickets.html', - controller: 'EventDetailsCtrl' + controller: 'EventTicketsCtrl' }) .state('event.ticket', { url: '/:id/ticket', diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index c7824cb..c6dd0ad 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -69,7 +69,6 @@ eventManControllers.controller('ModalConfirmInstanceCtrl', ['$scope', '$uibModal eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal', '$log', '$translate', '$rootScope', function ($scope, Event, $uibModal, $log, $translate, $rootScope) { $scope.events = Event.all(); - $scope.personsOrderProp = 'name'; $scope.eventsOrderProp = "-begin_date"; $scope.confirm_delete = 'Do you really want to delete this event?'; @@ -99,30 +98,80 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal' ); -eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Person', 'EventUpdates', '$stateParams', 'Setting', '$log', '$translate', '$rootScope', '$uibModal', - function ($scope, $state, Event, Person, EventUpdates, $stateParams, Setting, $log, $translate, $rootScope, $uibModal) { - $scope.personsOrder = ["name", "surname"]; - $scope.countAttendees = 0; - $scope.message = {}; +eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Setting', '$log', '$translate', '$rootScope', '$uibModal', + function ($scope, $state, Event, Setting, $log, $translate, $rootScope, $uibModal) { $scope.event = {}; $scope.event.persons = []; $scope.event.formSchema = {}; $scope.eventFormDisabled = false; + + if ($state.params.id) { + $scope.event = Event.get($state.params); + if ($state.is('event.view') || !$rootScope.hasPermission('event|update')) { + $scope.eventFormDisabled = true; + } + } + + // store a new Event or update an existing one + $scope.save = function() { + // avoid override of event.persons list. + var this_event = angular.copy($scope.event); + if (this_event.persons) { + delete this_event.persons; + } + if (this_event._id === undefined) { + $scope.event = Event.save(this_event); + } else { + $scope.event = Event.update(this_event); + } + $scope.eventForm.$setPristine(false); + }; + }] +); + + +eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', + function ($scope, $state, Event, EventTicket, Person, Setting, $log, $translate, $rootScope, EventUpdates) { + $scope.personsOrder = ["name", "surname"]; + $scope.countAttendees = 0; + $scope.message = {}; + $scope.event = {}; + $scope.ticket = {}; + $scope.formSchema = {}; + $scope.formData = {}; + $scope.dangerousActionsEnabled = false; $scope.customFields = Setting.query({setting: 'person_custom_field', in_event_details: true}); - if ($stateParams.id) { - $scope.event = Event.get($stateParams, function() { + $scope.formFieldsMap = {}; + $scope.formFieldsMapRev = {}; + + if ($state.params.id) { + $scope.event = Event.get({id: $state.params.id}, function(data) { $scope.$watchCollection(function() { return $scope.event.persons; }, function(prev, old) { $scope.calcAttendees(); } ); - }); + if (!(data && data.formSchema)) { + return; + } + $scope.formSchema = data.formSchema.edaFieldsModel; + $scope.extractFormFields(data.formSchema.formlyFieldsModel); - if ($state.is('event.view') || !$rootScope.hasPermission('event|update')) { - $scope.eventFormDisabled = true; - } + if ($state.params.ticket_id) { + EventTicket.get({id: $state.params.id, ticket_id: $state.params.ticket_id}, function(data) { + $scope.ticket = data; + angular.forEach(data, function(value, key) { + if (!$scope.formFieldsMapRev[key]) { + return; + } + $scope.formData[$scope.formFieldsMapRev[key]] = value; + }); + }); + } + + }); if ($state.is('event.tickets')) { $scope.allPersons = Person.all(); @@ -158,7 +207,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', if (data.action == 'update' && person_idx != -1 && $scope.event.persons[person_idx] != data.person) { $scope.event.persons[person_idx] = data.person; } else if (data.action == 'add' && person_idx == -1) { - $scope._localAddAttendee(data.person, true); + $scope._localAddTicket(data.person); } else if (data.action == 'delete' && person_idx != -1) { $scope._localRemoveAttendee({_id: data._id}); } @@ -167,39 +216,6 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', } } - $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; - }; - - // store a new Event or update an existing one - $scope.save = function() { - // avoid override of event.persons list. - var this_event = angular.copy($scope.event); - if (this_event.persons) { - delete this_event.persons; - } - if (this_event._id === undefined) { - $scope.event = Event.save(this_event); - } else { - $scope.event = Event.update(this_event); - } - $scope.eventForm.$setPristine(false); - }; - $scope.calcAttendees = function() { if (!($scope.event && $scope.event.persons)) { $scope.countAttendees = 0; @@ -215,7 +231,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', }; /* Stuff to do when an attendee is added locally. */ - $scope._localAddAttendee = function(person) { + $scope._localAddTicket = function(person) { if (!$scope.event.persons) { $scope.event.persons = []; } @@ -230,7 +246,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', }; $rootScope.$on('event.ticket.new', function(evt, ticket) { - $scope._localAddAttendee(ticket); + $scope._localAddTicket(ticket); }); $rootScope.$on('event.ticket.update', function(evt, ticket) { @@ -247,10 +263,10 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope.event.persons[ticket_idx] = ticket; }); - $scope._addAttendee = function(person) { - person._id = $stateParams.id; // that's the id of the event, not the person. - Event.addPerson(person, function() { - $scope._localAddAttendee(person); + $scope._addTicket = function(person) { + person.event_id = $state.params.id; + EventTicket.add(person, function() { + $scope._localAddTicket(person); }); $scope.query = ''; return person; @@ -270,57 +286,43 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope.fastAddAttendee = function(person) { $log.debug('EventDetailsCtrl.fastAddAttendee.person:'); $log.debug(person); - person = $scope._addAttendee(angular.copy(person)); + person = $scope._addTicket(angular.copy(person)); $scope._setAttended(person); }; - $scope.openQuickAddTicket = function(_id) { - var modalInstance = $uibModal.open({ - templateUrl: 'modal-quick-add-ticket.html', - controller: 'EventTicketsCtrl' - }); - modalInstance.result.then(function(x) { - }); - }; - - $scope.addRegisteredPerson = function(person) { - $scope.fastAddAttendee(person, true); - }; - $scope.setPersonAttribute = function(person, key, value, callback, hideMessage) { - $log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $stateParams.id); + $log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $state.params.id); $log.debug('EventDetailsCtrl.setPersonAttribute._id: ' + person._id); $log.debug('EventDetailsCtrl.setPersonAttribute.key: ' + key + ' value: ' + value); - var data = {_id: $stateParams.id, ticket_id: person._id}; - data[key] = value; - Event.updatePerson(data, - function(data) { - if (!(data && data.person_id && data.person)) { - return; - } - var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return data._id == el._id; - }); - if (person_idx == -1) { - $log.warn('unable to find _id ' + _id); - return; - } - if ($scope.event.persons[person_idx] != data.person) { - $scope.event.persons[person_idx] = data.person; - } - if (callback) { - callback(data); - } - if (key === 'attended' && !hideMessage) { - var msg = {}; - if (value) { - msg.message = '' + person.name + ' ' + person.surname + ' successfully added to event ' + $scope.event.title; - } else { - msg.message = '' + person.name + ' ' + person.surname + ' successfully removed from event ' + $scope.event.title; - msg.isError = true; - } - $scope.showMessage(msg); + var newData = {event_id: $state.params.id, _id: person._id}; + newData[key] = value; + EventTicket.update(newData, function(data) { + if (!(data && data._id && data.person)) { + return; + } + var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { + return data._id == el._id; + }); + if (person_idx == -1) { + $log.warn('unable to find ticket _id ' + _id); + return; + } + if ($scope.event.persons[person_idx] != data.person) { + $scope.event.persons[person_idx] = data.person; + } + if (callback) { + callback(data); + } + if (key === 'attended' && !hideMessage) { + var msg = {}; + if (value) { + msg.message = '' + person.name + ' ' + person.surname + ' successfully added to event ' + $scope.event.title; + } else { + msg.message = '' + person.name + ' ' + person.surname + ' successfully removed from event ' + $scope.event.title; + msg.isError = true; } + $scope.showMessage(msg); + } }); }; @@ -340,7 +342,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', return person._id == el._id; }); if (person_idx == -1) { - $log.warn('unable to find and delete _id ' + person._id); + $log.warn('unable to find and delete ticket _id ' + person._id); return; } var removed_person = $scope.event.persons.splice(person_idx, 1); @@ -349,7 +351,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', person = removed_person[0]; } var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { - return person.person_id == el._id; + return person._id == el._id; }); if (all_person_idx == -1 && person._id) { $scope.allPersons.push(person); @@ -357,8 +359,8 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', }; $scope.removeAttendee = function(person) { - Event.deletePerson({ - _id: $stateParams.id, + EventTicket.delete({ + event_id: $state.params.id, ticket_id: person._id }, function() { $scope._localRemoveAttendee(person); @@ -374,48 +376,6 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', $scope.message.show(cfg); }; - $scope.$on('$destroy', function() { - $scope.EventUpdates && $scope.EventUpdates.close(); - }); - }] -); - - -eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'Setting', '$log', '$translate', '$rootScope', - function ($scope, $state, Event, EventTicket, Person, Setting, $log, $translate, $rootScope) { - $scope.message = {}; - $scope.event = {}; - $scope.ticket = {}; - $scope.formSchema = {}; - $scope.formData = {}; - $scope.dangerousActionsEnabled = false; - - $scope.formFieldsMap = {}; - $scope.formFieldsMapRev = {}; - - if ($state.params.id) { - $scope.event = Event.get({id: $state.params.id}, function(data) { - if (!(data && data.formSchema)) { - return; - } - $scope.formSchema = data.formSchema.edaFieldsModel; - $scope.extractFormFields(data.formSchema.formlyFieldsModel); - - if ($state.params.ticket_id) { - EventTicket.get({id: $state.params.id, ticket_id: $state.params.ticket_id}, function(data) { - $scope.ticket = data; - angular.forEach(data, function(value, key) { - if (!$scope.formFieldsMapRev[key]) { - return; - } - $scope.formData[$scope.formFieldsMapRev[key]] = value; - }); - }); - } - - }); - } - $scope.extractFormFields = function(formlyFieldsModel) { if (!formlyFieldsModel) { return; @@ -436,6 +396,32 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }); }; + $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.openQuickAddTicket = function(_id) { + var modalInstance = $uibModal.open({ + templateUrl: 'modal-quick-add-ticket.html' + }); + modalInstance.result.then(function(x) { + }); + }; + $scope.addTicket = function(person) { person.event_id = $state.params.id; EventTicket.add(person, function(ticket) { @@ -488,6 +474,10 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.$close(); } }; + + $scope.$on('$destroy', function() { + $scope.EventUpdates && $scope.EventUpdates.close(); + }); }] ); @@ -552,17 +542,17 @@ eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting' ); -eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$stateParams', 'Person', 'Event', 'Setting', '$log', - function ($scope, $stateParams, Person, Event, Setting, $log) { +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 ($stateParams.id) { - $scope.person = Person.get($stateParams); - $scope.events = Person.getEvents({_id: $stateParams.id, all: 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(); } @@ -595,11 +585,11 @@ eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$stateParams', ' }; $scope.setPersonAttributeAtEvent = function(evnt, key, value) { - var attrs = {_id: evnt._id, person_id: $stateParams.id}; + var attrs = {_id: evnt._id, person_id: $state.params.id}; attrs[key] = value; Event.updatePerson(attrs, function(data) { - $scope.events = Person.getEvents({_id: $stateParams.id, all: true}); + $scope.events = Person.getEvents({_id: $state.params.id, all: true}); } ); }; @@ -615,13 +605,13 @@ eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$stateParams', ' data.attended = false; Event.addPerson(data, function(data) { - $scope.events = Person.getEvents({_id: $stateParams.id, all: true}); + $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: $stateParams.id, all: true}); + $scope.events = Person.getEvents({_id: $state.params.id, all: true}); } ); } diff --git a/angular_app/js/services.js b/angular_app/js/services.js index e137b59..171f775 100644 --- a/angular_app/js/services.js +++ b/angular_app/js/services.js @@ -58,39 +58,6 @@ eventManServices.factory('Event', ['$resource', '$rootScope', update: { method: 'PUT', interceptor : {responseError: $rootScope.errorHandler} - }, - - updatePerson: { - method: 'PUT', - interceptor : {responseError: $rootScope.errorHandler}, - isArray: false, - url: 'events/:id/tickets/:ticket_id', - params: {uuid: $rootScope.app_uuid}, - transformResponse: function(data, headers) { - return angular.fromJson(data); - } - }, - - addPerson: { - method: 'POST', - interceptor : {responseError: $rootScope.errorHandler}, - isArray: false, - url: 'events/:id/tickets', - params: {uuid: $rootScope.app_uuid}, - transformResponse: function(data, headers) { - return angular.fromJson(data); - } - }, - - deletePerson: { - method: 'DELETE', - interceptor : {responseError: $rootScope.errorHandler}, - isArray: false, - url: 'events/:_id/persons/:ticket_id', - params: {uuid: $rootScope.app_uuid}, - transformResponse: function(data, headers) { - return angular.fromJson(data); - } } }); }] @@ -123,7 +90,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', } }, - updateTicket: { + update: { method: 'PUT', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, @@ -134,7 +101,7 @@ eventManServices.factory('EventTicket', ['$resource', '$rootScope', } }, - deleteTicket: { + 'delete': { method: 'DELETE', interceptor : {responseError: $rootScope.errorHandler}, isArray: false, From e4fba8039d37fd8338cb50e7973221d05cb8543b Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 2 Jul 2016 19:05:28 +0200 Subject: [PATCH 04/34] fix ticket cancellation --- angular_app/js/controllers.js | 21 ++++++++++++--------- angular_app/ticket-edit.html | 21 ++++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index c6dd0ad..d2a0341 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -98,8 +98,8 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$uibModal' ); -eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', 'Setting', '$log', '$translate', '$rootScope', '$uibModal', - function ($scope, $state, Event, Setting, $log, $translate, $rootScope, $uibModal) { +eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', '$log', '$translate', '$rootScope', + function ($scope, $state, Event, $log, $translate, $rootScope) { $scope.event = {}; $scope.event.persons = []; $scope.event.formSchema = {}; @@ -130,8 +130,8 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', ); -eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', 'EventTicket', 'Person', 'Setting', '$log', '$translate', '$rootScope', 'EventUpdates', - function ($scope, $state, Event, EventTicket, Person, Setting, $log, $translate, $rootScope, EventUpdates) { +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) { $scope.personsOrder = ["name", "surname"]; $scope.countAttendees = 0; $scope.message = {}; @@ -139,7 +139,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.ticket = {}; $scope.formSchema = {}; $scope.formData = {}; - $scope.dangerousActionsEnabled = false; + $scope.guiOptions = {dangerousActionsEnabled: false}; $scope.customFields = Setting.query({setting: 'person_custom_field', in_event_details: true}); $scope.formFieldsMap = {}; @@ -416,9 +416,10 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.openQuickAddTicket = function(_id) { var modalInstance = $uibModal.open({ - templateUrl: 'modal-quick-add-ticket.html' + templateUrl: 'modal-quick-add-ticket.html', + controller: 'EventTicketsCtrl' }); - modalInstance.result.then(function(x) { + modalInstance.result.then(function() { }); }; @@ -430,6 +431,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', if (!$state.is('event.tickets')) { $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); } else if ($scope.$close) { + $scope._setAttended(person); $scope.$close(); } }); @@ -462,8 +464,8 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', return; } $scope.ticket.cancelled = !$scope.ticket.cancelled; - $scope.updateTicket($scope.ticket, function() { - $scope.dangerousActionsEnabled = false; + $scope.setPersonAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() { + $scope.guiOptions.dangerousActionsEnabled = false; }); }; @@ -619,6 +621,7 @@ eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$state', 'Person }] ); + eventManControllers.controller('LoginCtrl', ['$scope', '$rootScope', '$state', '$log', 'User', function ($scope, $rootScope, $state, $log, User) { $scope.loginData = {}; diff --git a/angular_app/ticket-edit.html b/angular_app/ticket-edit.html index 90060ec..bd1ca1f 100644 --- a/angular_app/ticket-edit.html +++ b/angular_app/ticket-edit.html @@ -45,17 +45,16 @@
{{'Dangerous stuff' | translate}}
- -   - - + +   +
From 40eb303cfec54fc1a7e89b5144f1c625549c1ca4 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sat, 2 Jul 2016 20:40:18 +0200 Subject: [PATCH 05/34] simplify ticket adding --- angular_app/event-tickets.html | 2 +- angular_app/js/controllers.js | 221 +++++++++++++++------------------ static/css/eventman.css | 6 +- 3 files changed, 105 insertions(+), 124 deletions(-) diff --git a/angular_app/event-tickets.html b/angular_app/event-tickets.html index 771109b..bfc7a1b 100644 --- a/angular_app/event-tickets.html +++ b/angular_app/event-tickets.html @@ -100,7 +100,7 @@ {{person.email}} - + diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index d2a0341..49b1683 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -126,6 +126,11 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', '$state', 'Event', } $scope.eventForm.$setPristine(false); }; + + $scope.saveForm = function(easyFormGeneratorModel) { + $scope.event.formSchema = easyFormGeneratorModel; + $scope.save(); + }; }] ); @@ -136,7 +141,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.countAttendees = 0; $scope.message = {}; $scope.event = {}; - $scope.ticket = {}; + $scope.ticket = {}; // current ticket, for the event.ticket.* states $scope.formSchema = {}; $scope.formData = {}; $scope.guiOptions = {dangerousActionsEnabled: false}; @@ -159,6 +164,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.formSchema = data.formSchema.edaFieldsModel; $scope.extractFormFields(data.formSchema.formlyFieldsModel); + // Editing an existing ticket if ($state.params.ticket_id) { EventTicket.get({id: $state.params.id, ticket_id: $state.params.ticket_id}, function(data) { $scope.ticket = data; @@ -170,9 +176,9 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }); }); } - }); + // Managing the list of tickets. if ($state.is('event.tickets')) { $scope.allPersons = Person.all(); @@ -195,7 +201,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.event.persons = []; } var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return data._id == el._id; + return data._id == el._id; }); $log.debug(data); if (person_idx != -1) { @@ -209,7 +215,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', } else if (data.action == 'add' && person_idx == -1) { $scope._localAddTicket(data.person); } else if (data.action == 'delete' && person_idx != -1) { - $scope._localRemoveAttendee({_id: data._id}); + $scope._localRemoveTicket({_id: data._id}); } } ); @@ -230,7 +236,8 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.countAttendees = attendees; }; - /* Stuff to do when an attendee is added locally. */ + /* Stuff to do when a ticket is added, modified or removed locally. */ + $scope._localAddTicket = function(person) { if (!$scope.event.persons) { $scope.event.persons = []; @@ -245,16 +252,12 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.event.persons.push(person); }; - $rootScope.$on('event.ticket.new', function(evt, ticket) { - $scope._localAddTicket(ticket); - }); - - $rootScope.$on('event.ticket.update', function(evt, ticket) { + $scope._localUpdateTicket(ticket) { if (!$scope.event.persons) { $scope.event.persons = []; } var ticket_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return ticket._id == el._id; + return ticket._id == el._id; }); if (ticket_idx == -1) { $log.debug('person not present: not updated'); @@ -263,13 +266,30 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.event.persons[ticket_idx] = ticket; }); - $scope._addTicket = function(person) { - person.event_id = $state.params.id; - EventTicket.add(person, function() { - $scope._localAddTicket(person); + $scope._localRemoveTicket = function(person) { + $log.debug('_localRemoveAttendee'); + $log.debug(person); + if (!(person && person._id && $scope.event.persons)) { + return; + } + var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { + return person._id == el._id; }); - $scope.query = ''; - return person; + if (person_idx == -1) { + $log.warn('unable to find and delete ticket _id ' + person._id); + return; + } + var removed_person = $scope.event.persons.splice(person_idx, 1); + // to be used to populate allPersons, if needed. + if (removed_person.length) { + person = removed_person[0]; + } + var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { + return person._id == el._id; + }); + if (all_person_idx == -1 && person._id) { + $scope.allPersons.push(person); + } }; $scope._setAttended = function(person) { @@ -283,13 +303,6 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }, true); }; - $scope.fastAddAttendee = function(person) { - $log.debug('EventDetailsCtrl.fastAddAttendee.person:'); - $log.debug(person); - person = $scope._addTicket(angular.copy(person)); - $scope._setAttended(person); - }; - $scope.setPersonAttribute = function(person, key, value, callback, hideMessage) { $log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $state.params.id); $log.debug('EventDetailsCtrl.setPersonAttribute._id: ' + person._id); @@ -331,49 +344,79 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.query = ''; }; - /* Stuff to do when an attendee is removed locally. */ - $scope._localRemoveAttendee = function(person) { - $log.debug('_localRemoveAttendee'); - $log.debug(person); - if (!(person && person._id && $scope.event.persons)) { - return; - } - var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return person._id == el._id; - }); - if (person_idx == -1) { - $log.warn('unable to find and delete ticket _id ' + person._id); - return; - } - var removed_person = $scope.event.persons.splice(person_idx, 1); - // to be used to populate allPersons, if needed. - if (removed_person.length) { - person = removed_person[0]; - } - var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { - return person._id == el._id; - }); - if (all_person_idx == -1 && person._id) { - $scope.allPersons.push(person); - } - }; - $scope.removeAttendee = function(person) { EventTicket.delete({ event_id: $state.params.id, ticket_id: person._id }, function() { - $scope._localRemoveAttendee(person); + $scope._localRemoveTicket(person); }); }; - $scope.saveForm = function(easyFormGeneratorModel) { - $scope.event.formSchema = easyFormGeneratorModel; - $scope.save(); + $scope.addTicket = function(person) { + person.event_id = $state.params.id; + EventTicket.add(person, function(ticket) { + $log.debug(ticket); + $scope._localAddTicket(ticket); + if (!$state.is('event.tickets')) { + $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); + } else { + $scope.query = ''; + $scope._setAttended(ticket); + if ($scope.$close) { + $scope.$close(); + } + } + }); }; - $scope.showMessage = function(cfg) { - $scope.message.show(cfg); + $scope.updateTicket = function(ticket, cb) { + ticket.event_id = $state.params.id; + EventTicket.update(ticket, function(t) { + $scope._localUpdateTicket(t.person); + if (cb) { + cb(t); + } + }); + }; + + $scope.toggleTicket = function() { + if (!$scope.ticket._id) { + return; + } + $scope.ticket.cancelled = !$scope.ticket.cancelled; + $scope.setPersonAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() { + $scope.guiOptions.dangerousActionsEnabled = false; + }); + }; + + $scope.openQuickAddTicket = function(_id) { + var modalInstance = $uibModal.open({ + templateUrl: 'modal-quick-add-ticket.html', + controller: 'EventTicketsCtrl' + }); + modalInstance.result.then(function() { + }); + }; + + $scope.submitForm = function(dataModelSubmitted) { + angular.forEach(dataModelSubmitted, function(value, key) { + key = $scope.formFieldsMap[key] || key; + $scope.ticket[key] = value; + }); + if (!$state.params.ticket_id) { + $scope.addTicket($scope.ticket); + } else { + $scope.updateTicket($scope.ticket); + } + }; + + $scope.cancelForm = function() { + if (!$state.is('event.tickets')) { + $state.go('events'); + } else if ($scope.$close) { + $scope.$close(); + } }; $scope.extractFormFields = function(formlyFieldsModel) { @@ -414,67 +457,8 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.personsOrder = new_order; }; - $scope.openQuickAddTicket = function(_id) { - var modalInstance = $uibModal.open({ - templateUrl: 'modal-quick-add-ticket.html', - controller: 'EventTicketsCtrl' - }); - modalInstance.result.then(function() { - }); - }; - - $scope.addTicket = function(person) { - person.event_id = $state.params.id; - EventTicket.add(person, function(ticket) { - $log.debug(ticket); - $rootScope.$emit('event.ticket.new', ticket); - if (!$state.is('event.tickets')) { - $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); - } else if ($scope.$close) { - $scope._setAttended(person); - $scope.$close(); - } - }); - }; - - $scope.updateTicket = function(ticket, cb) { - ticket.event_id = $state.params.id; - EventTicket.update(ticket, function(t) { - $rootScope.$emit('event.ticket.update', ticket); - if (cb) { - cb(t); - } - }); - }; - - $scope.submitForm = function(dataModelSubmitted) { - angular.forEach(dataModelSubmitted, function(value, key) { - key = $scope.formFieldsMap[key] || key; - $scope.ticket[key] = value; - }); - if (!$state.params.ticket_id) { - $scope.addTicket($scope.ticket); - } else { - $scope.updateTicket($scope.ticket); - } - }; - - $scope.toggleTicket = function() { - if (!$scope.ticket._id) { - return; - } - $scope.ticket.cancelled = !$scope.ticket.cancelled; - $scope.setPersonAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() { - $scope.guiOptions.dangerousActionsEnabled = false; - }); - }; - - $scope.cancelForm = function() { - if (!$state.is('event.tickets')) { - $state.go('events'); - } else if ($scope.$close) { - $scope.$close(); - } + $scope.showMessage = function(cfg) { + $scope.message.show(cfg); }; $scope.$on('$destroy', function() { @@ -658,6 +642,7 @@ eventManControllers.controller('LoginCtrl', ['$scope', '$rootScope', '$state', ' }] ); + eventManControllers.controller('FileUploadCtrl', ['$scope', '$log', '$upload', 'Event', function ($scope, $log, $upload, Event) { $scope.file = null; diff --git a/static/css/eventman.css b/static/css/eventman.css index aa1640c..45889e8 100644 --- a/static/css/eventman.css +++ b/static/css/eventman.css @@ -8,11 +8,7 @@ body { padding-top: 70px; } padding-bottom: 0px; } -a:focus a:hover { - color: #23527c; -} - -a:hover { +a:focus, a:hover { color: #23527c; } From 06d49cf27e6cf400e5bbad43324e513bc50e1560 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Sun, 3 Jul 2016 00:39:07 +0200 Subject: [PATCH 06/34] rename methods --- angular_app/event-tickets.html | 2 +- angular_app/js/controllers.js | 28 ++++++++++++++-------------- angular_app/ticket-edit.html | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/angular_app/event-tickets.html b/angular_app/event-tickets.html index bfc7a1b..900e2b6 100644 --- a/angular_app/event-tickets.html +++ b/angular_app/event-tickets.html @@ -72,7 +72,7 @@ - + diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 49b1683..66e99bf 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -267,7 +267,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }); $scope._localRemoveTicket = function(person) { - $log.debug('_localRemoveAttendee'); + $log.debug('_localRemoveTicket'); $log.debug(person); if (!(person && person._id && $scope.event.persons)) { return; @@ -292,17 +292,6 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', } }; - $scope._setAttended = function(person) { - $scope.setPersonAttribute(person, 'attended', true, function() { - var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { - return person._id == el._id; - }); - if (all_person_idx != -1) { - $scope.allPersons.splice(all_person_idx, 1); - } - }, true); - }; - $scope.setPersonAttribute = function(person, key, value, callback, hideMessage) { $log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $state.params.id); $log.debug('EventDetailsCtrl.setPersonAttribute._id: ' + person._id); @@ -344,7 +333,18 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.query = ''; }; - $scope.removeAttendee = function(person) { + $scope._setAttended = function(person) { + $scope.setPersonAttribute(person, 'attended', true, function() { + var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { + return person._id == el._id; + }); + if (all_person_idx != -1) { + $scope.allPersons.splice(all_person_idx, 1); + } + }, true); + }; + + $scope.deleteTicket = function(person) { EventTicket.delete({ event_id: $state.params.id, ticket_id: person._id @@ -380,7 +380,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }); }; - $scope.toggleTicket = function() { + $scope.toggleCancelledTicket = function() { if (!$scope.ticket._id) { return; } diff --git a/angular_app/ticket-edit.html b/angular_app/ticket-edit.html index bd1ca1f..7bb7a55 100644 --- a/angular_app/ticket-edit.html +++ b/angular_app/ticket-edit.html @@ -50,7 +50,7 @@ {{'Toggle dangerous actions' | translate}}   -    {{'New event' | translate}}{{event.title}} @@ -77,6 +77,10 @@ {{'Where' | translate}}
+
+ {{'Group ID' | translate}} + +
diff --git a/angular_app/event-tickets.html b/angular_app/event-tickets.html index 900e2b6..7f1afe6 100644 --- a/angular_app/event-tickets.html +++ b/angular_app/event-tickets.html @@ -45,7 +45,7 @@ # - {{'Person' | translate}} {{'Name' | translate}} {{'Surname' | translate}} + {{'Name' | translate}} {{'Surname' | translate}} {{'Attended' | translate}} {{col.label | translate}} @@ -61,11 +61,11 @@

{{person.job_title}} @ {{person.company}}

- + - + {{person[col.key]}} diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 66e99bf..de68acc 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -180,7 +180,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', // Managing the list of tickets. if ($state.is('event.tickets')) { - $scope.allPersons = Person.all(); + $scope.allPersons = Event.group_persons({id: $state.params.id}); // Handle WebSocket connection used to update the list of persons. $scope.EventUpdates = EventUpdates; @@ -203,7 +203,6 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { return data._id == el._id; }); - $log.debug(data); if (person_idx != -1) { $log.debug('_id ' + data._id + ' found'); } else { @@ -238,21 +237,43 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', /* Stuff to do when a ticket is added, modified or removed locally. */ - $scope._localAddTicket = function(person) { + $scope._localAddTicket = function(ticket, original_person) { + var ret = true; if (!$scope.event.persons) { $scope.event.persons = []; } - var person_idx = $scope.event.persons.findIndex(function(el, idx, array) { - return person._id == el._id; + var ticket_idx = $scope.event.persons.findIndex(function(el, idx, array) { + return ticket._id == el._id; }); - if (person_idx != -1) { - $log.debug('person already present: not added'); - return false; + if (ticket_idx != -1) { + $log.warn('ticket already present: not added'); + ret = false; + } else { + $scope.event.persons.push(ticket); } - $scope.event.persons.push(person); + + // Try to remove this person from the allPersons list using ID or email. + var field = null; + var field_value = null; + if (original_person && original_person._id) { + field = '_id'; + field_value = original_person._id; + } else if (ticket.email) { + field = 'email'; + field_value = ticket.email; + } + if (field) { + var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { + return field_value == el[field]; + }); + if (all_person_idx != -1) { + $scope.allPersons.splice(all_person_idx, 1); + } + } + return ret; }; - $scope._localUpdateTicket(ticket) { + $scope._localUpdateTicket = function(ticket) { if (!$scope.event.persons) { $scope.event.persons = []; } @@ -260,15 +281,13 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', return ticket._id == el._id; }); if (ticket_idx == -1) { - $log.debug('person not present: not updated'); + $log.warn('ticket not present: not updated'); return false; } $scope.event.persons[ticket_idx] = ticket; - }); + }; $scope._localRemoveTicket = function(person) { - $log.debug('_localRemoveTicket'); - $log.debug(person); if (!(person && person._id && $scope.event.persons)) { return; } @@ -292,10 +311,8 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', } }; - $scope.setPersonAttribute = function(person, key, value, callback, hideMessage) { - $log.debug('EventDetailsCtrl.setPersonAttribute.event_id: ' + $state.params.id); - $log.debug('EventDetailsCtrl.setPersonAttribute._id: ' + person._id); - $log.debug('EventDetailsCtrl.setPersonAttribute.key: ' + key + ' value: ' + value); + $scope.setTicketAttribute = function(person, key, value, callback, hideMessage) { + $log.debug('setTicketAttribute for _id ' + person._id + ' key: ' + key + ' value: ' + value); var newData = {event_id: $state.params.id, _id: person._id}; newData[key] = value; EventTicket.update(newData, function(data) { @@ -328,20 +345,13 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', }); }; - $scope.setPersonAttributeAndRefocus = function(person, key, value) { - $scope.setPersonAttribute(person, key, value); + $scope.setTicketAttributeAndRefocus = function(person, key, value) { + $scope.setTicketAttribute(person, key, value); $scope.query = ''; }; $scope._setAttended = function(person) { - $scope.setPersonAttribute(person, 'attended', true, function() { - var all_person_idx = $scope.allPersons.findIndex(function(el, idx, array) { - return person._id == el._id; - }); - if (all_person_idx != -1) { - $scope.allPersons.splice(all_person_idx, 1); - } - }, true); + $scope.setTicketAttribute(person, 'attended', true, null, true); }; $scope.deleteTicket = function(person) { @@ -356,8 +366,9 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', $scope.addTicket = function(person) { person.event_id = $state.params.id; EventTicket.add(person, function(ticket) { + $log.debug('addTicket'); $log.debug(ticket); - $scope._localAddTicket(ticket); + $scope._localAddTicket(ticket, person); if (!$state.is('event.tickets')) { $state.go('event.ticket.edit', {id: $scope.event._id, ticket_id: ticket._id}); } else { @@ -385,7 +396,7 @@ eventManControllers.controller('EventTicketsCtrl', ['$scope', '$state', 'Event', return; } $scope.ticket.cancelled = !$scope.ticket.cancelled; - $scope.setPersonAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() { + $scope.setTicketAttribute($scope.ticket, 'cancelled', $scope.ticket.cancelled, function() { $scope.guiOptions.dangerousActionsEnabled = false; }); }; @@ -570,7 +581,7 @@ eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$state', 'Person $scope.personForm.$setPristine(false); }; - $scope.setPersonAttributeAtEvent = function(evnt, key, value) { + $scope.setTicketAttributeAtEvent = function(evnt, key, value) { var attrs = {_id: evnt._id, person_id: $state.params.id}; attrs[key] = value; Event.updatePerson(attrs, diff --git a/angular_app/js/services.js b/angular_app/js/services.js index 171f775..9aee1f2 100644 --- a/angular_app/js/services.js +++ b/angular_app/js/services.js @@ -18,7 +18,7 @@ function convert_dates(obj) { eventManServices.factory('Event', ['$resource', '$rootScope', function($resource, $rootScope) { - return $resource('events/:id', {id: '@_id', ticket_id: '@_id'}, { + return $resource('events/:id', {id: '@_id'}, { all: { method: 'GET', @@ -58,6 +58,16 @@ eventManServices.factory('Event', ['$resource', '$rootScope', update: { method: 'PUT', interceptor : {responseError: $rootScope.errorHandler} + }, + + group_persons: { + method: 'GET', + url: 'events/:id/group_persons', + isArray: true, + transformResponse: function(data, headers) { + data = angular.fromJson(data); + return data.persons || []; + } } }); }] diff --git a/eventman_server.py b/eventman_server.py index 66fe5a7..60b7e46 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -576,6 +576,15 @@ class EventsHandler(CollectionHandler): event['persons'] = [] return output + def filter_input_post(self, data): + # Auto-generate the group_id, if missing. + if 'group_id' not in data: + data['group_id'] = self.gen_id() + return data + + filter_input_post_all = filter_input_post + filter_input_put = filter_input_post + def filter_input_post_tickets(self, data): if not self.has_permission('event|update'): if 'attended' in data: @@ -584,6 +593,23 @@ class EventsHandler(CollectionHandler): filter_input_put_tickets = filter_input_post_tickets + def handle_get_group_persons(self, id_, resource_id=None): + persons = [] + this_query = {'_id': id_} + this_event = self.db.query('events', this_query)[0] + group_id = this_event.get('group_id') + if group_id is None: + return {'persons': persons} + this_persons = [p for p in (this_event.get('persons') or []) if not p.get('cancelled')] + this_emails = filter(None, [p.get('email') for p in this_persons]) + all_query = {'group_id': group_id} + events = self.db.query('events', all_query) + for event in events: + if str(event.get('_id')) == id_: + continue + persons += [p for p in (event.get('persons') or []) if p.get('email') and p.get('email') not in this_emails] + return {'persons': persons} + def _get_person_data(self, person_id_or_query, persons): """Filter a list of persons returning the first item with a given person_id or which set of keys specified in a dictionary match their respective values.""" From bee15ca088575e6a455820f89549c46e33ea3bc8 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Tue, 5 Jul 2016 21:30:12 +0200 Subject: [PATCH 08/34] partial implementation of an All Tickets page --- angular_app/index.html | 3 +- angular_app/js/app.js | 27 +++------------- angular_app/js/controllers.js | 3 ++ angular_app/js/services.js | 14 +++++++++ .../{persons-list.html => tickets-list.html} | 2 +- eventman_server.py | 31 ++++++++++++++++--- 6 files changed, 51 insertions(+), 29 deletions(-) rename angular_app/{persons-list.html => tickets-list.html} (98%) diff --git a/angular_app/index.html b/angular_app/index.html index 7c29a2f..32a6195 100644 --- a/angular_app/index.html +++ b/angular_app/index.html @@ -73,7 +73,8 @@