diff --git a/src/app/controllers/grafanaCtrl.js b/src/app/controllers/grafanaCtrl.js index c25742c7992..e54dbfe8280 100644 --- a/src/app/controllers/grafanaCtrl.js +++ b/src/app/controllers/grafanaCtrl.js @@ -78,17 +78,27 @@ function (angular, config, _, $) { $scope.initProfiling = function() { var count = 0; + console.log("registering digest counter"); + $scope.$watch(function() { console.log(1); count++; }, function() { }); - setTimeout(function() { - console.log("Dashboard::Performance Total Digests: " + count); - console.log("Dashboard::Performance Total Watchers: " + $scope.getTotalWatcherCount()); - console.log("Dashboard::Performance Total ScopeCount: " + $scope.performance.scopeCount); - }, 3000); + $scope.onAppEvent('setup-dashboard', function() { + count = 0; + + setTimeout(function() { + console.log("Dashboard::Performance Total Digests: " + count); + console.log("Dashboard::Performance Total Watchers: " + $scope.getTotalWatcherCount()); + console.log("Dashboard::Performance Total ScopeCount: " + $rootScope.performance.scopeCount); + + var timeTaken = $rootScope.performance.allPanelsInitialized - $rootScope.performance.dashboardLoadStart; + console.log("Dashboard::Performance - All panels initialized in " + timeTaken + " ms"); + }, 3000); + + }); }; diff --git a/src/app/directives/grafanaPanel.js b/src/app/directives/grafanaPanel.js index bba6d10e6da..b2d9c1d46a7 100644 --- a/src/app/directives/grafanaPanel.js +++ b/src/app/directives/grafanaPanel.js @@ -8,7 +8,7 @@ function (angular, $) { angular .module('grafana.directives') - .directive('grafanaPanel', function($compile) { + .directive('grafanaPanel', function($compile, $parse) { var container = '
'; var content = '
'; @@ -51,8 +51,7 @@ function (angular, $) { return { restrict: 'E', link: function($scope, elem, attr) { - // once we have the template, scan it for controllers and - // load the module.js if we have any + var getter = $parse(attr.type), panelType = getter($scope); var newScope = $scope.$new(); $scope.kbnJqUiDraggableOptions = { @@ -77,31 +76,17 @@ function (angular, $) { elem.remove(); }); - $scope.$watch(attr.type, function (name) { - elem.addClass("ng-cloak"); - // load the panels module file, then render it in the dom. - var nameAsPath = name.replace(".", "/"); - $scope.require([ - 'jquery', - 'text!panels/'+nameAsPath+'/module.html' - ], function ($, moduleTemplate) { - var $module = $(moduleTemplate); - // top level controllers - var $controllers = $module.filter('ngcontroller, [ng-controller], .ng-controller'); - // add child controllers - $controllers = $controllers.add($module.find('ngcontroller, [ng-controller], .ng-controller')); + elem.addClass('ng-cloak'); - if ($controllers.length) { - $controllers.first().prepend(panelHeader); - $controllers.first().find('.panel-header').nextAll().wrapAll(content); - - $scope.require(['panels/' + nameAsPath + '/module'], function() { - loadModule($module); - }); - } else { - loadModule($module); - } - }); + $scope.require([ + 'jquery', + 'text!panels/'+panelType+'/module.html', + 'panels/' + panelType + "/module", + ], function ($, moduleTemplate) { + var $module = $(moduleTemplate); + $module.prepend(panelHeader); + $module.first().find('.panel-header').nextAll().wrapAll(content); + loadModule($module); }); } diff --git a/src/app/services/panelSrv.js b/src/app/services/panelSrv.js index 78eab13798d..3c362818f2d 100644 --- a/src/app/services/panelSrv.js +++ b/src/app/services/panelSrv.js @@ -133,8 +133,7 @@ function (angular, _) { if ($rootScope.profilingEnabled) { $rootScope.performance.panelsInitialized++; if ($rootScope.performance.panelsInitialized === $scope.dashboard.rows.length) { - var timeTaken = new Date().getTime() - $scope.performance.dashboardLoadStart; - console.log("Dashboard::Performance - All panels initialized in " + timeTaken + " ms"); + $rootScope.performance.allPanelsInitialized = new Date().getTime(); } } };