diff --git a/ui/app/js/app.js b/ui/app/js/app.js index 0b293248..69bfb4ad 100644 --- a/ui/app/js/app.js +++ b/ui/app/js/app.js @@ -4,10 +4,11 @@ angular.module('am.services', ['ngResource']); angular.module('am.services').factory('Silence', function($resource){ - return $resource('', {}, { + return $resource('', {id: '@id'}, { + 'query': {method: 'GET', url: '/api/v1/silences'}, + 'create': {method: 'POST', url: '/api/v1/silences'}, 'get': {method: 'GET', url: '/api/v1/silence/:id'}, 'save': {method: 'POST', url: '/api/v1/silence/:id'}, - 'query': {method: 'GET', url: '/api/v1/silences'}, 'delete': {method: 'DELETE', url: '/api/v1/silence/:id'} }); } @@ -18,13 +19,48 @@ angular.module('am.controllers', []); angular.module('am.controllers').controller('SilencesCtrl', function($scope, Silence) { $scope.silences = []; + $scope.order = "startsAt"; - Silence.query( - {}, - function(data) { - $scope.silences = data.data || []; - } - ); + $scope.refresh = function() { + Silence.query({}, + function(data) { + console.log(data); + $scope.silences = data.data || []; + } + ); + } + + $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: [] + } + + $scope.create = function() { + Silence.create($scope.silence); + $scope.$parent.refresh(); + } } ); diff --git a/ui/app/partials/silences.html b/ui/app/partials/silences.html index 77424afa..bbe25983 100644 --- a/ui/app/partials/silences.html +++ b/ui/app/partials/silences.html @@ -1,7 +1,32 @@ -