2015-03-22 08:57:57 +01:00
|
|
|
'use strict';
|
|
|
|
|
2015-03-22 09:36:32 +01:00
|
|
|
/* Services that are used to interact with the backend. */
|
2015-03-21 13:21:15 +01:00
|
|
|
var eventManServices = angular.module('eventManServices', ['ngResource']);
|
|
|
|
|
2015-03-22 09:19:30 +01:00
|
|
|
|
2015-03-21 13:21:15 +01:00
|
|
|
eventManServices.factory('Event', ['$resource',
|
2015-03-21 15:45:40 +01:00
|
|
|
function($resource) {
|
2015-04-05 00:55:59 +02:00
|
|
|
return $resource('events/:id', {id: '@_id', person_id: '@person_id'}, {
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-03-21 15:45:40 +01:00
|
|
|
all: {
|
|
|
|
method: 'GET',
|
|
|
|
isArray: true,
|
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
return angular.fromJson(data).events;
|
|
|
|
}
|
|
|
|
},
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-03-23 23:06:44 +01:00
|
|
|
get: {method: 'GET',
|
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
data = angular.fromJson(data);
|
|
|
|
if (data && data['begin-datetime']) {
|
2015-04-06 21:08:52 +02:00
|
|
|
data['begin-date'] = data['begin-date'].getTime();
|
2015-03-23 23:06:44 +01:00
|
|
|
}
|
|
|
|
if (data && data['end-datetime']) {
|
2015-04-06 21:08:52 +02:00
|
|
|
data['end-date'] = data['end-date'].getTime();
|
2015-03-23 23:06:44 +01:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
},
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-04-05 00:55:59 +02:00
|
|
|
update: {method: 'PUT'},
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-04-18 19:56:00 +02:00
|
|
|
updatePerson: {
|
2015-04-05 00:55:59 +02:00
|
|
|
method: 'PUT',
|
2016-04-10 17:21:46 +02:00
|
|
|
isArray: false,
|
2015-04-05 00:55:59 +02:00
|
|
|
url: 'events/:id/persons/:person_id',
|
|
|
|
transformResponse: function(data, headers) {
|
2016-04-10 17:21:46 +02:00
|
|
|
return angular.fromJson(data);
|
2015-04-05 00:55:59 +02:00
|
|
|
}
|
2015-04-05 11:20:57 +02:00
|
|
|
},
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-04-18 19:58:15 +02:00
|
|
|
addPerson: {
|
2015-04-06 17:19:20 +02:00
|
|
|
method: 'POST',
|
2016-04-10 18:45:30 +02:00
|
|
|
isArray: false,
|
2015-04-06 17:19:20 +02:00
|
|
|
url: 'events/:id/persons/:person_id',
|
|
|
|
transformResponse: function(data, headers) {
|
2016-04-10 18:45:30 +02:00
|
|
|
return angular.fromJson(data);
|
2015-04-06 17:19:20 +02:00
|
|
|
}
|
|
|
|
},
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-04-18 19:58:15 +02:00
|
|
|
deletePerson: {
|
2015-04-05 11:20:57 +02:00
|
|
|
method: 'DELETE',
|
|
|
|
isArray: true,
|
|
|
|
url: 'events/:_id/persons/:person_id',
|
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
return angular.fromJson(data).event.persons;
|
|
|
|
}
|
2015-04-05 00:55:59 +02:00
|
|
|
}
|
2015-03-21 15:45:40 +01:00
|
|
|
});
|
|
|
|
}]
|
2015-03-21 13:21:15 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
eventManServices.factory('Person', ['$resource',
|
2015-03-21 15:45:40 +01:00
|
|
|
function($resource) {
|
2015-03-21 20:31:36 +01:00
|
|
|
return $resource('persons/:id', {id: '@_id'}, {
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-03-21 15:45:40 +01:00
|
|
|
all: {
|
|
|
|
method: 'GET',
|
2015-03-21 20:31:36 +01:00
|
|
|
isArray: true,
|
2015-03-21 15:45:40 +01:00
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
return angular.fromJson(data).persons;
|
|
|
|
}
|
2015-03-21 16:48:00 +01:00
|
|
|
},
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-04-04 14:15:52 +02:00
|
|
|
update: {method: 'PUT'},
|
2015-04-06 21:08:52 +02:00
|
|
|
|
2015-04-04 14:15:52 +02:00
|
|
|
getEvents: {
|
|
|
|
method: 'GET',
|
2015-04-06 17:19:20 +02:00
|
|
|
url: 'persons/:_id/events',
|
2015-04-04 14:15:52 +02:00
|
|
|
isArray: true,
|
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
return angular.fromJson(data).events;
|
|
|
|
}
|
|
|
|
}
|
2015-03-21 15:45:40 +01:00
|
|
|
});
|
|
|
|
}]
|
2015-03-21 13:21:15 +01:00
|
|
|
);
|
|
|
|
|
2015-04-18 17:33:42 +02:00
|
|
|
|
|
|
|
eventManServices.factory('Person', ['$resource',
|
|
|
|
function($resource) {
|
|
|
|
return $resource('persons/:id', {id: '@_id'}, {
|
|
|
|
|
|
|
|
all: {
|
|
|
|
method: 'GET',
|
|
|
|
isArray: true,
|
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
return angular.fromJson(data).persons;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
update: {method: 'PUT'},
|
|
|
|
|
|
|
|
getEvents: {
|
|
|
|
method: 'GET',
|
|
|
|
url: 'persons/:_id/events',
|
|
|
|
isArray: true,
|
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
return angular.fromJson(data).events;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
eventManServices.factory('Setting', ['$resource',
|
|
|
|
function($resource) {
|
|
|
|
return $resource('settings/', {}, {
|
|
|
|
|
|
|
|
query: {
|
|
|
|
method: 'GET',
|
|
|
|
isArray: true,
|
|
|
|
transformResponse: function(data, headers) {
|
|
|
|
return angular.fromJson(data).settings;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
update: {method: 'PUT'},
|
|
|
|
});
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
|
2015-04-26 01:10:58 +02:00
|
|
|
|
|
|
|
/* WebSocket collection used to update the list of persons of an Event. */
|
|
|
|
eventManApp.factory('EventUpdates', ['$websocket', '$location', '$log',
|
|
|
|
function($websocket, $location, $log) {
|
2015-04-26 10:27:33 +02:00
|
|
|
|
2015-04-26 12:42:47 +02:00
|
|
|
var dataStream = null;
|
2015-04-26 01:10:58 +02:00
|
|
|
|
|
|
|
var data = {};
|
|
|
|
|
|
|
|
var methods = {
|
|
|
|
data: data,
|
2015-04-26 12:42:47 +02:00
|
|
|
close: function() {
|
|
|
|
$log.debug('close WebSocket connection');
|
|
|
|
dataStream.close();
|
|
|
|
},
|
|
|
|
open: function() {
|
|
|
|
$log.debug('open WebSocket connection');
|
|
|
|
dataStream && dataStream.close();
|
|
|
|
var proto = $location.protocol() == 'https' ? 'wss' : 'ws';
|
|
|
|
dataStream = $websocket(proto + '://' + $location.host() + ':' + $location.port() +
|
|
|
|
'/ws/' + $location.path() + '/updates');
|
|
|
|
dataStream.onMessage(function(message) {
|
|
|
|
$log.debug('EventUpdates message received');
|
2016-04-10 17:21:46 +02:00
|
|
|
data.update = angular.fromJson(message.data);
|
|
|
|
});
|
2015-04-26 12:42:47 +02:00
|
|
|
}
|
2015-04-26 01:10:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return methods;
|
|
|
|
}]
|
|
|
|
);
|
|
|
|
|