Config is not loaded in 'run' anymore

This commit is contained in:
Frédéric Vachon 2015-04-30 14:24:59 -04:00
parent 0d49eb7a00
commit d2df46467a
4 changed files with 40 additions and 35 deletions

View File

@ -18,4 +18,17 @@ angular.module('bansho.config', [])
this.$get = [function () {
return new AdagiosConfig(data);
}];
});
})
.service('configManager', ['readConfig', function (readConfig) {
this.loadByTemplate = function (templateName, destination) {
var viewsConfig = readConfig.data;
angular.forEach(viewsConfig, function (config, view) {
if (config.template === templateName) {
destination[view] = config;
}
});
}
}]);

View File

@ -13,11 +13,15 @@ angular.module('bansho.view', ['ngRoute',
});
}])
.controller('ViewCtrl', ['$scope', '$routeParams', 'viewsTemplate',
function ($scope, $routeParams, viewsTemplate) {
.controller('ViewCtrl', ['$scope', '$routeParams', 'viewsTemplate', 'loadConfig',
function ($scope, $routeParams, viewsTemplate, loadConfig) {
var templateName,
templateUrl;
if (jQuery.isEmptyObject(viewsTemplate)) {
loadConfig
}
if (!!$routeParams.view) {
$scope.viewName = $routeParams.view;
} else {
@ -28,7 +32,7 @@ angular.module('bansho.view', ['ngRoute',
$scope.templateUrl = 'templates/' + templateName + '/' + templateName + '.html';
}])
.run(['readConfig', 'viewsTemplate', function (readConfig, viewsTemplate) {
.service('loadConfig', ['readConfig', 'viewsTemplate', function (readConfig, viewsTemplate) {
var viewsConfig = readConfig.data;
angular.forEach(viewsConfig, function (config, view) {

View File

@ -1,18 +1,18 @@
'use strict';
angular.module('bansho.view.dashboard', ['ngRoute',
'bansho.utils.promiseManager',
'bansho.tactical',
'bansho.table',
'bansho.live'
])
'bansho.utils.promiseManager',
'bansho.tactical',
'bansho.table',
'bansho.live'
])
.value('dashboardConfig', {})
.controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'dashboardConfig', 'getObjects',
.controller('DashboardCtrl', ['$scope', '$routeParams', '$interval', 'configManager', 'dashboardConfig', 'getObjects',
'TableConfigObj', 'TacticalConfigObj', 'getHostOpenProblems', 'getServiceOpenProblems', 'getHostProblems',
'getServiceProblems', 'addAjaxPromise',
function ($scope, $routeParams, $interval, dashboardConfig, getObjects, TableConfigObj, TacticalConfigObj, getHostOpenProblems,
function ($scope, $routeParams, $interval, configManager, dashboardConfig, getObjects, TableConfigObj, TacticalConfigObj, getHostOpenProblems,
getServiceOpenProblems, getHostProblems, getServiceProblems, addAjaxPromise) {
var components = [],
component,
@ -21,6 +21,10 @@ angular.module('bansho.view.dashboard', ['ngRoute',
i = 0,
getData;
if (jQuery.isEmptyObject(dashboardConfig)) {
configManager.loadByTemplate('dashboard', dashboardConfig);
}
$scope.dashboardTitle = dashboardConfig[viewName].title;
$scope.dashboardTemplate = dashboardConfig[viewName].template;
$scope.dashboardRefreshInterval = dashboardConfig[viewName].refreshInterval;
@ -66,14 +70,4 @@ angular.module('bansho.view.dashboard', ['ngRoute',
}
getData();
}])
.run(['readConfig', 'dashboardConfig', function (readConfig, dashboardConfig) {
var viewsConfig = readConfig.data;
angular.forEach(viewsConfig, function (config, view) {
if (config.template === 'dashboard') {
dashboardConfig[view] = config;
}
});
}]);
}]);

View File

@ -9,22 +9,16 @@ angular.module('bansho.view.singleTable', ['ngRoute',
.value('singleTableConfig', {})
.controller('SingleTableCtrl', ['$scope', '$routeParams', 'singleTableConfig', 'TableConfigObj',
function ($scope, $routeParams, singleTableConfig, TableConfigObj) {
.controller('SingleTableCtrl', ['$scope', '$routeParams', 'singleTableConfig', 'TableConfigObj', 'configManager',
function ($scope, $routeParams, singleTableConfig, TableConfigObj, configManager) {
var viewName = $scope.viewName;
if (jQuery.isEmptyObject(singleTableConfig)) {
configManager.loadByTemplate('single_table', singleTableConfig);
}
$scope.tableConfig = new TableConfigObj(singleTableConfig[viewName].components[0].config);
$scope.singleTableTitle = singleTableConfig[viewName].title;
$scope.singleTableRefreshInterval = singleTableConfig[viewName].refreshInterval;
}])
.run(['readConfig', 'singleTableConfig', function (readConfig, singleTableConfig) {
var viewsConfig = readConfig.data;
angular.forEach(viewsConfig, function (config, view) {
if (config.template === 'single_table') {
singleTableConfig[view] = config;
}
});
}]);
}]);