alertmanager/ui/app/js/app.js

118 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-10-12 15:08:07 +00:00
'use strict';
angular.module('am.services', ['ngResource']);
angular.module('am.services').factory('Silence',
function($resource){
2015-10-12 20:22:21 +00:00
return $resource('', {id: '@id'}, {
'query': {method: 'GET', url: '/api/v1/silences'},
'create': {method: 'POST', url: '/api/v1/silences'},
2015-10-12 15:08:07 +00:00
'get': {method: 'GET', url: '/api/v1/silence/:id'},
'save': {method: 'POST', url: '/api/v1/silence/:id'},
'delete': {method: 'DELETE', url: '/api/v1/silence/:id'}
});
}
);
angular.module('am.controllers', []);
2015-10-15 10:01:19 +00:00
angular.module('am.controllers').controller('NavCtrl',
function($scope, $location) {
$scope.items = [
{name: 'Silences', url:'/silences'},
{name: 'Alerts', url:'/alerts'},
{name: 'Status', url:'/status'}
];
$scope.selected = function(item) {
return item.url == $location.path()
}
}
);
2015-10-12 15:08:07 +00:00
angular.module('am.controllers').controller('SilencesCtrl',
function($scope, Silence) {
$scope.silences = [];
2015-10-12 20:22:21 +00:00
$scope.order = "startsAt";
$scope.refresh = function() {
Silence.query({},
function(data) {
$scope.silences = data.data || [];
},
function(data) {
2015-10-12 20:22:21 +00:00
}
);
}
$scope.delete = function(sil) {
Silence.delete({id: sil.id})
$scope.refresh()
}
$scope.refresh();
}
);
angular.module('am.controllers').controller('SilenceCreateCtrl',
function($scope, Silence) {
var now = new Date(),
end = new Date();
now.setMilliseconds(0);
end.setMilliseconds(0);
now.setSeconds(0);
end.setSeconds(0);
end.setHours(end.getHours() + 2)
$scope.silence = {
startsAt: now,
endsAt: end,
matchers: [{}]
2015-10-12 20:22:21 +00:00
}
2015-10-12 15:08:07 +00:00
2015-10-12 20:22:21 +00:00
$scope.create = function() {
Silence.create($scope.silence,
function(data) {
$scope.refresh();
},
function(data) {
$scope.error = data.data;
}
);
2015-10-12 20:22:21 +00:00
}
$scope.error = null;
$scope.newMatcher = function() {
$scope.silence.matchers.push({});
}
$scope.delMatcher = function(i) {
$scope.silence.matchers.splice(i, 1);
}
2015-10-12 15:08:07 +00:00
}
);
angular.module('am', [
'ngRoute',
'am.controllers',
'am.services'
]);
angular.module('am').config(
function($routeProvider) {
$routeProvider.
when('/silences', {
templateUrl: '/app/partials/silences.html',
controller: 'SilencesCtrl'
}).
otherwise({
redirectTo: '/silences'
});
}
2015-10-15 10:01:19 +00:00
);