2016-10-30 14:20:09 +00:00
|
|
|
import { debounce } from 'underscore';
|
|
|
|
|
|
|
|
function Events($http) {
|
|
|
|
this.events = [];
|
|
|
|
|
|
|
|
this.post = debounce(() => {
|
|
|
|
const events = this.events;
|
|
|
|
this.events = [];
|
|
|
|
|
|
|
|
$http.post('api/events', events);
|
|
|
|
}, 1000);
|
|
|
|
|
2016-11-23 15:58:00 +00:00
|
|
|
this.record = function record(action, objectType, objectId, additionalProperties) {
|
2016-10-30 14:20:09 +00:00
|
|
|
const event = {
|
|
|
|
action,
|
|
|
|
object_type: objectType,
|
|
|
|
object_id: objectId,
|
|
|
|
timestamp: Date.now() / 1000.0,
|
|
|
|
};
|
|
|
|
Object.assign(event, additionalProperties);
|
|
|
|
this.events.push(event);
|
|
|
|
|
|
|
|
this.post();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function (ngModule) {
|
|
|
|
ngModule.service('Events', Events);
|
|
|
|
}
|