host_view generalized to work with all objects. Only services are implemeted but it is only a matter of adding a clause in object_view.js:getIdentifier and cleaning up

This commit is contained in:
Philippe Pepos Petitclerc 2015-03-23 18:33:05 -04:00 committed by Frédéric Vachon
parent 68124e223f
commit 4fff4f937a
12 changed files with 97 additions and 62 deletions

View File

@ -111,7 +111,8 @@ module.exports = function (grunt) {
'<%= project.app %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.app %>/routing_view/routing_view.js',
'<%= project.app %>/templates/dashboard/dashboard.js',
'<%= project.app %>/templates/single_table/single_table.js'
'<%= project.app %>/templates/single_table/single_table.js',
'<%= project.app %>/object_view/object_view.js'
]
}],
options: {
@ -145,7 +146,8 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_host_status/cell_host_status.js': '<%= project.app %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.build %>/routing_view/routing_view.js': '<%= project.app %>/routing_view/routing_view.js',
'<%= project.build %>/templates/dashboard/dashboard.js': '<%= project.app %>/templates/dashboard/dashboard.js',
'<%= project.build %>/templates/single_table/single_table.js' : '<%= project.app %>/templates/single_table/single_table.js'
'<%= project.build %>/templates/single_table/single_table.js' : '<%= project.app %>/templates/single_table/single_table.js',
'<%= project.build %>/object_view/object_view.js' : '<%= project.app %>/object_view/object_view.js'
},
{
'<%= project.build %>/js/adagios.min.js' : [
@ -173,7 +175,8 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.build %>/routing_view/routing_view.js',
'<%= project.build %>/templates/dashboard/dashboard.js',
'<%= project.build %>/templates/single_table/single_table.js'
'<%= project.build %>/templates/single_table/single_table.js',
'<%= project.build %>/object_view/object_view.js'
]
}
],

View File

@ -20,6 +20,7 @@ angular.module('adagios', [
'adagios.config',
'adagios.view.dashboard',
'adagios.view.singleTable',
'adagios.view.object_view',
'adagios.view'
])

View File

