Host view uses adg-host directive

This commit is contained in:
Frédéric Vachon 2015-03-26 16:17:08 -04:00
parent 5e974cb532
commit cef8d8c9fd
7 changed files with 66 additions and 47 deletions

View File

@ -109,10 +109,16 @@ module.exports = function (grunt) {
'<%= project.app %>/components/table/cell_hosts_host/cell_hosts_host.js', '<%= project.app %>/components/table/cell_hosts_host/cell_hosts_host.js',
'<%= project.app %>/components/table/cell_host_address/cell_host_address.js', '<%= project.app %>/components/table/cell_host_address/cell_host_address.js',
'<%= project.app %>/components/table/cell_host_status/cell_host_status.js', '<%= project.app %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.app %>/components/host/host.js',
'<%= project.app %>/components/host/host_cpu/host_cpu.js',
'<%= project.app %>/components/host/host_info/host_info.js',
'<%= project.app %>/components/host/host_load/host_load.js',
'<%= project.app %>/components/host/host_main/host_main.js',
'<%= project.app %>/components/host/host_services_list/host_services_list.js',
'<%= project.app %>/routing_view/routing_view.js', '<%= project.app %>/routing_view/routing_view.js',
'<%= project.app %>/templates/dashboard/dashboard.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 %>/templates/host/host.js', '<%= project.app %>/templates/host/host.js'
] ]
}], }],
options: { options: {
@ -144,10 +150,18 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_hosts_host/cell_hosts_host.js': '<%= project.app %>/components/table/cell_hosts_host/cell_hosts_host.js', '<%= project.build %>/components/table/cell_hosts_host/cell_hosts_host.js': '<%= project.app %>/components/table/cell_hosts_host/cell_hosts_host.js',
'<%= project.build %>/components/table/cell_host_address/cell_host_address.js': '<%= project.app %>/components/table/cell_host_address/cell_host_address.js', '<%= project.build %>/components/table/cell_host_address/cell_host_address.js': '<%= project.app %>/components/table/cell_host_address/cell_host_address.js',
'<%= project.build %>/components/table/cell_host_status/cell_host_status.js': '<%= project.app %>/components/table/cell_host_status/cell_host_status.js', '<%= project.build %>/components/table/cell_host_status/cell_host_status.js': '<%= project.app %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.build %>/components/host/host.js': '<%= project.app %>/components/host/host.js',
'<%= project.build %>/components/host/host_cpu/host_cpu.js': '<%= project.app %>/components/host/host_cpu/host_cpu.js',
'<%= project.build %>/components/host/host_info/host_info.js': '<%= project.app %>/components/host/host_info/host_info.js',
'<%= project.build %>/components/host/host_load/host_load.js': '<%= project.app %>/components/host/host_load/host_load.js',
'<%= project.build %>/components/host/host_main/host_main.js': '<%= project.app %>/components/host/host_main/host_main.js',
'<%= project.build %>/components/host/host_services_list/host_services_list.js': '<%= project.app %>/components/host/host_services_list/host_services_list.js',
'<%= project.build %>/routing_view/routing_view.js': '<%= project.app %>/routing_view/routing_view.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/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 %>/templates/host/host.js' : '<%= project.app %>/templates/host/host.js', '<%= project.build %>/templates/host/host.js' : '<%= project.app %>/templates/host/host.js'
}, },
{ {
'<%= project.build %>/js/adagios.min.js' : [ '<%= project.build %>/js/adagios.min.js' : [
@ -173,10 +187,16 @@ module.exports = function (grunt) {
'<%= project.build %>/components/table/cell_hosts_host/cell_hosts_host.js', '<%= project.build %>/components/table/cell_hosts_host/cell_hosts_host.js',
'<%= project.build %>/components/table/cell_host_address/cell_host_address.js', '<%= project.build %>/components/table/cell_host_address/cell_host_address.js',
'<%= project.build %>/components/table/cell_host_status/cell_host_status.js', '<%= project.build %>/components/table/cell_host_status/cell_host_status.js',
'<%= project.build %>/components/host/host.js',
'<%= project.build %>/components/host/host_cpu/host_cpu.js',
'<%= project.build %>/components/host/host_info/host_info.js',
'<%= project.build %>/components/host/host_load/host_load.js',
'<%= project.build %>/components/host/host_main/host_main.js',
'<%= project.build %>/components/host/host_services_list/host_services_list.js',
'<%= project.build %>/routing_view/routing_view.js', '<%= project.build %>/routing_view/routing_view.js',
'<%= project.build %>/templates/dashboard/dashboard.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 %>/templates/host/host.js', '<%= project.build %>/templates/host/host.js'
] ]
} }
], ],

View File

