mirror of
https://github.com/datahub-project/datahub.git
synced 2025-07-26 19:10:15 +00:00
34 lines
893 B
JavaScript
34 lines
893 B
JavaScript
![]() |
'use strict'
|
||
|
|
||
|
App.MetricWatchComponent = Ember.Component.extend({
|
||
|
actions: {
|
||
|
watch: function(metric) {
|
||
|
var url = '/api/v1/metrics/' + metric.id + '/watch'
|
||
|
var method = !metric.watchId ? 'POST' : 'DELETE'
|
||
|
if(method.toLowerCase() === 'delete')
|
||
|
url += '/' + metric.watchId
|
||
|
var token = $("#csrfToken").val().replace('/', '')
|
||
|
var _this = this
|
||
|
$.ajax({
|
||
|
url: url,
|
||
|
method: method,
|
||
|
headers: {
|
||
|
'Csrf-Token': token
|
||
|
},
|
||
|
dataType: 'json',
|
||
|
data: {
|
||
|
csrfToken: token,
|
||
|
item_type: 'metric',
|
||
|
notification_type: 'weekly'
|
||
|
}
|
||
|
}).done(function(data, txt, xhr){
|
||
|
_this.set('metric.watchId', data.watchId)
|
||
|
_this.sendAction('getMetrics')
|
||
|
}).fail(function(xhr, txt, err){
|
||
|
console.log('Error: Could not watch metric.')
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
|