diff --git a/app/components/config/config.json b/app/components/config/config.json index 59b43ef..1528802 100644 --- a/app/components/config/config.json +++ b/app/components/config/config.json @@ -28,7 +28,7 @@ "Host status" ], "name": [ - "hosts_host", + "host", "host_address", "duration", "last_check", @@ -93,7 +93,7 @@ "Host status" ], "name": [ - "hosts_host", + "host", "host_address", "duration", "last_check", @@ -162,7 +162,7 @@ "Host status" ], "name": [ - "hosts_host", + "host", "host_address", "duration", "last_check", diff --git a/app/components/live/get_objects.js b/app/components/live/get_objects.js index 37e125a..98f452d 100644 --- a/app/components/live/get_objects.js +++ b/app/components/live/get_objects.js @@ -12,9 +12,9 @@ angular.module('adagios.live') regex: '__regex' }) - .service('getObjects', ['$http', 'filterSuffixes', - function ($http, filterSuffixes) { - return function (columns, filters, apiName, additionnalFields) { + .service('getObjects', ['$http', 'filterSuffixes', 'hostMiddleware', + function ($http, filterSuffixes, hostMiddleware) { + return function (fields, filters, apiName, additionnalFields) { var filtersQuery = '', additionnalQuery = ''; @@ -46,17 +46,35 @@ angular.module('adagios.live') filtersQuery = createFiltersQuery(filters); additionnalQuery = createAdditionnalQuery(additionnalFields); - return $http.get('/rest/status/json/' + apiName + '/?fields=' + columns + filtersQuery + additionnalQuery) - .error(function () { - throw new Error('getObjects : GET Request failed'); - }); + function appendTransform(defaults, transform) { + // We can't guarantee that the default transformation is an array + defaults = angular.isArray(defaults) ? defaults : [defaults]; + + return defaults.concat(transform); + }; + + + function transformations(data) { + if (apiName === 'hosts') { + hostMiddleware(data); + } + return data; + } + + return $http({ + url: '/adagios/rest/status/json/' + apiName + '/?fields=' + fields + filtersQuery + additionnalQuery, + method: 'GET', + transformResponse: appendTransform($http.defaults.transformResponse, transformations) + }).error(function () { + throw new Error('getObjects : GET Request failed'); + }); }; }]) .service('getService', ['$http', function ($http) { return function (hostName, description) { - return $http.get('/rest/status/json/services/?host_name=' + hostName + '&description=' + description) + return $http.get('/adagios/rest/status/json/services/?host_name=' + hostName + '&description=' + description) .error(function () { throw new Error('getService : GET Request failed'); }); @@ -174,7 +192,7 @@ angular.module('adagios.live') req = { method: 'POST', - url: '/rest/pynag/json/get_objects', + url: '/adagios/rest/pynag/json/get_objects', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, @@ -197,7 +215,7 @@ angular.module('adagios.live') req = { method: 'POST', - url: '/rest/pynag/json/get_object', + url: '/adagios/rest/pynag/json/get_object', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, @@ -216,7 +234,7 @@ angular.module('adagios.live') .service('addObjectToScope', ['$http', 'getObjectId', 'getObjectById', function ($http, getObjectId, getObjectById) { return function (objectType, objectIdentifier, scope) { var objectData = {}, - url = "/rest/status/json/", + url = "/adagios/rest/status/json/", firstParameter = true, endpoints = { "host" : "hosts", @@ -250,4 +268,24 @@ angular.module('adagios.live') }); }); }; - }]); + }]) + + // Modify response object to conform to web ui + .service('hostMiddleware', function() { + return function(data) { + var i = 0, + conversions = { + 'name': 'host_name', + 'state': 'host_state' + }; + + for (i = 0; i < data.length; i += 1) { + angular.forEach(data[i], function (value, field) { + if (field in conversions) { + data[i][conversions[field]] = value; + delete data[i][field]; + } + }); + } + }; + }); diff --git a/app/components/table/cell_hosts_host/cell_hosts_host.html b/app/components/table/cell_hosts_host/cell_hosts_host.html deleted file mode 100644 index 253a866..0000000 --- a/app/components/table/cell_hosts_host/cell_hosts_host.html +++ /dev/null @@ -1,3 +0,0 @@ - - {{entry.name}} - diff --git a/app/components/table/cell_hosts_host/cell_hosts_host.js b/app/components/table/cell_hosts_host/cell_hosts_host.js deleted file mode 100644 index cbb1ef5..0000000 --- a/app/components/table/cell_hosts_host/cell_hosts_host.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -angular.module('adagios.table.cell_hosts_host', ['adagios.table']) - - .controller('CellHostsHostCtrl', ['$scope', function ($scope) { - if ($scope.entry.state === 0) { - $scope.state = 'state--ok'; - } else if ($scope.entry.state === 1) { - $scope.state = 'state--error'; - } else if ($scope.entry.state === "") { - $scope.state = ''; - } else { - $scope.state = 'state--unreachable'; - } - }]) - - .run(['tableGlobalConfig', function (tableGlobalConfig) { - tableGlobalConfig.cellToFieldsMap.hosts_host = ['name', 'state']; - }]);