Drupal: Added General info to Drupal detailed view

Change-Id: I636ffe3f53768ff5bf8a0977b9127d3bb83faee6
This commit is contained in:
Frédéric Vachon 2015-06-10 12:45:36 -04:00 committed by Alexandre Viau
parent d8eb2c91b5
commit 61c391e3ef
5 changed files with 106 additions and 40 deletions

View File

@ -14,6 +14,7 @@ angular.module('bansho', [
'bansho.service',
'bansho.drupal',
'bansho.drupal.tile',
'bansho.drupal.info',
'bansho.view',
'bansho.view.dashboard',
'bansho.view.singleTable',
@ -29,11 +30,12 @@ angular.module('bansho', [
}])
// Reinitialise objects on url change
.run(['$rootScope', 'promisesManager', 'reinitTables', 'reinitDrupalTiles',
function ($rootScope, promisesManager, reinitTables, reinitDrupalTiles) {
.run(['$rootScope', 'promisesManager', 'reinitTables', 'reinitDrupalTiles', 'reinitDrupalInfo',
function ($rootScope, promisesManager, reinitTables, reinitDrupalTiles, reinitDrupalInfo) {
$rootScope.$on('$locationChangeStart', function () {
reinitTables();
reinitDrupalTiles();
reinitDrupalInfo();
promisesManager.clearAllPromises();
});
}]);

View File

@ -1,43 +1,9 @@
<article ng-controller="DrupalCtrl">
<h1 class="drupal__dashboard__title">{{drupal_id}}</h1>
<div class="tile__main">
<h1>General informations</h1>
<table class="data-table">
<tbody>
<tr>
<td>Core version :</td>
<td>7.37</td>
</tr>
<tr>
<td>Core up-to-date :</td>
<td>YES</td>
</tr>
<tr class="btn-success">
<td>Vulnerable core :</td>
<td>NO</td>
</tr>
<tr>
<td>JQuery version:</td>
<td>2.1.4</td>
</tr>
<tr>
<td>Database :</td>
<td>MySQL</td>
</tr>
<tr>
<td>Database version :</td>
<td>5.6.23</td>
</tr>
<tr>
<td>Database state :</td> <td>OK</td>
</tr>
<tr>
<td>Cache activated :</td>
<td>YES</td>
</tr>
</tbody>
</table>
</div>
<bansho-drupal-info host-name="{{hostName}}"
plugin="drupal_status"
title="General informations"></bansho-drupal-info>
<bansho-drupal-tile host-name="{{hostName}}"
plugin="drupal_cache"

View File

@ -0,0 +1,11 @@
<div class="tile__main" ng-controller='DrupalInfoCtrl'>
<h1>{{title}}</h1>
<table class="data-table">
<tbody>
<tr ng-repeat="datum in data" ng-class="datum[2]">
<td style="text-align:center;">{{datum[0]}}</td>
<td style="text-align:center;">{{datum[1]}}</td>
</tr>
</tbody>
</table>
</div>

View File

@ -0,0 +1,86 @@
'use strict';
angular.module('bansho.drupal.info', [])
.value('DrupalInfoConfig', {'nextIndex': 0, 'conf': []})
.controller('DrupalInfoCtrl', ['$scope', 'surveilStatus', 'DrupalInfoConfig',
function ($scope, surveilStatus, DrupalInfoConfig) {
var fields = [],
apiName = 'services',
filters = {},
currentIndex = DrupalInfoConfig.nextIndex,
conf = DrupalInfoConfig.conf[currentIndex];
$scope.plugin = conf.plugin;
$scope.title = conf.title;
$scope.hostName = conf.hostName;
filters = {'is': {'host_name': [$scope.hostName],
'service_description': [$scope.plugin]}};
surveilStatus.getObjects(fields, filters, apiName)
.success(function (response) {
var finalScore = response[0].plugin_output.split(' ')[1],
out = [],
data = response[0].long_output.split('\n').slice(0, -1);
// Split data into (key, value, score_class) tuples
for (var i = 0; i < data.length; i++) {
var tuple = data[i].split(';'),
score = parseInt(tuple[2], 10);
if (score === 1) {
tuple[2] = 'btn-warning';
} else if (score === 0) {
tuple[2] = 'btn-danger';
} else {
tuple[2] = '';
}
out.push(tuple);
}
$scope.data = out;
});
DrupalInfoConfig.nextIndex++;
}])
.directive('banshoDrupalInfo', ['$http', '$compile', 'DrupalInfoConfig',
function ($http, $compile, DrupalInfoConfig) {
return {
restrict: 'E',
compile: function () {
return function (scope, element, attrs) {
var template = 'components/drupal/drupal_info/drupal_info.html',
currentIndex = DrupalInfoConfig.nextIndex,
conf = {};
if (!attrs.hostName || !attrs.plugin) {
throw new Error('<bansho-drupal-tile> "host-name" and "plugin"' +
'attributes must be defined');
}
conf.hostName = attrs.hostName;
conf.plugin = attrs.plugin;
conf.title = attrs.title;
DrupalInfoConfig.conf.push(conf);
$http.get(template, { cache: true })
.success(function (data) {
var elem = $compile(data)(scope);
element.append(elem);
});
};
}
};
}])
.service('reinitDrupalInfo', ['DrupalInfoConfig',
function (DrupalInfoConfig) {
return function () {
// Reinitialise tile index
DrupalInfoConfig.nextIndex = 0;
};
}]);

View File

@ -88,6 +88,7 @@
<script src="components/service/service_metrics/service_metrics.js"></script>
<script src="components/drupal/drupal.js"></script>
<script src="components/drupal/drupal_tile/drupal_tile.js"></script>
<script src="components/drupal/drupal_info/drupal_info.js"></script>
<script src="routing_view/routing_view.js"></script>
<script src="templates/dashboard/dashboard.js"></script>
<script src="templates/single_table/single_table.js"></script>