@ -15,9 +15,10 @@ angular.element(document).ready(function () {
angular.module('adagios', [ angular.module('adagios', [
'ngRoute', 'ngRoute',
'adagios.sidebar',
'adagios.topbar',
'adagios.config', 'adagios.config',
'adagios.topbar',
'adagios.sidebar',
'adagios.host',
'adagios.view', 'adagios.view',
'adagios.view.dashboard', 'adagios.view.dashboard',
'adagios.view.singleTable', 'adagios.view.singleTable',

View File

@ -0,0 +1,17 @@
<article ng-controller="HostCtrl">
<section class="main__content tabpanel">
<h2 class="main__overview__title">{{hostName}}</h2>
<table class="data-table">
<tbody >
<tr ng-repeat="(key, value) in data.live">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
<tr ng-repeat="(key, value) in data.config">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
</tbody>
</table>
</section>
</article>

View File

@ -1,25 +1,35 @@
'use strict'; 'use strict';
angular.module('adagios.host', []) angular.module('adagios.host', ['adagios.live'])
.controller('TableCtrl', ['$scope', function ($scope) { .value('hostConfig', {})
angular.noop();
.controller('HostCtrl', ['$scope', 'hostConfig', 'addObjectToScope', function ($scope, hostConfig, addObjectToScope) {
var objectType = 'host',
objectIdentifier = {};
objectIdentifier.host_name = hostConfig.hostName;
$scope.data = {};
addObjectToScope(objectType, objectIdentifier, $scope);
}]) }])
.directive('adgHost', ['$http', '$compile', .directive('adgHost', ['$http', '$compile', 'hostConfig',
function ($http, $compile) { function ($http, $compile, hostConfig) {
return { return {
restrict: 'E', restrict: 'E',
compile: function () { compile: function () {
return function (scope, element, attrs) { return function (scope, element, attrs) {
var template = 'components/host/host.html', var template = 'components/host/host.html';
conf;
if (!attrs.hostName || !attrs.modules) { if (!attrs.hostName) {
throw new Error('<adg-host> "host-name" and "modules" attributes must be defined'); throw new Error('<adg-host> "host-name" attribute must be defined');
} }
hostConfig.hostName = {};
hostConfig.hostName = attrs.hostName;
$http.get(template, { cache: true }) $http.get(template, { cache: true })
.success(function (data) { .success(function (data) {
var elem = $compile(data)(scope); var elem = $compile(data)(scope);

View File

@ -173,18 +173,11 @@ angular.module('adagios.live')
"service" : "services" "service" : "services"
}; };
if (objectType === "host") {
objectIdentifier.host_name = objectIdentifier.host_name;
} else if (objectType === "service") {
objectIdentifier.host_name = objectIdentifier.host_name;
objectIdentifier.description = objectIdentifier.description;
}
url += endpoints[objectType]; url += endpoints[objectType];
url += "/?"; url += "/?";
angular.forEach(objectIdentifier, function (value, key){ angular.forEach(objectIdentifier, function (value, key) {
if(!firstParameter){ if (!firstParameter) {
url += "&"; url += "&";
} }
url += key + "=" + value; url += key + "=" + value;

View File

@ -1,17 +1,3 @@
<article ng-controller="HostViewCtrl"> <article ng-controller="HostViewCtrl">
<section class="main__content tabpanel"> <adg-host host-name="{{hostName}}"></adg-host>
<h2 class="main__overview__title">{{hostName}}</h2>
<table class="data-table">
<tbody >
<tr ng-repeat="(key, value) in data.live">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
<tr ng-repeat="(key, value) in data.config">
<td>{{key}}</td>
<td>{{value}}</td>
</tr>
</tbody>
</table>
</section>
</article> </article>

View File

@ -1,20 +1,12 @@
'use strict'; 'use strict';
angular.module('adagios.view.host', ['adagios.live']) angular.module('adagios.view.host', ['adagios.live'])
.controller('HostViewCtrl', ['$http', '$scope', '$routeParams', 'getObjectId', 'getObjectById', 'addObjectToScope', .controller('HostViewCtrl', ['$http', '$scope', '$routeParams', 'getObjectId', 'getObjectById', 'addObjectToScope',
function ($http, $scope, $routeParams, getObjectId, getObjectById, addObjectToScope) { function ($http, $scope, $routeParams, getObjectId, getObjectById, addObjectToScope) {
var objectIdentifier = {},
objectType = 'host';
if (!!$routeParams.host_name) { if (!!$routeParams.host_name) {
objectIdentifier.host_name = $routeParams.host_name; $scope.hostName = $routeParams.host_name;
} else { } else {
throw new Error("ERROR :'host_name' GET parameter must be set"); throw new Error("ERROR :'host_name' GET parameter must be set");
} }
$scope.data = {};
addObjectToScope(objectType, objectIdentifier, $scope);
}]); }]);