Config file defines table headers name

This commit is contained in:
Frédéric Vachon 2015-02-16 13:21:55 -05:00
parent 3f8c39853f
commit a9c56401cf
6 changed files with 74 additions and 21 deletions

View File

@ -140,7 +140,7 @@
.data-table__service__summary,
.data-table__duration,
.data-table__lastcheck {
.data-table__last_check {
@extend %typo-more-info--little;
.color-scheme--dark & {
@ -162,4 +162,4 @@
}
}
.data-table__duration {width:percentage(166 / 1200);}
.data-table__duration {width:percentage(166 / 1200);}

View File

@ -1,16 +1,63 @@
{
"dashboardConfig": {
"cells": ["host", "service_check", "duration", "last_check"],
"cells": {
"text": [
"Host",
"Service check",
"Duration",
"Last check"
],
"name": [
"host",
"service_check",
"duration",
"last_check"
]
},
"apiName": "services",
"filters": { "isnot": { "host_state": ["0"]} }
"filters": {
"isnot": {
"host_state": [
"0"
]
}
}
},
"hostsConfig": {
"cells": ["hosts_host", "host_address", "duration", "last_check", "host_status"],
"cells": {
"text": [
"Host",
"Address",
"Duration",
"Last check",
"Host status"
],
"name": [
"hosts_host",
"host_address",
"duration",
"last_check",
"host_status"
]
},
"apiName": "hosts",
"filters": {}
},
"servicesConfig": {
"cells": ["host", "service_check", "duration", "last_check"],
"cells": {
"text": [
"Host",
"Service check",
"Duration",
"Last check"
],
"name": [
"host",
"service_check",
"duration",
"last_check"
]
},
"apiName": "services",
"filters": {}
},

View File

@ -2,20 +2,17 @@
<thead>
<tr>
<th class="data-table__checkbox"><input type="checkbox"></th>
<th class="state--current data-table__host">
<span class="data-table__cell__string">Host</span>
<th ng-repeat="i in cellIndexes" class="data-table__{{cellsName[i]}}">
{{cellsText[i]}}
<i class="ico-up-dir"></i>
</th>
<th class="data-table__service">Service check</th>
<th class="data-table__duration">Duration</th>
<th class="data-table__lastcheck">Last check</th>
</tr>
</thead>
<tbody class="" ng-repeat="entry in entries">
<tr>
<td><input type="checkbox"></td>
<td ng-repeat="cell in cells">
<td ng-repeat="cell in cellsName">
<adg-cell type="{{cell}}"></adg-cell>
</td>
</tr>

View File

@ -11,7 +11,7 @@ angular.module('adagios.table', ['adagios.live',
'adagios.table.cell_host_status'
])
.value('tableConfig', { cells: [],
.value('tableConfig', { cells: { 'text': [], 'name': [] },
apiName: '',
filters: {},
cellToFieldsMap: {} })
@ -21,9 +21,15 @@ angular.module('adagios.table', ['adagios.live',
var requestFields = [],
filters = JSON.parse(tableConfig.filters);
$scope.cells = tableConfig.cells;
$scope.cellsName = tableConfig.cells.name;
$scope.cellsText = tableConfig.cells.text;
$scope.cellIndexes = [];
angular.forEach($scope.cells, function (key, value) {
for (var i = 0; i < $scope.cellsName.length; i++) {
$scope.cellIndexes.push(i);
}
angular.forEach($scope.cellsName, function (key, value) {
angular.forEach(tableConfig.cellToFieldsMap[key], function (_value) {
requestFields.push(_value);
});
@ -41,8 +47,9 @@ angular.module('adagios.table', ['adagios.live',
link: function (scope, element, attrs) {
scope.generateTable = function () {
if (!!attrs.cells && !!attrs.apiName) {
tableConfig.cells = attrs.cells.split(',');
if (!!attrs.cellsText && !!attrs.cellsName && !!attrs.apiName) {
tableConfig.cells.text = attrs.cellsText.split(',');
tableConfig.cells.name = attrs.cellsName.split(',');
tableConfig.apiName = attrs.apiName;
if (!!attrs.filters) {
@ -51,7 +58,7 @@ angular.module('adagios.table', ['adagios.live',
return 'components/table/table.html';
}
console.log('<adg-table> "cells" and "api-name" attributes must be defined');
console.error('<adg-table> "cells" and "api-name" attributes must be defined');
};
},
template: '<div ng-include="generateTable()"></div>'

View File

@ -136,7 +136,7 @@
<p class="main__content__alert state--error">There are 5 host problems.</p>
</header>
<adg-table cells="{{dashboardCells}}" api-name="{{dashboardApiName}}" filters="{{dashboardFilters}}"></adg-table>
<adg-table cells-text="{{dashboardCellsText}}" cells-name="{{dashboardCellsName}}" api-name="{{dashboardApiName}}" filters="{{dashboardFilters}}"></adg-table>
</section>
</article>

View File

@ -15,13 +15,15 @@ angular.module('adagios.view.dashboard', ['ngRoute',
}])
.controller('DashboardCtrl', ['$scope', 'dashboardConfig', function ($scope, dashboardConfig) {
$scope.dashboardCells = dashboardConfig.cells.join();
$scope.dashboardCellsText = dashboardConfig.cellsText.join();
$scope.dashboardCellsName = dashboardConfig.cellsName.join();
$scope.dashboardApiName = dashboardConfig.apiName;
$scope.dashboardFilters = dashboardConfig.filters;
}])
.run(['readConfig', 'dashboardConfig', function (readConfig, dashboardConfig) {
dashboardConfig.cells = readConfig.data.dashboardConfig.cells;
dashboardConfig.cellsText = readConfig.data.dashboardConfig.cells.text;
dashboardConfig.cellsName = readConfig.data.dashboardConfig.cells.name;
dashboardConfig.apiName = readConfig.data.dashboardConfig.apiName;
dashboardConfig.filters = readConfig.data.dashboardConfig.filters;
}]);