Allow for multiple table input sources

Change-Id: I7d5bbfd2991462eacc47d4f0a2ded46da2cb8f9d
This commit is contained in:
aviau 2015-05-21 17:51:13 -04:00
parent 24f73d6e66
commit 57f2ebd3d4
5 changed files with 94 additions and 65 deletions

View File

@ -35,16 +35,21 @@
"status_host_status"
]
},
"apiName": "hosts",
"filters": {
"is": {
"acknowledged": [
false
],
"state": [
"DOWN",
"UNREACHABLE"
]
"inputSource": {
"service": "surveilStatus",
"config": {
"apiName": "hosts",
"filters": {
"is": {
"acknowledged": [
false
],
"state": [
"DOWN",
"UNREACHABLE"
]
}
}
}
},
"isWrappable": false,
@ -69,21 +74,26 @@
"status_last_check"
]
},
"apiName": "services",
"filters": {
"isnot": {
"state": [
"OK"
],
"host_state": [
"DOWN",
"UNREACHABLE"
]
},
"is": {
"acknowledged": [
false
]
"inputSource": {
"service": "surveilStatus",
"config": {
"apiName": "services",
"filters": {
"isnot": {
"state": [
"OK"
],
"host_state": [
"DOWN",
"UNREACHABLE"
]
},
"is": {
"acknowledged": [
false
]
}
}
}
},
"isWrappable": true,
@ -110,12 +120,17 @@
"status_host_status"
]
},
"apiName": "hosts",
"filters": {
"isnot": {
"state": [
"UP"
]
"inputSource": {
"service": "surveilStatus",
"config": {
"apiName": "hosts",
"filters": {
"isnot": {
"state": [
"UP"
]
}
}
}
},
"isWrappable": false,
@ -140,12 +155,17 @@
"status_last_check"
]
},
"apiName": "services",
"filters": {
"isnot": {
"state": [
"OK"
]
"inputSource": {
"service": "surveilStatus",
"config": {
"apiName": "services",
"filters": {
"isnot": {
"state": [
"OK"
]
}
}
}
},
"isWrappable": true,
@ -179,8 +199,13 @@
"status_host_status"
]
},
"apiName": "hosts",
"filters": {},
"inputSource": {
"service": "surveilStatus",
"config": {
"apiName": "hosts",
"filters": {}
}
},
"isWrappable": false,
"noRepeatCell": ""
}
@ -210,8 +235,13 @@
"status_last_check"
]
},
"apiName": "services",
"filters": {},
"inputSource": {
"service": "surveilStatus",
"config": {
"apiName": "services",
"filters": {}
}
},
"isWrappable": false,
"noRepeatCell": "host"
}

View File

