From 741a1736a490804201786e7492aa4996742b4fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 17 Mar 2015 16:04:08 -0400 Subject: [PATCH] can handle updates --- .../features/dashboard/dynamicDashboardSrv.js | 20 +++++++++++++++++++ src/app/features/dashboard/submenuCtrl.js | 7 +++++-- .../features/templating/templateValuesSrv.js | 17 +++++----------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/app/features/dashboard/dynamicDashboardSrv.js b/src/app/features/dashboard/dynamicDashboardSrv.js index c8bfd74c895..8af85bc0aba 100644 --- a/src/app/features/dashboard/dynamicDashboardSrv.js +++ b/src/app/features/dashboard/dynamicDashboardSrv.js @@ -13,6 +13,25 @@ function (angular, _) { this.handlePanelRepeats(dashboard); }; + this.update = function(dashboard) { + this.removeLinkedPanels(dashboard); + this.handlePanelRepeats(dashboard); + }; + + this.removeLinkedPanels = function(dashboard) { + var i, j, row, panel; + for (i = 0; i < dashboard.rows.length; i++) { + row = dashboard.rows[i]; + for (j = 0; j < row.panels.length; j++) { + panel = row.panels[j]; + if (panel.linked) { + row.panels = _.without(row.panels, panel); + j = j - 1; + } + } + } + }; + this.handlePanelRepeats = function(dashboard) { var i, j, row, panel; for (i = 0; i < dashboard.rows.length; i++) { @@ -37,6 +56,7 @@ function (angular, _) { if (index > 0) { var copy = dashboard.duplicatePanel(panel, row); copy.repeat = null; + copy.linked = true; copy.scopedVars = {}; copy.scopedVars[variable.name] = option; } else { diff --git a/src/app/features/dashboard/submenuCtrl.js b/src/app/features/dashboard/submenuCtrl.js index 456cc1b76c1..cca0c9c731a 100644 --- a/src/app/features/dashboard/submenuCtrl.js +++ b/src/app/features/dashboard/submenuCtrl.js @@ -7,7 +7,7 @@ function (angular, _) { var module = angular.module('grafana.controllers'); - module.controller('SubmenuCtrl', function($scope, $q, $rootScope, templateValuesSrv) { + module.controller('SubmenuCtrl', function($scope, $q, $rootScope, templateValuesSrv, dynamicDashboardSrv) { var _d = { enable: true }; @@ -27,7 +27,10 @@ function (angular, _) { }; $scope.setVariableValue = function(param, option) { - templateValuesSrv.setVariableValue(param, option); + templateValuesSrv.setVariableValue(param, option).then(function() { + dynamicDashboardSrv.update($scope.dashboard); + $rootScope.$broadcast('refresh'); + }); }; $scope.init(); diff --git a/src/app/features/templating/templateValuesSrv.js b/src/app/features/templating/templateValuesSrv.js index 73bcfb662bd..63a7a863272 100644 --- a/src/app/features/templating/templateValuesSrv.js +++ b/src/app/features/templating/templateValuesSrv.js @@ -32,7 +32,7 @@ function (angular, _, kbn) { var option = _.findWhere(variable.options, { text: urlValue }); option = option || { text: urlValue, value: urlValue }; - var promise = this.setVariableValue(variable, option, true); + var promise = this.setVariableValue(variable, option); this.updateAutoInterval(variable); promises.push(promise); @@ -60,17 +60,10 @@ function (angular, _, kbn) { templateSrv.setGrafanaVariable('$__auto_interval', interval); }; - this.setVariableValue = function(variable, option, recursive) { + this.setVariableValue = function(variable, option) { variable.current = option; - templateSrv.updateTemplateData(); - - return this.updateOptionsInChildVariables(variable) - .then(function() { - if (!recursive) { - $rootScope.$broadcast('refresh'); - } - }); + return this.updateOptionsInChildVariables(variable); }; this.updateOptionsInChildVariables = function(updatedVariable) { @@ -117,11 +110,11 @@ function (angular, _, kbn) { if (variable.current) { var currentOption = _.findWhere(variable.options, { text: variable.current.text }); if (currentOption) { - return self.setVariableValue(variable, currentOption, true); + return self.setVariableValue(variable, currentOption); } } - return self.setVariableValue(variable, variable.options[0], true); + return self.setVariableValue(variable, variable.options[0]); }); }); };