redash/client/app/services/events.js

30 lines
626 B
JavaScript
Raw Normal View History

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);
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);
}