Add "filters" parameter to table

This commit is contained in:
Frédéric Vachon 2015-02-06 14:18:30 -05:00
parent 0244f80edd
commit 1f494b2c08
7 changed files with 20 additions and 5 deletions

View File

@ -1,10 +1,12 @@
{
"dashboardConfig": {
"cells": ["host", "service_check", "duration", "last_check"],
"apiName": "services"
"apiName": "services",
"filters": { "isnot": { "host_state": ["0"]} }
},
"hostsConfig": {
"cells": ["hosts_host", "host_address", "duration", "last_check", "host_status"],
"apiName": "hosts"
"apiName": "hosts",
"filters": {}
}
}

View File

@ -8,6 +8,7 @@ angular.module('adagios.live')
endswith: '__endswith',
exists: '__exists',
in: '__in',
isnot: '__isnot',
regex: '__regex'
})

View File

@ -12,14 +12,16 @@ angular.module('adagios.table', ['adagios.live',
.value('tableConfig', { cells: [],
apiName: '',
filters: {},
cellToFieldsMap: {} })
.controller('TableCtrl', ['$scope', 'getServices', 'readConfig', 'tableConfig', function ($scope, getServices, readConfig, tableConfig) {
var requestFields = [],
filters = {};
filters = JSON.parse(tableConfig.filters);
$scope.cells = tableConfig.cells;
angular.forEach($scope.cells, function (key, value) {
angular.forEach(tableConfig.cellToFieldsMap[key], function (_value) {
requestFields.push(_value);
@ -37,9 +39,15 @@ angular.module('adagios.table', ['adagios.live',
restrict: 'E',
link: function (scope, element, attrs) {
scope.generateTable = function () {
if (!!attrs.cells && !!attrs.apiName) {
tableConfig.cells = attrs.cells.split(',');
tableConfig.apiName = attrs.apiName;
if (!!attrs.filters) {
tableConfig.filters = attrs.filters;
}
return 'components/table/table.html';
}
console.log('<adg-table> "cells" and "api-name" attributes must be defined');

View File

@ -18,6 +18,6 @@
</div>
<adg-table cells="{{dashboardCells}}" api-name="{{dashboardApiName}}"></adg-table>
<adg-table cells="{{dashboardCells}}" api-name="{{dashboardApiName}}" filters="{{dashboardFilters}}"></adg-table>
</div>

View File

@ -19,9 +19,11 @@ angular.module('adagios.tactical', ['ngRoute',
.controller('DashboardCtrl', ['$scope', 'dashboardConfig', function ($scope, dashboardConfig) {
$scope.dashboardCells = dashboardConfig.cells.join();
$scope.dashboardApiName = dashboardConfig.apiName;
$scope.dashboardFilters = dashboardConfig.filters;
}])
.run(['readConfig', 'dashboardConfig', function (readConfig, dashboardConfig) {
dashboardConfig.cells = readConfig.dashboardConfig.cells;
dashboardConfig.apiName = readConfig.dashboardConfig.apiName;
dashboardConfig.filters = readConfig.dashboardConfig.filters;
}]);

View File

@ -2,6 +2,6 @@
<h2>Hosts</h2>
<adg-table cells="{{hostsCells}}" api-name="{{hostsApiName}}"></adg-table>
<adg-table cells="{{hostsCells}}" api-name="{{hostsApiName}}" filters="{{hostsFilters}}"></adg-table>
</div>

View File

@ -16,9 +16,11 @@ angular.module('adagios.view.hosts', ['ngRoute',
.controller('HostsCtrl', ['$scope', 'hostsConfig', function ($scope, hostsConfig) {
$scope.hostsCells = hostsConfig.cells.join();
$scope.hostsApiName = hostsConfig.apiName;
$scope.hostsFilters = hostsConfig.filters;
}])
.run(['readConfig', 'hostsConfig', function (readConfig, hostsConfig) {
hostsConfig.cells = readConfig.hostsConfig.cells;
hostsConfig.apiName = readConfig.hostsConfig.apiName;
hostsConfig.filters = readConfig.hostsConfig.filters;
}]);