@ -110,11 +110,17 @@ angular.module('adagios.live')
}])
.factory('getObjectId', ['$http', function ($http) {
return function (objectType, objectName) {
return function (objectType, objectIdentifier) {
var postString, req;
postString = "with_fields=id&object_type=" + objectType + "&host_name=" + objectName;
postString = "with_fields=id&object_type=" + objectType;
angular.forEach(objectIdentifier, function (value, key) {
if (key === "description") {
key = "service_description";
}
postString += "&" + key + "=" + value;
});
req = {
method: 'POST',
@ -132,7 +138,7 @@ angular.module('adagios.live')
};
}])
.factory('getHostById', ['$http', function ($http) {
.factory('getObjectById', ['$http', function ($http) {
return function (objectId) {
var postString, req;

View File

@ -1,3 +1,3 @@
<td class="data-table__host {{entry[cell_name + '_additionnalClass']}} {{state}}" ng-controller="CellHostCtrl">
<a class="data-table__data" href="#/host_view?host={{entry.host_name}}">{{entry.host_name}}</a>
<a class="data-table__data" href="#/object_view?object_type=host&host_name={{entry.host_name}}">{{entry.host_name}}</a>
</td>

View File

@ -1,3 +1,3 @@
<td class="data-table__hosts_host {{state}}" ng-controller="CellHostsHostCtrl">
<a class="data-table__data" href="#/host_view?host={{entry.name}}">{{entry.name}}</a>
<a class="data-table__data" href="#/object_view?object_type=host&host_name={{entry.name}}">{{entry.name}}</a>
</td>

View File

@ -1,6 +1,8 @@
<td class="data-table__service {{state}}" ng-controller="CellServiceCheckCtrl">
<dl class="data-table__data">
<dt class="data-table__service__name">{{entry.description}}</dt>
<dt class="data-table__service__name">
<a href="#/object_view?object_type=service&host_name={{entry.host_name}}&description={{entry.description}}">{{entry.description}}</a>
</dt>
<dd class="data-table__service__summary">{{entry.plugin_output}}</dd>
</dl>
</td>

View File

@ -5,7 +5,7 @@ angular.module('adagios.table.cell_service_check', ['adagios.table'])
.controller('CellServiceCheckCtrl', ['$scope', function ($scope) {
if ($scope.entry.state === 0) {
$scope.state = 'state--ok';
} else if ($scope.entry === 1) {
} else if ($scope.entry.state === 1) {
$scope.state = 'state--warning';
} else {
$scope.state = 'state--error';

View File

@ -15,5 +15,4 @@
<td adg-cell cell-name="{{cell}}" ng-repeat="cell in cellsName"></td>
</tr>
</tbody>
</table>

View File

@ -187,6 +187,7 @@ angular.module('adagios.table', ['adagios.live',
input[i - 1].has_child = 1;
input[i - 1].child_class = class_name[0];
entry.child_class = class_name[1];
parent_found = true;
} else {
entry.is_child = 1;

View File

@ -1,51 +0,0 @@
'use strict';
angular.module('adagios.view.host_view', ['ngRoute',
'adagios.live'
])
.value('hostViewConfig', {})
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/host_view', {
templateUrl: 'host_view/host_view.html',
controller: 'HostViewCtrl'
});
}])
.controller('HostViewCtrl', ['$http', '$scope', '$routeParams', 'getObjectId', 'getHostById',
function ($http, $scope, $routeParams, getObjectId, getHostById) {
$scope.data = {};
if (!!$routeParams.host) {
$scope.hostName = $routeParams.host;
} else {
throw new Error("ERROR : 'view' GET parameter must be the host");
}
var getData = function (host) {
var objectData = {}, objectId, objectType;
$http.get('/rest/status/json/hosts/?host_name=' + host)
.success(function (data) {
$scope.data = objectData.live = data[0];
});
objectType = 'host';
getObjectId(objectType, host)
.success(function (data) {
objectId = data[0].id;
$scope.data.id = objectId;
getHostById(objectId)
.success(function (data) {
$scope.data.config = data;
});
});
};
getData($scope.hostName);
}]);

View File

@ -0,0 +1,74 @@
'use strict';
angular.module('adagios.view.object_view', ['ngRoute',
'adagios.live'
])
.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/object_view', {
templateUrl: 'object_view/object_view.html',
controller: 'ObjectViewCtrl'
});
}])
.controller('ObjectViewCtrl', ['$http', '$scope', '$routeParams', 'getObjectId', 'getObjectById',
function ($http, $scope, $routeParams, getObjectId, getObjectById) {
var objectIdentifier = {},
objectType = $routeParams.object_type,
endpoints = {
"host" : "hosts",
"service" : "services"
};
var getIdentifier = function () {
if (objectType === "host") {
objectIdentifier.host_name = $routeParams.host_name;
} else if (objectType === "service") {
objectIdentifier.host_name = $routeParams.host_name;
objectIdentifier.description = $routeParams.description;
} else {
throw new Error("ERROR : 'view' GET parameter must be the host");
}
};
$scope.data = {};
var getData = function () {
var objectData = {},
url = "/rest/status/json/",
firstParameter = true;
url += endpoints[objectType];
url += "/?";
angular.forEach(objectIdentifier, function (value, key){
if(!firstParameter){
url += "&";
}
url += key + "=" + objectIdentifier[key];
firstParameter = false;
});
$http.get(url)
.success(function (data) {
objectData.live = data[0];
getObjectId(objectType, objectIdentifier)
.success(function (data) {
var objectId = data[0].id;
$scope.data.id = objectId;
getObjectById(objectId)
.success(function (data) {
objectData.config = data;
$scope.data = objectData;
});
});
});
};
getIdentifier();
getData(objectIdentifier);
}]);