Single Table template

This commit is contained in:
Frédéric Vachon
2015-02-26 16:44:08 -05:00
parent bae160e75c
commit 2f4c1e04c4
7 changed files with 97 additions and 151 deletions

View File

@@ -1,7 +1,7 @@
{ {
"dashboardConfig": { "dashboardConfig": {
"title": "Unhandled service problems", "title": "Unhandled service problems",
"refreshInterval": "0", "refreshInterval": "10000",
"template": "", "template": "",
"components" : [ "components" : [
{ {
@@ -82,7 +82,7 @@
"hostsConfig": { "hostsConfig": {
"title": "Hosts", "title": "Hosts",
"refreshInterval": "10000", "refreshInterval": "10000",
"template": "", "template": "singleTable",
"components": [ "components": [
{ {
"type": "table", "type": "table",
@@ -115,11 +115,11 @@
"servicesConfig": { "servicesConfig": {
"title": "Services", "title": "Services",
"refreshInterval": "10000", "refreshInterval": "10000",
"template": "", "template": "singleTable",
"components": [{ "components": [{
"title": "Services",
"type": "table", "type": "table",
"config": { "config": {
"title": "Services",
"cells": { "cells": {
"text": [ "text": [
"Host", "Host",
@@ -140,67 +140,5 @@
"noRepeatCell" : "host" "noRepeatCell" : "host"
} }
}] }]
},
"customViewsConfig": {
"customView1": {
"title": "Custom View 1",
"refreshInterval": "10000",
"template": "",
"components": [{
"type": "table",
"config": {
"title": "Custom View 1",
"cells": {
"text": [
"Host",
"Address",
"Duration",
"Last check",
"Host status"
],
"name": [
"hosts_host",
"host_address",
"duration",
"last_check",
"host_status"
]
},
"apiName": "hosts",
"filters": {},
"isWrappable" : false,
"noRepeatCell" : ""
}
}]
},
"customView2": {
"title": "Custom View 2",
"refreshInterval": "10000",
"template": "",
"components": [{
"type": "table",
"config": {
"title": "Custom View 2",
"cells": {
"text": [
"Host",
"Service check",
"Duration",
"Last check"
],
"name": [
"host",
"service_check",
"duration",
"last_check"
]
},
"apiName": "services",
"filters": {},
"isWrappable" : false,
"noRepeatCell" : "host"
}
}]
}
} }
} }

View File

@@ -16,29 +16,28 @@ angular.module('adagios.table', ['adagios.live',
.controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'processColumnRepeat', .controller('TableCtrl', ['$scope', '$interval', 'getServices', 'tableConfig', 'processColumnRepeat',
function ($scope, $interval, getServices, tableConfig, processColumnRepeat) { function ($scope, $interval, getServices, tableConfig, processColumnRepeat) {
var requestFields = [],
filters = JSON.parse(tableConfig[tableConfig.index].filters),
conf = tableConfig[tableConfig.index],
getData,
i;
var requestFields = [], $scope.cellsName = conf.cells.name;
filters = JSON.parse(tableConfig[tableConfig.index].filters), $scope.cellsText = conf.cells.text;
conf = tableConfig[tableConfig.index], $scope.cellIndexes = [];
i;
$scope.cellsName = conf.cells.name; for (i = 0; i < $scope.cellsName.length; i += 1) {
$scope.cellsText = conf.cells.text; $scope.cellIndexes.push(i);
$scope.cellIndexes = []; }
for (i = 0; i < $scope.cellsName.length; i += 1) { angular.forEach($scope.cellsName, function (key) {
$scope.cellIndexes.push(i); angular.forEach(tableConfig.cellToFieldsMap[key], function (_value) {
} requestFields.push(_value);
});
angular.forEach($scope.cellsName, function (key) {
angular.forEach(tableConfig.cellToFieldsMap[key], function (_value) {
requestFields.push(_value);
}); });
});
getData = function (requestFields, filters, apiName) {
$scope.getData = getServices(requestFields, filters, apiName)
function (requestFields, filters, apiName) {
getServices(requestFields, filters, conf.apiName)
.success(function (data) { .success(function (data) {
var fieldToWrap = tableConfig.cellWrappableField[conf.noRepeatCell], var fieldToWrap = tableConfig.cellWrappableField[conf.noRepeatCell],
cellFields = tableConfig.cellToFieldsMap[conf.noRepeatCell]; cellFields = tableConfig.cellToFieldsMap[conf.noRepeatCell];
@@ -49,19 +48,19 @@ angular.module('adagios.table', ['adagios.live',
$scope.entries = data; $scope.entries = data;
}); });
};
getData(requestFields, filters, conf.apiName);
if (tableConfig.refreshInterval !== '0') {
$interval(function () {
getData(requestFields, filters, conf.apiName);
}, tableConfig.refreshInterval);
} }
$scope.getData(requestFields, filters, conf.apiName); // Used if there's more than one table in a view
tableConfig.index += 1;
if (tableConfig.refreshInterval !== '0') { }])
$interval(function() {
$scope.getData(requestFields, filters, conf.apiName);
}, tableConfig.refreshInterval);
}
// Used if there's more than one table in a view
tableConfig.index += 1;
}])
.directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) { .directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) {
return { return {
@@ -74,26 +73,26 @@ angular.module('adagios.table', ['adagios.live',
+ ' and "is-wrappable" attributes must be defined'); + ' and "is-wrappable" attributes must be defined');
} }
tableConfig[attrs.tableIndex] = {}; tableConfig[attrs.tableId] = {};
tableConfig[attrs.tableIndex].filters = {}; tableConfig[attrs.tableId].filters = {};
tableConfig[attrs.tableIndex].cells = { 'text': [], 'name': [] }; tableConfig[attrs.tableId].cells = { 'text': [], 'name': [] };
tableConfig[attrs.tableIndex].cells.text = attrs.cellsText.split(','); tableConfig[attrs.tableId].cells.text = attrs.cellsText.split(',');
tableConfig[attrs.tableIndex].cells.name = attrs.cellsName.split(','); tableConfig[attrs.tableId].cells.name = attrs.cellsName.split(',');
tableConfig[attrs.tableIndex].apiName = attrs.apiName; tableConfig[attrs.tableId].apiName = attrs.apiName;
tableConfig[attrs.tableId].isWrappable = false;
tableConfig[attrs.tableId].isWrappable = attrs.isWrappable;
tableConfig[attrs.tableId].noRepeatCell = attrs.noRepeatCell;
tableConfig[attrs.tableId].tableId = attrs.tableId;
tableConfig[attrs.tableIndex].isWrappable = false;
tableConfig[attrs.tableIndex].isWrappable = attrs.isWrappable;
tableConfig[attrs.tableIndex].noRepeatCell = attrs.noRepeatCell;
tableConfig[attrs.tableIndex].tableIndex = attrs.tableIndex;
if (!!attrs.refreshInterval) { if (!!attrs.refreshInterval) {
tableConfig.refreshInterval = attrs.refreshInterval; tableConfig.refreshInterval = attrs.refreshInterval;
} }
if (!!attrs.filters) { if (!!attrs.filters) {
tableConfig[attrs.tableIndex].filters = attrs.filters; tableConfig[attrs.tableId].filters = attrs.filters;
} }
var template = 'components/table/table.html'; var template = 'components/table/table.html';
@@ -130,13 +129,13 @@ angular.module('adagios.table', ['adagios.live',
}; };
}]) }])
.service('processColumnRepeat', function() { .service('processColumnRepeat', function () {
function clearFields(entry, fields) { function clearFields(entry, fields) {
angular.forEach(fields, function (value) { angular.forEach(fields, function (value) {
entry[value] = ''; entry[value] = '';
}); });
}; }
// Erase subsequently repeated data of a given cell only keeping the first occurrence // Erase subsequently repeated data of a given cell only keeping the first occurrence
// fieldToProcess is the field to watch for subsequent repetition // fieldToProcess is the field to watch for subsequent repetition
@@ -145,24 +144,23 @@ angular.module('adagios.table', ['adagios.live',
var last = '', var last = '',
actual = '', actual = '',
entry = {}, entry = {},
first_child = false,
parent_found = false, parent_found = false,
class_name = ['', ''], class_name = ['', ''],
i; i;
if (isWrappable == "true") { if (isWrappable === "true") {
class_name = ['state--hasChild', 'state--isChild']; class_name = ['state--hasChild', 'state--isChild'];
} }
for (i = 0; i < data.length; i += 1) { for (i = 0; i < data.length; i += 1) {
entry = data[i]; entry = data[i];
actual = entry[fieldToProcess]; actual = entry[fieldToProcess];
if (entry[fieldToProcess] === last) { if (entry[fieldToProcess] === last) {
if (!data[i-1].has_child && !parent_found) { if (!data[i - 1].has_child && !parent_found) {
data[i-1].has_child = 1; data[i - 1].has_child = 1;
data[i-1].child_class = class_name[0]; data[i - 1].child_class = class_name[0];
entry.child_class = class_name[1]; entry.child_class = class_name[1];
parent_found = true; parent_found = true;
} else { } else {
@@ -173,7 +171,6 @@ angular.module('adagios.table', ['adagios.live',
clearFields(entry, fields); clearFields(entry, fields);
} else { } else {
first_child = false;
parent_found = false; parent_found = false;
} }
@@ -181,5 +178,5 @@ angular.module('adagios.table', ['adagios.live',
} }
return data; return data;
} };
}); });

View File

@@ -27,11 +27,12 @@ angular.module('adagios.tactical', ['adagios.tactical.status_overview',
compile: function compile() { compile: function compile() {
return { return {
pre: function preLink(scope, iElement, iAttrs, controller) { pre: function preLink(scope, iElement, iAttrs, controller) {
// This is the earliest phase during which attributes are evaluated
tacticalConfig.statusOverview = JSON.parse(iAttrs.statusOverview.toLowerCase()); tacticalConfig.statusOverview = JSON.parse(iAttrs.statusOverview.toLowerCase());
tacticalConfig.currentHealth = JSON.parse(iAttrs.currentHealth.toLowerCase()); tacticalConfig.currentHealth = JSON.parse(iAttrs.currentHealth.toLowerCase());
tacticalConfig.topAlertProducers = JSON.parse(iAttrs.topAlertProducers.toLowerCase()); tacticalConfig.topAlertProducers = JSON.parse(iAttrs.topAlertProducers.toLowerCase());
} }
} };
} }
}; };
}]); }]);

View File

@@ -5,18 +5,19 @@
<div class="tab-content"> <div class="tab-content">
<div role="tabpanel" class="problems tab-pane active" id="openProblems"> <div role="tabpanel" class="problems tab-pane active" id="openProblems">
<header class="main__content__header clearfix"> <header class="main__content__header clearfix">
<h2 class="main__content__title">{{customViewTitle}}</h2> <h2 class="main__content__title">{{singleTableTitle}}</h2>
</header> </header>
</div> </div>
</div> </div>
<adg-table cells-name="{{customViewCellsName}}" <adg-table cells-name="{{tableConfig.CellsName}}"
cells-text="{{customViewCellsText}}" cells-text="{{tableConfig.CellsText}}"
api-name="{{customViewApiName}}" api-name="{{tableConfig.ApiName}}"
filters="{{customViewFilters}}" filters="{{tableConfig.Filters}}"
is-wrappable="{{customViewIsWrappable}}" is-wrappable="{{tableConfig.IsWrappable}}"
no-repeat-cell="{{customViewNoRepeatCell}}" no-repeat-cell="{{tableConfig.NoRepeatCell}}"
refresh-interval="{{customViewRefreshInterval}}"></adg-table> refresh-interval="{{singleTableRefreshInterval}}"
table-id="0"></adg-table>
</section> </section>
</article> </article>

View File

@@ -27,21 +27,28 @@ angular.module('adagios.view.custom', ['ngRoute',
return; return;
} }
$scope.customViewTitle = customViewsConfig[viewName].title; function TableConfig(config) {
$scope.customViewCellsText = customViewsConfig[viewName].cells.text.join(); this.title = config.title;
$scope.customViewCellsName = customViewsConfig[viewName].cells.name.join(); this.CellsText = config.cells.text.join();
$scope.customViewApiName = customViewsConfig[viewName].apiName; this.CellsName = config.cells.name.join();
$scope.customViewFilters = customViewsConfig[viewName].filters; this.ApiName = config.apiName;
$scope.customViewIsWrappable = customViewsConfig[viewName].isWrappable; this.Filters = config.filters;
$scope.customViewNoRepeatCell = customViewsConfig[viewName].noRepeatCell; this.IsWrappable = config.isWrappable;
$scope.customViewRefreshInterval = customViewsConfig[viewName].refreshInterval; this.NoRepeatCell = config.noRepeatCell;
}
$scope.tableConfig = new TableConfig(customViewsConfig[viewName].components[0].config);
$scope.singleTableTitle = customViewsConfig[viewName].title;
$scope.singleTableRefreshInterval = customViewsConfig[viewName].refreshInterval;
}]) }])
.run(['readConfig', 'customViewsConfig', function (readConfig, customViewsConfig) { .run(['readConfig', 'customViewsConfig', function (readConfig, customViewsConfig) {
var viewsConfig = readConfig.data.customViewsConfig; var viewsConfig = readConfig.data;
angular.forEach(viewsConfig, function (config, view) { angular.forEach(viewsConfig, function (config, view) {
customViewsConfig[view] = config; if (config.template === "singleTable") {
customViewsConfig[view] = config;
}
}); });
}]); }]);

View File

@@ -50,7 +50,7 @@
is-wrappable="{{dashboardTables[0].IsWrappable}}" is-wrappable="{{dashboardTables[0].IsWrappable}}"
no-repeat-cell="{{dashboardTables[0].NoRepeatCell}}" no-repeat-cell="{{dashboardTables[0].NoRepeatCell}}"
refresh-interval="{{dashboardRefreshInterval}}" refresh-interval="{{dashboardRefreshInterval}}"
table-index="0"></adg-table> table-id="0"></adg-table>
</div> </div>
@@ -67,7 +67,7 @@
is-wrappable="{{dashboardTables[1].IsWrappable}}" is-wrappable="{{dashboardTables[1].IsWrappable}}"
no-repeat-cell="{{dashboardTables[1].NoRepeatCell}}" no-repeat-cell="{{dashboardTables[1].NoRepeatCell}}"
refresh-interval="{{dashboardRefreshInterval}}" refresh-interval="{{dashboardRefreshInterval}}"
table-index="1"></adg-table> table-id="1"></adg-table>
</div> </div>
</div> </div>

View File

@@ -15,12 +15,14 @@ angular.module('adagios.view.dashboard', ['ngRoute',
}); });
}]) }])
.controller('DashboardCtrl', ['$scope', '$timeout', 'dashboardConfig', 'getServices', function ($scope, $timeout, dashboardConfig, getServices) { .controller('DashboardCtrl', ['$scope', 'dashboardConfig', 'getServices', function ($scope, dashboardConfig, getServices) {
var fields = ['state'], var fields = ['state'],
filters = {'isnot' : { 'state' : ['0'] }}, filters = {'isnot' : { 'state' : ['0'] }},
apiName = 'hosts', apiName = 'hosts',
components = [], components = [],
component,
config,
i = 0; i = 0;
$scope.dashboardTitle = dashboardConfig.data.title; $scope.dashboardTitle = dashboardConfig.data.title;
@@ -32,7 +34,7 @@ angular.module('adagios.view.dashboard', ['ngRoute',
components = dashboardConfig.data.components; components = dashboardConfig.data.components;
function tableConfig(config) { function TableConfig(config) {
this.title = config.title; this.title = config.title;
this.CellsText = config.cells.text.join(); this.CellsText = config.cells.text.join();
this.CellsName = config.cells.name.join(); this.CellsName = config.cells.name.join();
@@ -40,23 +42,23 @@ angular.module('adagios.view.dashboard', ['ngRoute',
this.Filters = config.filters; this.Filters = config.filters;
this.IsWrappable = config.isWrappable; this.IsWrappable = config.isWrappable;
this.NoRepeatCell = config.noRepeatCell; this.NoRepeatCell = config.noRepeatCell;
}; }
function tacticalConfig(config) { function TacticalConfig(config) {
this.title = config.title; this.title = config.title;
this.statusOverview = config.components.statusOverview; this.statusOverview = config.components.statusOverview;
this.currentHealth = config.components.currentHealth; this.currentHealth = config.components.currentHealth;
this.topAlertProducers = config.components.topAlertProducers; this.topAlertProducers = config.components.topAlertProducers;
}; }
for (i = 0; i < components.length; i += 1) { for (i = 0; i < components.length; i += 1) {
var component = components[i], component = components[i];
config = component.config; config = component.config;
if (component.type === 'table') { if (component.type === 'table') {
$scope.dashboardTables.push(new tableConfig(config)); $scope.dashboardTables.push(new TableConfig(config));
} else if (component.type === 'tactical') { } else if (component.type === 'tactical') {
$scope.dashboardTactical.push(new tacticalConfig(config)); $scope.dashboardTactical.push(new TacticalConfig(config));
console.log($scope.dashboardTactical[0].statusOverview); console.log($scope.dashboardTactical[0].statusOverview);
} }
} }