Added service filter engine

This commit is contained in:
Frédéric Vachon 2015-01-28 13:52:27 -05:00
parent 998d30e72f
commit c68d470f5d
2 changed files with 32 additions and 13 deletions

View File

@ -2,10 +2,28 @@
angular.module('adagios.live') angular.module('adagios.live')
.factory('GetServices', ['$http', function ($http, columns) { .constant('searchFields', { host_name: 'host_name__contains',
description: 'description__contains',
plugin_output: 'plugin_output__contains',
host_address: 'host_address__contains' })
return function (columns) { .factory('GetServices', ['$http', 'searchFields',
return $http.get('/rest/status/json/services/?fields=' + columns) function ($http, searchFields, columns, filters) {
return function (columns, filters) {
var filtersQuery = '';
function createQuery(filters) {
angular.forEach(filters, function (value, key) {
console.log(key);
console.log(searchFields[key]);
filtersQuery += '&' + searchFields[key] + '=';
filtersQuery += value;
});
}
createQuery(filters);
return $http.get('/rest/status/json/services/?fields=' + columns + filtersQuery)
.error(function (data, status, headers, config) { .error(function (data, status, headers, config) {
console.error('GetServices : GET Request failed'); console.error('GetServices : GET Request failed');
}); });

View File

@ -6,7 +6,10 @@ angular.module('adagios.table', ['ngRoute',
.controller('TableCtrl', ['$scope', 'GetServices', function ($scope, GetServices) { .controller('TableCtrl', ['$scope', 'GetServices', function ($scope, GetServices) {
var requestFields = []; var requestFields = [],
filters = { host_name: 'srv', plugin_output: 'SWAP'};
$scope.cells = ['host', 'service_check', 'duration', 'last_check'];
// The module directory name must be cell_ + key // The module directory name must be cell_ + key
$scope.cellToFieldsMap = { $scope.cellToFieldsMap = {
@ -16,15 +19,13 @@ angular.module('adagios.table', ['ngRoute',
last_check: ['last_check'] last_check: ['last_check']
}; };
$scope.cells = ['host', 'service_check', 'duration', 'last_check'];
angular.forEach($scope.cells, function (key, value) { angular.forEach($scope.cells, function (key, value) {
angular.forEach($scope.cellToFieldsMap[key], function (_value) { angular.forEach($scope.cellToFieldsMap[key], function (_value) {
requestFields.push(_value); requestFields.push(_value);
}); });
}); });
new GetServices(requestFields) new GetServices(requestFields,)
.success(function (data) { .success(function (data) {
$scope.entries = data; $scope.entries = data;
}); });