@ -250,7 +250,7 @@ angular.module('bansho.surveil')
return data;
};
var getTableData = function (fields, filters, apiName) {
var getTableData = function (fields, inputSourceConfig) {
var hostFields = [],
serviceFields = [],
hostFilters = {},
@ -264,8 +264,8 @@ angular.module('bansho.surveil')
i,
found = false;
if (apiName === 'hosts') {
this.getObjects(fields, filters, 'hosts')
if (inputSourceConfig.apiName === 'hosts') {
this.getObjects(fields, inputSourceConfig.filters, 'hosts')
.success(function (data) {
responsePromise.resolve(data);
});
@ -289,7 +289,7 @@ angular.module('bansho.surveil')
serviceFields.push('host_name');
}
angular.forEach(filters, function (filterData, filterName) {
angular.forEach(inputSourceConfig.filters, function (filterData, filterName) {
angular.forEach(filterData, function (values, field) {
if (field in hostKeys) {
if (!(filterData in hostFilters)) {

View File

@ -22,7 +22,12 @@ angular.module('bansho.table', ['bansho.surveil',
var requestFields = [],
conf = tablesConfig[tableGlobalConfig.nextTableIndex],
getData,
i;
i,
inputSourceServices;
inputSourceServices = {
surveilStatus: surveilStatus
};
$scope.cellsName = conf.cells.name;
$scope.cellsText = conf.cells.text;
@ -52,8 +57,8 @@ angular.module('bansho.table', ['bansho.surveil',
});
});
getData = function (requestFields, filters, apiName) {
var promise = surveilStatus.getTableData(requestFields, filters, apiName);
getData = function (requestFields, inputSource) {
var promise = inputSourceServices[inputSource.service].getTableData(requestFields, inputSource.config);
promise.then(function (data) {
$scope.entries = data;
conf.entries = data;
@ -62,12 +67,12 @@ angular.module('bansho.table', ['bansho.surveil',
});
};
getData(requestFields, conf.filters, conf.apiName);
getData(requestFields, conf.inputSource);
if (tableGlobalConfig.refreshInterval !== 0) {
promisesManager.addAjaxPromise(
$interval(function () {
getData(requestFields, conf.filters, conf.apiName);
getData(requestFields, conf.inputSource);
}, tableGlobalConfig.refreshInterval)
);
}
@ -89,28 +94,23 @@ angular.module('bansho.table', ['bansho.surveil',
var template = 'components/table/table.html',
conf;
if (!attrs.cellsText || !attrs.cellsName || !attrs.apiName || !attrs.isWrappable) {
throw new Error('<bansho-table> "cells-text", "cells-name", "api-name" and "is-wrappable" attributes must be defined');
if (!attrs.cellsText || !attrs.cellsName || !attrs.inputSource || !attrs.isWrappable) {
throw new Error('<bansho-table> "cells-text", "cells-name", "inputSource" and "is-wrappable" attributes must be defined');
}
tablesConfig[attrs.tableId] = {};
conf = tablesConfig[attrs.tableId];
conf.filters = {};
conf.cells = { 'text': [], 'name': [] };
conf.cells.text = attrs.cellsText.split(',');
conf.cells.name = attrs.cellsName.split(',');
conf.apiName = attrs.apiName;
conf.inputSource = JSON.parse(attrs.inputSource);
conf.isWrappable = JSON.parse(attrs.isWrappable);
conf.noRepeatCell = attrs.noRepeatCell;
tableGlobalConfig.tableId = attrs.tableId;
if (!!attrs.filters) {
conf.filters = JSON.parse(attrs.filters);
}
if (!!attrs.refreshInterval) {
tableGlobalConfig.refreshInterval = parseInt(attrs.refreshInterval * 1000, 10);
}
@ -160,8 +160,7 @@ angular.module('bansho.table', ['bansho.surveil',
this.title = config.title;
this.CellsText = config.cells.text.join();
this.CellsName = config.cells.name.join();
this.ApiName = config.apiName;
this.Filters = config.filters;
this.InputSource = config.inputSource;
this.IsWrappable = config.isWrappable;
this.NoRepeatCell = config.noRepeatCell;
})

View File

@ -54,7 +54,7 @@
<bansho-table cells-text="{{dashboardTables[0].CellsText}}"
cells-name="{{dashboardTables[0].CellsName}}"
api-name="{{dashboardTables[0].ApiName}}"
input-source="{{dashboardTables[0].InputSource}}"
filters="{{dashboardTables[0].Filters}}"
is-wrappable="{{dashboardTables[0].IsWrappable}}"
no-repeat-cell="{{dashboardTables[0].NoRepeatCell}}"
@ -79,7 +79,7 @@
<bansho-table cells-text="{{dashboardTables[1].CellsText}}"
cells-name="{{dashboardTables[1].CellsName}}"
api-name="{{dashboardTables[1].ApiName}}"
input-source="{{dashboardTables[1].InputSource}}"
filters="{{dashboardTables[1].Filters}}"
is-wrappable="{{dashboardTables[1].IsWrappable}}"
no-repeat-cell="{{dashboardTables[1].NoRepeatCell}}"
@ -106,7 +106,7 @@
<bansho-table cells-text="{{dashboardTables[2].CellsText}}"
cells-name="{{dashboardTables[2].CellsName}}"
api-name="{{dashboardTables[2].ApiName}}"
input-source="{{dashboardTables[2].InputSource}}"
filters="{{dashboardTables[2].Filters}}"
is-wrappable="{{dashboardTables[2].IsWrappable}}"
no-repeat-cell="{{dashboardTables[2].NoRepeatCell}}"
@ -129,7 +129,7 @@
<bansho-table cells-text="{{dashboardTables[3].CellsText}}"
cells-name="{{dashboardTables[3].CellsName}}"
api-name="{{dashboardTables[3].ApiName}}"
input-source="{{dashboardTables[3].InputSource}}"
filters="{{dashboardTables[3].Filters}}"
is-wrappable="{{dashboardTables[3].IsWrappable}}"
no-repeat-cell="{{dashboardTables[3].NoRepeatCell}}"

View File

@ -14,7 +14,7 @@
<bansho-table cells-name="{{tableConfig.CellsName}}"
cells-text="{{tableConfig.CellsText}}"
api-name="{{tableConfig.ApiName}}"
input-source="{{tableConfig.InputSource}}"
filters="{{tableConfig.Filters}}"
is-wrappable="{{tableConfig.IsWrappable}}"
no-repeat-cell="{{tableConfig.NoRepeatCell}}"