2015-10-12 15:08:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-21 14:34:38 +00:00
|
|
|
angular.module('am.directives', []);
|
|
|
|
|
|
|
|
angular.module('am.directives').directive('route',
|
|
|
|
function(RecursionHelper) {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
route: '='
|
|
|
|
},
|
|
|
|
templateUrl: '/app/partials/route.html',
|
|
|
|
compile: function(element) {
|
|
|
|
// Use the compile function from the RecursionHelper,
|
|
|
|
// And return the linking function(s) which it returns
|
|
|
|
return RecursionHelper.compile(element);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am.directives').directive('alert',
|
|
|
|
function() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
a: '='
|
|
|
|
},
|
|
|
|
templateUrl: '/app/partials/alert.html'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-12 15:08:07 +00:00
|
|
|
angular.module('am.services', ['ngResource']);
|
|
|
|
|
2015-10-21 14:34:38 +00:00
|
|
|
angular.module('am.services').factory('RecursionHelper',
|
|
|
|
function($compile) {
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* Manually compiles the element, fixing the recursion loop.
|
|
|
|
* @param element
|
|
|
|
* @param [link] A post-link function, or an object with function(s) registered via pre and post properties.
|
|
|
|
* @returns An object containing the linking functions.
|
|
|
|
*/
|
|
|
|
compile: function(element, link) {
|
|
|
|
// Normalize the link parameter
|
|
|
|
if (angular.isFunction(link)) {
|
|
|
|
link = {
|
|
|
|
post: link
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Break the recursion loop by removing the contents
|
|
|
|
var contents = element.contents().remove();
|
|
|
|
var compiledContents;
|
|
|
|
return {
|
|
|
|
pre: (link && link.pre) ? link.pre : null,
|
|
|
|
/**
|
|
|
|
* Compiles and re-adds the contents
|
|
|
|
*/
|
|
|
|
post: function(scope, element) {
|
|
|
|
// Compile the contents
|
|
|
|
if (!compiledContents) {
|
|
|
|
compiledContents = $compile(contents);
|
|
|
|
}
|
|
|
|
// Re-add the compiled contents to the element
|
|
|
|
compiledContents(scope, function(clone) {
|
|
|
|
element.append(clone);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Call the post-linking function, if any
|
|
|
|
if (link && link.post) {
|
|
|
|
link.post.apply(null, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-12 15:08:07 +00:00
|
|
|
angular.module('am.services').factory('Silence',
|
2015-10-21 14:34:38 +00:00
|
|
|
function($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'
|
|
|
|
},
|
|
|
|
'delete': {
|
|
|
|
method: 'DELETE',
|
|
|
|
url: '/api/v1/silence/:id'
|
|
|
|
}
|
2015-10-12 15:08:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
angular.module('am.services').factory('Alert',
|
2015-10-21 14:34:38 +00:00
|
|
|
function($resource) {
|
2015-10-15 14:24:27 +00:00
|
|
|
return $resource('', {}, {
|
2015-10-21 14:34:38 +00:00
|
|
|
'query': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/alerts'
|
|
|
|
}
|
2015-10-15 14:24:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-21 14:34:38 +00:00
|
|
|
angular.module('am.services').factory('Route',
|
|
|
|
function($resource) {
|
|
|
|
return $resource('', {}, {
|
|
|
|
'query': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/routes',
|
|
|
|
params: {
|
|
|
|
'pruneEmpty': 'true'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am.services').factory('Alert',
|
|
|
|
function($resource) {
|
|
|
|
return $resource('', {}, {
|
|
|
|
'query': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/alerts'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2015-10-12 15:08:07 +00:00
|
|
|
angular.module('am.controllers', []);
|
|
|
|
|
2015-10-15 10:01:19 +00:00
|
|
|
angular.module('am.controllers').controller('NavCtrl',
|
|
|
|
function($scope, $location) {
|
2015-10-21 14:34:38 +00:00
|
|
|
$scope.items = [{
|
|
|
|
name: 'Silences',
|
|
|
|
url: '/silences'
|
|
|
|
}, {
|
|
|
|
name: 'Alerts',
|
|
|
|
url: '/alerts'
|
|
|
|
}, {
|
|
|
|
name: 'Status',
|
|
|
|
url: '/status'
|
|
|
|
}];
|
2015-10-15 10:01:19 +00:00
|
|
|
|
|
|
|
$scope.selected = function(item) {
|
|
|
|
return item.url == $location.path()
|
2015-10-21 14:34:38 +00:00
|
|
|
}
|
2015-10-15 10:01:19 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
angular.module('am.controllers').controller('AlertsCtrl',
|
2015-10-21 14:34:38 +00:00
|
|
|
function($scope, Route) {
|
|
|
|
$scope.route = null;
|
2015-10-15 14:24:27 +00:00
|
|
|
$scope.order = "startsAt";
|
|
|
|
|
|
|
|
$scope.refresh = function() {
|
2015-10-21 14:34:38 +00:00
|
|
|
Route.query({},
|
2015-10-15 14:24:27 +00:00
|
|
|
function(data) {
|
2015-10-21 14:34:38 +00:00
|
|
|
console.log(data);
|
|
|
|
$scope.route = data.data;
|
|
|
|
console.log($scope.route)
|
2015-10-15 14:24:27 +00:00
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.refresh();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-21 14:34:38 +00:00
|
|
|
// angular.module('am.controllers').controller('AlertsCtrl',
|
|
|
|
// function($scope, Alert) {
|
|
|
|
// $scope.alerts = [];
|
|
|
|
// $scope.order = "startsAt";
|
|
|
|
|
|
|
|
// $scope.refresh = function() {
|
|
|
|
// Alert.query({},
|
|
|
|
// function(data) {
|
|
|
|
// $scope.alerts = data.data || [];
|
|
|
|
// console.log($scope.alerts)
|
|
|
|
// },
|
|
|
|
// function(data) {
|
|
|
|
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
|
|
|
|
// $scope.refresh();
|
|
|
|
// }
|
|
|
|
// );
|
|
|
|
|
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 || [];
|
2015-10-13 14:59:37 +00:00
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
|
2015-10-12 20:22:21 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.delete = function(sil) {
|
2015-10-21 14:34:38 +00:00
|
|
|
Silence.delete({
|
|
|
|
id: sil.id
|
|
|
|
})
|
2015-10-12 20:22:21 +00:00
|
|
|
$scope.refresh()
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.refresh();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am.controllers').controller('SilenceCreateCtrl',
|
|
|
|
function($scope, Silence) {
|
2015-10-12 15:08:07 +00:00
|
|
|
|
2015-10-12 20:22:21 +00:00
|
|
|
$scope.create = function() {
|
2015-10-13 14:59:37 +00:00
|
|
|
Silence.create($scope.silence,
|
|
|
|
function(data) {
|
|
|
|
$scope.refresh();
|
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
$scope.error = data.data;
|
|
|
|
}
|
|
|
|
);
|
2015-10-12 20:22:21 +00:00
|
|
|
}
|
2015-10-13 14:59:37 +00:00
|
|
|
|
|
|
|
$scope.error = null;
|
|
|
|
|
|
|
|
$scope.newMatcher = function() {
|
|
|
|
$scope.silence.matchers.push({});
|
|
|
|
}
|
|
|
|
$scope.delMatcher = function(i) {
|
|
|
|
$scope.silence.matchers.splice(i, 1);
|
|
|
|
}
|
2015-10-15 14:24:27 +00:00
|
|
|
$scope.reset = function() {
|
|
|
|
var now = new Date(),
|
2015-10-21 14:34:38 +00:00
|
|
|
end = new Date();
|
2015-10-15 14:24:27 +00:00
|
|
|
|
|
|
|
now.setMilliseconds(0);
|
|
|
|
end.setMilliseconds(0);
|
|
|
|
now.setSeconds(0);
|
|
|
|
end.setSeconds(0);
|
|
|
|
|
|
|
|
end.setHours(end.getHours() + 2)
|
|
|
|
|
|
|
|
$scope.silence = {
|
|
|
|
startsAt: now,
|
|
|
|
endsAt: end,
|
|
|
|
matchers: [{}],
|
|
|
|
comment: "",
|
|
|
|
createdBy: ""
|
|
|
|
}
|
|
|
|
}
|
2015-10-13 14:59:37 +00:00
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
$scope.reset();
|
2015-10-12 15:08:07 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am', [
|
|
|
|
'ngRoute',
|
|
|
|
|
|
|
|
'am.controllers',
|
2015-10-21 14:34:38 +00:00
|
|
|
'am.services',
|
|
|
|
'am.directives'
|
2015-10-12 15:08:07 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
angular.module('am').config(
|
|
|
|
function($routeProvider) {
|
|
|
|
$routeProvider.
|
2015-10-21 14:34:38 +00:00
|
|
|
when('/alerts', {
|
|
|
|
templateUrl: '/app/partials/alerts.html',
|
|
|
|
controller: 'AlertsCtrl'
|
|
|
|
}).
|
|
|
|
when('/silences', {
|
|
|
|
templateUrl: '/app/partials/silences.html',
|
|
|
|
controller: 'SilencesCtrl'
|
|
|
|
}).
|
|
|
|
otherwise({
|
|
|
|
redirectTo: '/silences'
|
|
|
|
});
|
2015-10-12 15:08:07 +00:00
|
|
|
}
|
2015-10-21 14:34:38 +00:00
|
|
|
);
|