From 2f4c1e04c4c3cd11796f3cdfa8edca41cffaada3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Vachon?= Date: Thu, 26 Feb 2015 16:44:08 -0500 Subject: [PATCH] Single Table template --- app/components/config/config.json | 70 ++----------------- app/components/table/table.js | 105 ++++++++++++++-------------- app/components/tactical/tactical.js | 3 +- app/custom_views/custom_views.html | 17 ++--- app/custom_views/custom_views.js | 29 +++++--- app/dashboard/dashboard.html | 4 +- app/dashboard/dashboard.js | 20 +++--- 7 files changed, 97 insertions(+), 151 deletions(-) diff --git a/app/components/config/config.json b/app/components/config/config.json index d978453..a109953 100644 --- a/app/components/config/config.json +++ b/app/components/config/config.json @@ -1,7 +1,7 @@ { "dashboardConfig": { "title": "Unhandled service problems", - "refreshInterval": "0", + "refreshInterval": "10000", "template": "", "components" : [ { @@ -82,7 +82,7 @@ "hostsConfig": { "title": "Hosts", "refreshInterval": "10000", - "template": "", + "template": "singleTable", "components": [ { "type": "table", @@ -115,11 +115,11 @@ "servicesConfig": { "title": "Services", "refreshInterval": "10000", - "template": "", + "template": "singleTable", "components": [{ - "title": "Services", "type": "table", "config": { + "title": "Services", "cells": { "text": [ "Host", @@ -140,67 +140,5 @@ "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" - } - }] - } } } diff --git a/app/components/table/table.js b/app/components/table/table.js index 71b4fe6..015ad6e 100644 --- a/app/components/table/table.js +++ b/app/components/table/table.js @@ -16,29 +16,28 @@ angular.module('adagios.table', ['adagios.live', .controller('TableCtrl', ['$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 = [], - filters = JSON.parse(tableConfig[tableConfig.index].filters), - conf = tableConfig[tableConfig.index], - i; + $scope.cellsName = conf.cells.name; + $scope.cellsText = conf.cells.text; + $scope.cellIndexes = []; - $scope.cellsName = conf.cells.name; - $scope.cellsText = conf.cells.text; - $scope.cellIndexes = []; + for (i = 0; i < $scope.cellsName.length; i += 1) { + $scope.cellIndexes.push(i); + } - for (i = 0; i < $scope.cellsName.length; i += 1) { - $scope.cellIndexes.push(i); - } - - angular.forEach($scope.cellsName, function (key) { - 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); + }); }); - }); - - $scope.getData = - function (requestFields, filters, apiName) { - getServices(requestFields, filters, conf.apiName) + + getData = function (requestFields, filters, apiName) { + getServices(requestFields, filters, apiName) .success(function (data) { var fieldToWrap = tableConfig.cellWrappableField[conf.noRepeatCell], cellFields = tableConfig.cellToFieldsMap[conf.noRepeatCell]; @@ -49,19 +48,19 @@ angular.module('adagios.table', ['adagios.live', $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); - - 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; - }]) + // Used if there's more than one table in a view + tableConfig.index += 1; + }]) .directive('adgTable', ['$http', '$compile', 'tableConfig', function ($http, $compile, tableConfig) { return { @@ -74,26 +73,26 @@ angular.module('adagios.table', ['adagios.live', + ' and "is-wrappable" attributes must be defined'); } - tableConfig[attrs.tableIndex] = {}; - tableConfig[attrs.tableIndex].filters = {}; + tableConfig[attrs.tableId] = {}; + tableConfig[attrs.tableId].filters = {}; - tableConfig[attrs.tableIndex].cells = { 'text': [], 'name': [] }; - tableConfig[attrs.tableIndex].cells.text = attrs.cellsText.split(','); - tableConfig[attrs.tableIndex].cells.name = attrs.cellsName.split(','); + tableConfig[attrs.tableId].cells = { 'text': [], 'name': [] }; + tableConfig[attrs.tableId].cells.text = attrs.cellsText.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) { tableConfig.refreshInterval = attrs.refreshInterval; } if (!!attrs.filters) { - tableConfig[attrs.tableIndex].filters = attrs.filters; + tableConfig[attrs.tableId].filters = attrs.filters; } 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) { angular.forEach(fields, function (value) { - entry[value] = ''; + entry[value] = ''; }); - }; + } // Erase subsequently repeated data of a given cell only keeping the first occurrence // fieldToProcess is the field to watch for subsequent repetition @@ -145,24 +144,23 @@ angular.module('adagios.table', ['adagios.live', var last = '', actual = '', entry = {}, - first_child = false, parent_found = false, class_name = ['', ''], i; - if (isWrappable == "true") { + if (isWrappable === "true") { class_name = ['state--hasChild', 'state--isChild']; } - + for (i = 0; i < data.length; i += 1) { entry = data[i]; actual = entry[fieldToProcess]; if (entry[fieldToProcess] === last) { - if (!data[i-1].has_child && !parent_found) { - data[i-1].has_child = 1; - data[i-1].child_class = class_name[0]; + if (!data[i - 1].has_child && !parent_found) { + data[i - 1].has_child = 1; + data[i - 1].child_class = class_name[0]; entry.child_class = class_name[1]; parent_found = true; } else { @@ -173,7 +171,6 @@ angular.module('adagios.table', ['adagios.live', clearFields(entry, fields); } else { - first_child = false; parent_found = false; } @@ -181,5 +178,5 @@ angular.module('adagios.table', ['adagios.live', } return data; - } + }; }); diff --git a/app/components/tactical/tactical.js b/app/components/tactical/tactical.js index 2119883..c428874 100644 --- a/app/components/tactical/tactical.js +++ b/app/components/tactical/tactical.js @@ -27,11 +27,12 @@ angular.module('adagios.tactical', ['adagios.tactical.status_overview', compile: function compile() { return { 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.currentHealth = JSON.parse(iAttrs.currentHealth.toLowerCase()); tacticalConfig.topAlertProducers = JSON.parse(iAttrs.topAlertProducers.toLowerCase()); } - } + }; } }; }]); diff --git a/app/custom_views/custom_views.html b/app/custom_views/custom_views.html index 2b49c70..770d831 100644 --- a/app/custom_views/custom_views.html +++ b/app/custom_views/custom_views.html @@ -5,18 +5,19 @@
-

{{customViewTitle}}

+

{{singleTableTitle}}

- + diff --git a/app/custom_views/custom_views.js b/app/custom_views/custom_views.js index b7e9701..463f875 100644 --- a/app/custom_views/custom_views.js +++ b/app/custom_views/custom_views.js @@ -27,21 +27,28 @@ angular.module('adagios.view.custom', ['ngRoute', return; } - $scope.customViewTitle = customViewsConfig[viewName].title; - $scope.customViewCellsText = customViewsConfig[viewName].cells.text.join(); - $scope.customViewCellsName = customViewsConfig[viewName].cells.name.join(); - $scope.customViewApiName = customViewsConfig[viewName].apiName; - $scope.customViewFilters = customViewsConfig[viewName].filters; - $scope.customViewIsWrappable = customViewsConfig[viewName].isWrappable; - $scope.customViewNoRepeatCell = customViewsConfig[viewName].noRepeatCell; - $scope.customViewRefreshInterval = customViewsConfig[viewName].refreshInterval; + function TableConfig(config) { + 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.IsWrappable = config.isWrappable; + 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) { - var viewsConfig = readConfig.data.customViewsConfig; + var viewsConfig = readConfig.data; angular.forEach(viewsConfig, function (config, view) { - customViewsConfig[view] = config; + if (config.template === "singleTable") { + customViewsConfig[view] = config; + } }); - }]); diff --git a/app/dashboard/dashboard.html b/app/dashboard/dashboard.html index 4432455..09da4bf 100644 --- a/app/dashboard/dashboard.html +++ b/app/dashboard/dashboard.html @@ -50,7 +50,7 @@ is-wrappable="{{dashboardTables[0].IsWrappable}}" no-repeat-cell="{{dashboardTables[0].NoRepeatCell}}" refresh-interval="{{dashboardRefreshInterval}}" - table-index="0"> + table-id="0"> @@ -67,7 +67,7 @@ is-wrappable="{{dashboardTables[1].IsWrappable}}" no-repeat-cell="{{dashboardTables[1].NoRepeatCell}}" refresh-interval="{{dashboardRefreshInterval}}" - table-index="1"> + table-id="1"> diff --git a/app/dashboard/dashboard.js b/app/dashboard/dashboard.js index efaa816..bd1668b 100644 --- a/app/dashboard/dashboard.js +++ b/app/dashboard/dashboard.js @@ -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'], filters = {'isnot' : { 'state' : ['0'] }}, apiName = 'hosts', components = [], + component, + config, i = 0; $scope.dashboardTitle = dashboardConfig.data.title; @@ -32,7 +34,7 @@ angular.module('adagios.view.dashboard', ['ngRoute', components = dashboardConfig.data.components; - function tableConfig(config) { + function TableConfig(config) { this.title = config.title; this.CellsText = config.cells.text.join(); this.CellsName = config.cells.name.join(); @@ -40,23 +42,23 @@ angular.module('adagios.view.dashboard', ['ngRoute', this.Filters = config.filters; this.IsWrappable = config.isWrappable; this.NoRepeatCell = config.noRepeatCell; - }; + } - function tacticalConfig(config) { + function TacticalConfig(config) { this.title = config.title; this.statusOverview = config.components.statusOverview; this.currentHealth = config.components.currentHealth; this.topAlertProducers = config.components.topAlertProducers; - }; + } for (i = 0; i < components.length; i += 1) { - var component = components[i], - config = component.config; + component = components[i]; + config = component.config; if (component.type === 'table') { - $scope.dashboardTables.push(new tableConfig(config)); + $scope.dashboardTables.push(new TableConfig(config)); } else if (component.type === 'tactical') { - $scope.dashboardTactical.push(new tacticalConfig(config)); + $scope.dashboardTactical.push(new TacticalConfig(config)); console.log($scope.dashboardTactical[0].statusOverview); } }