From c68d470f5dec32e114407d46d34e66d2c280cd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Vachon?= Date: Wed, 28 Jan 2015 13:52:27 -0500 Subject: [PATCH] Added service filter engine --- app/components/live/get_services.js | 34 ++++++++++++++++++++++------- app/table/table.js | 11 +++++----- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/components/live/get_services.js b/app/components/live/get_services.js index 5167005..16e90a4 100644 --- a/app/components/live/get_services.js +++ b/app/components/live/get_services.js @@ -2,12 +2,30 @@ 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) { - return $http.get('/rest/status/json/services/?fields=' + columns) - .error(function (data, status, headers, config) { - console.error('GetServices : GET Request failed'); - }); - }; - }]); + .factory('GetServices', ['$http', 'searchFields', + 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) { + console.error('GetServices : GET Request failed'); + }); + }; + }]); diff --git a/app/table/table.js b/app/table/table.js index 16ca859..fe52aaa 100644 --- a/app/table/table.js +++ b/app/table/table.js @@ -6,25 +6,26 @@ angular.module('adagios.table', ['ngRoute', .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 $scope.cellToFieldsMap = { host: [ 'host_state', 'host_name' ], - service_check: ['state', 'description', 'plugin_output' ], + service_check: ['state', 'description', 'plugin_output'], duration: ['last_state_change'], last_check: ['last_check'] }; - $scope.cells = ['host', 'service_check', 'duration', 'last_check']; - angular.forEach($scope.cells, function (key, value) { angular.forEach($scope.cellToFieldsMap[key], function (_value) { requestFields.push(_value); }); }); - new GetServices(requestFields) + new GetServices(requestFields,) .success(function (data) { $scope.entries = data; });