From 5de499c7f628903b069df69e83e0e693080f1498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 17 Mar 2015 12:30:42 -0400 Subject: [PATCH] Working on panel repeat --- src/app/features/dashboard/dynamicDashboardSrv.js | 6 ++++++ src/app/features/panel/panelHelper.js | 1 + src/app/features/templating/templateSrv.js | 7 ++++++- src/app/plugins/datasource/graphite/datasource.js | 6 +++--- src/test/specs/templateSrv-specs.js | 12 ++++++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/app/features/dashboard/dynamicDashboardSrv.js b/src/app/features/dashboard/dynamicDashboardSrv.js index 0c54b61419a..446b7c96392 100644 --- a/src/app/features/dashboard/dynamicDashboardSrv.js +++ b/src/app/features/dashboard/dynamicDashboardSrv.js @@ -33,9 +33,15 @@ function (angular, _) { return; } + dashboard.scopedVars = { + panel: {} + }; + _.each(variable.options, function(option) { var copy = dashboard.duplicatePanel(panel, row); copy.repeat = null; + dashboard.scopedVars.panel[panel.id] = {}; + dashboard.scopedVars.panel[panel.id][variable.name] = option.value; console.log('duplicatePanel'); }); }; diff --git a/src/app/features/panel/panelHelper.js b/src/app/features/panel/panelHelper.js index c2842fb225e..2f90615fac6 100644 --- a/src/app/features/panel/panelHelper.js +++ b/src/app/features/panel/panelHelper.js @@ -8,6 +8,7 @@ function (angular, _, kbn, $) { 'use strict'; var module = angular.module('grafana.services'); + module.service('panelHelper', function(timeSrv) { this.updateTimeRange = function(scope) { diff --git a/src/app/features/templating/templateSrv.js b/src/app/features/templating/templateSrv.js index 8fc45097944..6e4a25f3580 100644 --- a/src/app/features/templating/templateSrv.js +++ b/src/app/features/templating/templateSrv.js @@ -63,13 +63,18 @@ function (angular, _) { }); }; - this.replace = function(target) { + this.replace = function(target, scopedVars) { if (!target) { return; } var value; this._regex.lastIndex = 0; return target.replace(this._regex, function(match, g1, g2) { + if (scopedVars) { + value = scopedVars[g1 || g2]; + if (value) { return value; } + } + value = self._values[g1 || g2]; if (!value) { return match; } diff --git a/src/app/plugins/datasource/graphite/datasource.js b/src/app/plugins/datasource/graphite/datasource.js index 37ce4356ee8..6e0ae3ebd97 100644 --- a/src/app/plugins/datasource/graphite/datasource.js +++ b/src/app/plugins/datasource/graphite/datasource.js @@ -36,7 +36,7 @@ function (angular, _, $, config, kbn, moment) { maxDataPoints: options.maxDataPoints, }; - var params = this.buildGraphiteParams(graphOptions); + var params = this.buildGraphiteParams(graphOptions, options.panelId); if (options.format === 'png') { return $q.when(this.url + '/render' + '?' + params.join('&')); @@ -231,7 +231,7 @@ function (angular, _, $, config, kbn, moment) { '#Y', '#Z' ]; - GraphiteDatasource.prototype.buildGraphiteParams = function(options) { + GraphiteDatasource.prototype.buildGraphiteParams = function(options, panelId) { var graphite_options = ['from', 'until', 'rawData', 'format', 'maxDataPoints', 'cacheTimeout']; var clean_options = [], targets = {}; var target, targetValue, i; @@ -252,7 +252,7 @@ function (angular, _, $, config, kbn, moment) { continue; } - targetValue = templateSrv.replace(target.target); + targetValue = templateSrv.replace(target.target, panelId); targetValue = targetValue.replace(intervalFormatFixRegex, fixIntervalFormat); targets[this._seriesRefLetters[i]] = targetValue; } diff --git a/src/test/specs/templateSrv-specs.js b/src/test/specs/templateSrv-specs.js index bb85b9a1c98..57e853d8a3f 100644 --- a/src/test/specs/templateSrv-specs.js +++ b/src/test/specs/templateSrv-specs.js @@ -29,6 +29,18 @@ define([ }); }); + describe('replace can pass scoped vars', function() { + beforeEach(function() { + _templateSrv.init([{ name: 'test', current: { value: 'oogle' } }]); + }); + + it('should replace $test with scoped value', function() { + var target = _templateSrv.replace('this.$test.filters', {'test': 'mupp'}); + expect(target).to.be('this.mupp.filters'); + }); + }); + + describe('can check if variable exists', function() { beforeEach(function() { _templateSrv.init([{ name: 'test', current: { value: 'oogle' } }]);