diff --git a/src/app/controllers/dashboardCtrl.js b/src/app/controllers/dashboardCtrl.js
index 3f113ab3a8c..03cdddfbf7b 100644
--- a/src/app/controllers/dashboardCtrl.js
+++ b/src/app/controllers/dashboardCtrl.js
@@ -41,8 +41,6 @@ function (angular, $, config, _) {
};
$scope.setupDashboard = function(event, dashboardData) {
- timer.cancel_all();
-
$rootScope.performance.dashboardLoadStart = new Date().getTime();
$rootScope.performance.panelsInitialized = 0;
$rootScope.performance.panelsRendered= 0;
@@ -67,11 +65,6 @@ function (angular, $, config, _) {
window.document.title = config.window_title_prefix + $scope.dashboard.title;
- // start auto refresh
- if($scope.dashboard.refresh) {
- $scope.dashboard.set_interval($scope.dashboard.refresh);
- }
-
dashboardKeybindings.shortcuts($scope);
$scope.emitAppEvent("dashboard-loaded", $scope.dashboard);
diff --git a/src/app/controllers/submenuCtrl.js b/src/app/controllers/submenuCtrl.js
index edaab142eb3..dcc147d49d9 100644
--- a/src/app/controllers/submenuCtrl.js
+++ b/src/app/controllers/submenuCtrl.js
@@ -8,7 +8,7 @@ function (angular, app, _) {
var module = angular.module('grafana.controllers');
- module.controller('SubmenuCtrl', function($scope, $q, $rootScope, datasourceSrv) {
+ module.controller('SubmenuCtrl', function($scope, $q, $rootScope, templateValuesSrv) {
var _d = {
enable: true
};
@@ -18,62 +18,7 @@ function (angular, app, _) {
$scope.init = function() {
$scope.panel = $scope.pulldown;
$scope.row = $scope.pulldown;
- };
-
- $scope.filterOptionSelected = function(templateParameter, option, recursive) {
- templateParameter.current = option;
-
- $scope.filter.updateTemplateData();
-
- return $scope.applyFilterToOtherFilters(templateParameter)
- .then(function() {
- // only refresh in the outermost call
- if (!recursive) {
- $scope.dashboard.emit_refresh();
- }
- });
- };
-
- $scope.applyFilterToOtherFilters = function(updatedTemplatedParam) {
- var promises = _.map($scope.filter.templateParameters, function(templateParam) {
- if (templateParam === updatedTemplatedParam) {
- return;
- }
- if (templateParam.query.indexOf('[[' + updatedTemplatedParam.name + ']]') !== -1) {
- return $scope.applyFilter(templateParam);
- }
- });
-
- return $q.all(promises);
- };
-
- $scope.applyFilter = function(templateParam) {
- return datasourceSrv.default.metricFindQuery($scope.filter, templateParam.query)
- .then(function (results) {
- templateParam.options = _.map(results, function(node) {
- return { text: node.text, value: node.text };
- });
-
- if (templateParam.includeAll) {
- var allExpr = '{';
- _.each(templateParam.options, function(option) {
- allExpr += option.text + ',';
- });
- allExpr = allExpr.substring(0, allExpr.length - 1) + '}';
- templateParam.options.unshift({text: 'All', value: allExpr});
- }
-
- // if parameter has current value
- // if it exists in options array keep value
- if (templateParam.current) {
- var currentExists = _.findWhere(templateParam.options, { value: templateParam.current.value });
- if (currentExists) {
- return $scope.filterOptionSelected(templateParam, templateParam.current, true);
- }
- }
-
- return $scope.filterOptionSelected(templateParam, templateParam.options[0], true);
- });
+ $scope.templateParameters = $scope.dashboard.templating.list;
};
$scope.disableAnnotation = function (annotation) {
@@ -81,6 +26,10 @@ function (angular, app, _) {
$rootScope.$broadcast('refresh');
};
+ $scope.filterOptionSelected = function(param, option) {
+ templateValuesSrv.filterOptionSelected(param, option);
+ };
+
$scope.init();
});
diff --git a/src/app/panels/text/module.js b/src/app/panels/text/module.js
index c3aabba2804..e652b40a56b 100644
--- a/src/app/panels/text/module.js
+++ b/src/app/panels/text/module.js
@@ -12,7 +12,7 @@ function (angular, app, _, require) {
var converter;
- module.controller('text', function($scope, filterSrv, $sce, panelSrv) {
+ module.controller('text', function($scope, templateSrv, $sce, panelSrv) {
$scope.panelMeta = {
description : "A static text panel that can use plain text, markdown, or (sanitized) HTML"
@@ -75,7 +75,7 @@ function (angular, app, _, require) {
$scope.updateContent = function(html) {
try {
- $scope.content = $sce.trustAsHtml(filterSrv.applyTemplateToTarget(html));
+ $scope.content = $sce.trustAsHtml(templateSrv.replace(html));
} catch(e) {
console.log('Text panel error: ', e);
$scope.content = $sce.trustAsHtml(html);
diff --git a/src/app/panels/timepicker/module.html b/src/app/panels/timepicker/module.html
index 0eacee58d4b..8357f66a7a3 100644
--- a/src/app/panels/timepicker/module.html
+++ b/src/app/panels/timepicker/module.html
@@ -32,10 +32,10 @@
Auto-Refresh
@@ -44,7 +44,7 @@
diff --git a/src/app/panels/timepicker/module.js b/src/app/panels/timepicker/module.js
index 7dcd222e4cd..656af0898a0 100644
--- a/src/app/panels/timepicker/module.js
+++ b/src/app/panels/timepicker/module.js
@@ -25,7 +25,7 @@ function (angular, app, _, moment, kbn) {
var module = angular.module('grafana.panels.timepicker', []);
app.useModule(module);
- module.controller('timepicker', function($scope, timeSrv) {
+ module.controller('timepicker', function($scope, $rootScope, timeSrv) {
$scope.panelMeta = {
status : "Stable",
@@ -50,6 +50,8 @@ function (angular, app, _, moment, kbn) {
millisecond: /^[0-9]*$/
};
+ $scope.timeSrv = timeSrv;
+
$scope.$on('refresh', function() {
$scope.init();
});
diff --git a/src/app/partials/submenu.html b/src/app/partials/submenu.html
index 4d9d6b10125..2d5c3e1831d 100644
--- a/src/app/partials/submenu.html
+++ b/src/app/partials/submenu.html
@@ -18,7 +18,7 @@
- -
+
-
{{param.name}}:
diff --git a/src/app/services/all.js b/src/app/services/all.js
index 1f515f4df49..81fe4603277 100644
--- a/src/app/services/all.js
+++ b/src/app/services/all.js
@@ -3,6 +3,7 @@ define([
'./datasourceSrv',
'./timeSrv',
'./templateSrv',
+ './templateValuesSrv',
'./panelSrv',
'./timer',
'./panelMove',
diff --git a/src/app/services/dashboard/dashboardSrv.js b/src/app/services/dashboard/dashboardSrv.js
index 9677409f5fa..e88092a4c16 100644
--- a/src/app/services/dashboard/dashboardSrv.js
+++ b/src/app/services/dashboard/dashboardSrv.js
@@ -11,7 +11,7 @@ function (angular, $, kbn, _, moment) {
var module = angular.module('grafana.services');
- module.factory('dashboardSrv', function(timer, $rootScope, $timeout) {
+ module.factory('dashboardSrv', function($rootScope) {
function DashboardModel (data) {
@@ -115,28 +115,6 @@ function (angular, $, kbn, _, moment) {
$rootScope.$broadcast('refresh');
};
- p.start_scheduled_refresh = function (after_ms) {
- this.cancel_scheduled_refresh();
- this.refresh_timer = timer.register($timeout(function () {
- this.start_scheduled_refresh(after_ms);
- this.emit_refresh();
- }.bind(this), after_ms));
- };
-
- p.cancel_scheduled_refresh = function () {
- timer.cancel(this.refresh_timer);
- };
-
- p.set_interval = function (interval) {
- this.refresh = interval;
- if (interval) {
- var _i = kbn.interval_to_ms(interval);
- this.start_scheduled_refresh(_i);
- } else {
- this.cancel_scheduled_refresh();
- }
- };
-
p.updateSchema = function(old) {
var oldVersion = this.version;
var panelUpgrades = [];
diff --git a/src/app/services/graphite/graphiteDatasource.js b/src/app/services/graphite/graphiteDatasource.js
index 061813bfe3f..f7c217d30d0 100644
--- a/src/app/services/graphite/graphiteDatasource.js
+++ b/src/app/services/graphite/graphiteDatasource.js
@@ -11,7 +11,7 @@ function (angular, _, $, config, kbn, moment) {
var module = angular.module('grafana.services');
- module.factory('GraphiteDatasource', function($q, $http, timeSrv) {
+ module.factory('GraphiteDatasource', function($q, $http, templateSrv) {
function GraphiteDatasource(datasource) {
this.type = 'graphite';
@@ -63,7 +63,7 @@ function (angular, _, $, config, kbn, moment) {
GraphiteDatasource.prototype.annotationQuery = function(annotation, rangeUnparsed) {
// Graphite metric as annotation
if (annotation.target) {
- var target = timeSrv.applyTemplateToTarget(annotation.target);
+ var target = templateSrv.replace(annotation.target);
var graphiteQuery = {
range: rangeUnparsed,
targets: [{ target: target }],
@@ -71,7 +71,7 @@ function (angular, _, $, config, kbn, moment) {
maxDataPoints: 100
};
- return this.query(timeSrv, graphiteQuery)
+ return this.query(graphiteQuery)
.then(function(result) {
var list = [];
@@ -95,7 +95,7 @@ function (angular, _, $, config, kbn, moment) {
}
// Graphite event as annotation
else {
- var tags = timeSrv.applyTemplateToTarget(annotation.tags);
+ var tags = templateSrv.replace(annotation.tags);
return this.events({ range: rangeUnparsed, tags: tags })
.then(function(results) {
var list = [];
@@ -169,7 +169,7 @@ function (angular, _, $, config, kbn, moment) {
GraphiteDatasource.prototype.metricFindQuery = function(query) {
var interpolated;
try {
- interpolated = encodeURIComponent(timeSrv.applyTemplateToTarget(query));
+ interpolated = encodeURIComponent(templateSrv.replace(query));
}
catch(err) {
return $q.reject(err);
@@ -226,7 +226,7 @@ function (angular, _, $, config, kbn, moment) {
if (key === "targets") {
_.each(value, function (value) {
if (value.target && !value.hide) {
- var targetValue = timeSrv.applyTemplateToTarget(value.target);
+ var targetValue = templateSrv.replace(value.target);
clean_options.push("target=" + encodeURIComponent(targetValue));
}
}, this);
diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js
index 8dcff41bc62..ae2a223602e 100644
--- a/src/app/services/influxdb/influxdbDatasource.js
+++ b/src/app/services/influxdb/influxdbDatasource.js
@@ -9,7 +9,7 @@ function (angular, _, kbn, InfluxSeries) {
var module = angular.module('grafana.services');
- module.factory('InfluxDatasource', function($q, $http, timeSrv) {
+ module.factory('InfluxDatasource', function($q, $http, templateSrv) {
function InfluxDatasource(datasource) {
this.type = 'influxDB';
@@ -73,7 +73,7 @@ function (angular, _, kbn, InfluxSeries) {
}
query = queryElements.join(" ");
- query = timeSrv.applyTemplateToTarget(query);
+ query = templateSrv.replace(query);
}
else {
@@ -100,7 +100,7 @@ function (angular, _, kbn, InfluxSeries) {
}
query = _.template(template, templateData, this.templateSettings);
- query = timeSrv.applyTemplateToTarget(query);
+ query = templateSrv.replace(query);
if (target.groupby_field_add) {
groupByField = target.groupby_field;
@@ -110,7 +110,7 @@ function (angular, _, kbn, InfluxSeries) {
}
if (target.alias) {
- alias = filterSrv.applyTemplateToTarget(target.alias);
+ alias = templateSrv.replace(target.alias);
}
var handleResponse = _.partial(handleInfluxQueryResponse, alias, groupByField);
@@ -164,7 +164,7 @@ function (angular, _, kbn, InfluxSeries) {
InfluxDatasource.prototype.metricFindQuery = function (filterSrv, query) {
var interpolated;
try {
- interpolated = filterSrv.applyTemplateToTarget(query);
+ interpolated = templateSrv.replace(query);
}
catch (err) {
return $q.reject(err);
diff --git a/src/app/services/panelSrv.js b/src/app/services/panelSrv.js
index 3c362818f2d..fd0c732f43b 100644
--- a/src/app/services/panelSrv.js
+++ b/src/app/services/panelSrv.js
@@ -129,13 +129,6 @@ function (angular, _) {
$scope.get_data();
}
}
-
- if ($rootScope.profilingEnabled) {
- $rootScope.performance.panelsInitialized++;
- if ($rootScope.performance.panelsInitialized === $scope.dashboard.rows.length) {
- $rootScope.performance.allPanelsInitialized = new Date().getTime();
- }
- }
};
});
diff --git a/src/app/services/templateSrv.js b/src/app/services/templateSrv.js
index 7165f4442ba..5958cfeae6a 100644
--- a/src/app/services/templateSrv.js
+++ b/src/app/services/templateSrv.js
@@ -4,16 +4,48 @@ define([
'kbn',
'store'
],
-function (angular) {
+function (angular, _) {
'use strict';
var module = angular.module('grafana.services');
- module.service('templateSrv', function() {
+ module.service('templateSrv', function($q, $routeParams) {
this.init = function(dashboard) {
this.dashboard = dashboard;
+ this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
+ this.templateParameters = dashboard.templating.list;
+ this.updateTemplateData(true);
+ };
+ this.updateTemplateData = function(initial) {
+ var _templateData = {};
+ _.each(this.templateParameters, function(templateParameter) {
+ if (initial) {
+ var urlValue = $routeParams[ templateParameter.name ];
+ if (urlValue) {
+ templateParameter.current = { text: urlValue, value: urlValue };
+ }
+ }
+ if (!templateParameter.current || !templateParameter.current.value) {
+ return;
+ }
+ _templateData[templateParameter.name] = templateParameter.current.value;
+ });
+ this._templateData = _templateData;
+ };
+
+ this.addTemplateParameter = function(templateParameter) {
+ this.templateParameters.push(templateParameter);
+ this.updateTemplateData();
+ };
+
+ this.replace = function(target) {
+ if (!target || target.indexOf('[[') === -1) {
+ return target;
+ }
+
+ return _.template(target, this._templateData, this.templateSettings);
};
});
diff --git a/src/app/services/templateValuesSrv.js b/src/app/services/templateValuesSrv.js
new file mode 100644
index 00000000000..0b6c4f20edf
--- /dev/null
+++ b/src/app/services/templateValuesSrv.js
@@ -0,0 +1,72 @@
+define([
+ 'angular',
+ 'lodash',
+ 'kbn',
+ 'store'
+],
+function (angular, _) {
+ 'use strict';
+
+ var module = angular.module('grafana.services');
+
+ module.service('templateValuesSrv', function($q, $rootScope, datasourceSrv, $routeParams, templateSrv) {
+ var self = this;
+
+ this.filterOptionSelected = function(templateParameter, option, recursive) {
+ templateParameter.current = option;
+
+ templateSrv.updateTemplateData();
+
+ return this.applyFilterToOtherFilters(templateParameter)
+ .then(function() {
+ if (!recursive) {
+ $rootScope.$broadcast('refresh');
+ }
+ });
+ };
+
+ this.applyFilterToOtherFilters = function(updatedTemplatedParam) {
+ var promises = _.map(self.templateParameters, function(templateParam) {
+ if (templateParam === updatedTemplatedParam) {
+ return;
+ }
+ if (templateParam.query.indexOf('[[' + updatedTemplatedParam.name + ']]') !== -1) {
+ return self.applyFilter(templateParam);
+ }
+ });
+
+ return $q.all(promises);
+ };
+
+ this.applyFilter = function(templateParam) {
+ return datasourceSrv.default.metricFindQuery(templateParam.query)
+ .then(function (results) {
+ templateParam.options = _.map(results, function(node) {
+ return { text: node.text, value: node.text };
+ });
+
+ if (templateParam.includeAll) {
+ var allExpr = '{';
+ _.each(templateParam.options, function(option) {
+ allExpr += option.text + ',';
+ });
+ allExpr = allExpr.substring(0, allExpr.length - 1) + '}';
+ templateParam.options.unshift({text: 'All', value: allExpr});
+ }
+
+ // if parameter has current value
+ // if it exists in options array keep value
+ if (templateParam.current) {
+ var currentExists = _.findWhere(templateParam.options, { value: templateParam.current.value });
+ if (currentExists) {
+ return self.filterOptionSelected(templateParam, templateParam.current, true);
+ }
+ }
+
+ return self.filterOptionSelected(templateParam, templateParam.options[0], true);
+ });
+ };
+
+ });
+
+});
diff --git a/src/app/services/timeSrv.js b/src/app/services/timeSrv.js
index 34c98ecefb8..d560956f90f 100644
--- a/src/app/services/timeSrv.js
+++ b/src/app/services/timeSrv.js
@@ -8,82 +8,82 @@ define([
var module = angular.module('grafana.services');
- module.service('timeSrv', function($rootScope, $timeout, $routeParams) {
+ module.service('timeSrv', function($rootScope, $timeout, timer) {
+ var self = this;
this.init = function(dashboard) {
- this.dashboard = dashboard;
- this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g };
- this.time = dashboard.time;
- this.templateParameters = dashboard.templating.list;
- this.updateTemplateData(true);
+ timer.cancel_all();
+
+ this.dashboard = dashboard;
+ this.time = dashboard.time;
+
+ if(this.dashboard.refresh) {
+ this.set_interval(this.dashboard.refresh);
+ }
};
- this.updateTemplateData = function(initial) {
- var _templateData = {};
- _.each(this.templateParameters, function(templateParameter) {
- if (initial) {
- var urlValue = $routeParams[ templateParameter.name ];
- if (urlValue) {
- templateParameter.current = { text: urlValue, value: urlValue };
- }
- }
- if (!templateParameter.current || !templateParameter.current.value) {
- return;
- }
- _templateData[templateParameter.name] = templateParameter.current.value;
- });
- this._templateData = _templateData;
- };
+ this.set_interval = function (interval) {
+ this.dashboard.refresh = interval;
+ if (interval) {
+ var _i = kbn.interval_to_ms(interval);
+ this.start_scheduled_refresh(_i);
+ } else {
+ this.cancel_scheduled_refresh();
+ }
+ };
- this.addTemplateParameter = function(templateParameter) {
- this.templateParameters.push(templateParameter);
- this.updateTemplateData();
- };
+ this.refreshDashboard = function() {
+ $rootScope.$broadcast('refresh');
+ };
- this.applyTemplateToTarget = function(target) {
- if (!target || target.indexOf('[[') === -1) {
- return target;
- }
+ this.start_scheduled_refresh = function (after_ms) {
+ self.cancel_scheduled_refresh();
+ self.refresh_timer = timer.register($timeout(function () {
+ self.start_scheduled_refresh(after_ms);
+ self.refreshDashboard();
+ }, after_ms));
+ };
- return _.template(target, this._templateData, this.templateSettings);
- };
+ this.cancel_scheduled_refresh = function () {
+ timer.cancel(this.refresh_timer);
+ };
- this.setTime = function(time) {
- _.extend(this.time, time);
+ this.setTime = function(time) {
+ _.extend(this.time, time);
- // disable refresh if we have an absolute time
- if (time.to !== 'now') {
- this.old_refresh = this.dashboard.refresh;
- this.dashboard.set_interval(false);
- }
- else if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) {
- this.dashboard.set_interval(this.old_refresh);
- this.old_refresh = null;
- }
+ // disable refresh if we have an absolute time
+ if (time.to !== 'now') {
+ this.old_refresh = this.dashboard.refresh;
+ this.set_interval(false);
+ }
+ else if (this.old_refresh && this.old_refresh !== this.dashboard.refresh) {
+ this.set_interval(this.old_refresh);
+ this.old_refresh = null;
+ }
- $timeout(this.dashboard.emit_refresh, 0);
- };
+ $timeout(this.refreshDashboard, 0);
+ };
- this.timeRange = function(parse) {
- var _t = this.time;
- if(_.isUndefined(_t) || _.isUndefined(_t.from)) {
- return false;
- }
- if(parse === false) {
- return {
- from: _t.from,
- to: _t.to
- };
- } else {
- var _from = _t.from;
- var _to = _t.to || new Date();
+ this.timeRange = function(parse) {
+ var _t = this.time;
+ if(_.isUndefined(_t) || _.isUndefined(_t.from)) {
+ return false;
+ }
+ if(parse === false) {
+ return {
+ from: _t.from,
+ to: _t.to
+ };
+ } else {
+ var _from = _t.from;
+ var _to = _t.to || new Date();
- return {
- from : kbn.parseDate(_from),
- to : kbn.parseDate(_to)
- };
- }
- };
+ return {
+ from: kbn.parseDate(_from),
+ to: kbn.parseDate(_to)
+ };
+ }
+ };
});
diff --git a/src/test/mocks/dashboard-mock.js b/src/test/mocks/dashboard-mock.js
index 7ec0e5e9997..6367093bd36 100644
--- a/src/test/mocks/dashboard-mock.js
+++ b/src/test/mocks/dashboard-mock.js
@@ -5,9 +5,6 @@ define([],
return {
create: function() {
return {
- emit_refresh: function() {},
- set_interval: function(value) { this.refresh = value; },
-
title: "",
tags: [],
style: "dark",
@@ -18,11 +15,11 @@ define([],
rows: [],
pulldowns: [ { type: 'templating' }, { type: 'annotations' } ],
nav: [ { type: 'timepicker' } ],
- time: {},
+ time: {from: '1h', to: 'now'},
templating: {
list: []
},
- refresh: true
+ refresh: '10s',
};
}
};
diff --git a/src/test/specs/helpers.js b/src/test/specs/helpers.js
index 5012f75dbe6..bdc358d009d 100644
--- a/src/test/specs/helpers.js
+++ b/src/test/specs/helpers.js
@@ -73,7 +73,7 @@ define([
};
};
- this.applyTemplateToTarget = function(target) {
+ this.replace = function(target) {
return target;
};
}
diff --git a/src/test/specs/templateSrv-specs.js b/src/test/specs/templateSrv-specs.js
new file mode 100644
index 00000000000..e57ce40fa3e
--- /dev/null
+++ b/src/test/specs/templateSrv-specs.js
@@ -0,0 +1,55 @@
+define([
+ 'mocks/dashboard-mock',
+ 'lodash',
+ 'services/templateSrv'
+], function(dashboardMock) {
+ 'use strict';
+
+ describe('templateSrv', function() {
+ var _templateSrv;
+ var _dashboard;
+
+ beforeEach(module('grafana.services'));
+ beforeEach(module(function() {
+ _dashboard = dashboardMock.create();
+ }));
+
+ beforeEach(inject(function(templateSrv) {
+ _templateSrv = templateSrv;
+ }));
+
+ beforeEach(function() {
+ _templateSrv.init(_dashboard);
+ });
+
+ describe('init', function() {
+ beforeEach(function() {
+ _templateSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } });
+ });
+
+ it('should initialize template data', function() {
+ var target = _templateSrv.replace('this.[[test]].filters');
+ expect(target).to.be('this.oogle.filters');
+ });
+ });
+
+ describe('updateTemplateData', function() {
+ beforeEach(function() {
+ _templateSrv.addTemplateParameter({
+ name: 'test',
+ value: 'muuu',
+ current: { value: 'muuuu' }
+ });
+
+ _templateSrv.updateTemplateData();
+ });
+
+ it('should set current value and update template data', function() {
+ var target = _templateSrv.replace('this.[[test]].filters');
+ expect(target).to.be('this.muuuu.filters');
+ });
+ });
+
+ });
+
+});
diff --git a/src/test/specs/timeSrv-specs.js b/src/test/specs/timeSrv-specs.js
index cc2c4b0f158..615656afcdf 100644
--- a/src/test/specs/timeSrv-specs.js
+++ b/src/test/specs/timeSrv-specs.js
@@ -10,45 +10,15 @@ define([
var _dashboard;
beforeEach(module('grafana.services'));
- beforeEach(module(function() {
- _dashboard = dashboardMock.create();
- }));
-
beforeEach(inject(function(timeSrv) {
_timeSrv = timeSrv;
+ _dashboard = dashboardMock.create();
}));
beforeEach(function() {
_timeSrv.init(_dashboard);
});
- describe('init', function() {
- beforeEach(function() {
- _timeSrv.addTemplateParameter({ name: 'test', current: { value: 'oogle' } });
- });
-
- it('should initialize template data', function() {
- var target = _timeSrv.applyTemplateToTarget('this.[[test]].filters');
- expect(target).to.be('this.oogle.filters');
- });
- });
-
- describe('updateTemplateData', function() {
- beforeEach(function() {
- _timeSrv.addTemplateParameter({
- name: 'test',
- value: 'muuu',
- current: { value: 'muuuu' }
- });
-
- _timeSrv.updateTemplateData();
- });
- it('should set current value and update template data', function() {
- var target = _timeSrv.applyTemplateToTarget('this.[[test]].filters');
- expect(target).to.be('this.muuuu.filters');
- });
- });
-
describe('timeRange', function() {
it('should return unparsed when parse is false', function() {
_timeSrv.setTime({from: 'now', to: 'now-1h' });
@@ -67,18 +37,18 @@ define([
describe('setTime', function() {
it('should return disable refresh for absolute times', function() {
- _dashboard.refresh = true;
+ _dashboard.refresh = false;
_timeSrv.setTime({from: '2011-01-01', to: '2015-01-01' });
expect(_dashboard.refresh).to.be(false);
});
it('should restore refresh after relative time range is set', function() {
- _dashboard.refresh = true;
+ _dashboard.refresh = '10s';
_timeSrv.setTime({from: '2011-01-01', to: '2015-01-01' });
expect(_dashboard.refresh).to.be(false);
_timeSrv.setTime({from: '2011-01-01', to: 'now' });
- expect(_dashboard.refresh).to.be(true);
+ expect(_dashboard.refresh).to.be('10s');
});
});
diff --git a/src/test/test-main.js b/src/test/test-main.js
index ed5a9cb3b63..dc477e9e2dc 100644
--- a/src/test/test-main.js
+++ b/src/test/test-main.js
@@ -126,6 +126,7 @@ require([
'specs/grafanaGraph-specs',
'specs/seriesOverridesCtrl-specs',
'specs/timeSrv-specs',
+ 'specs/templateSrv-specs',
'specs/kbn-format-specs',
'specs/dashboardSrv-specs',
'specs/dashboardViewStateSrv-specs',