Commit c41aa647 by Torkel Ödegaard

ShareModal: Added template variables to share url, and an option for it, #864

parent 285d246c
...@@ -62,6 +62,7 @@ function (angular, _, config, $) { ...@@ -62,6 +62,7 @@ function (angular, _, config, $) {
}; };
$scope.goToDashboard = function(id) { $scope.goToDashboard = function(id) {
$location.search({});
$location.path("/dashboard/db/" + id); $location.path("/dashboard/db/" + id);
}; };
......
...@@ -7,12 +7,13 @@ function (angular, _) { ...@@ -7,12 +7,13 @@ function (angular, _) {
var module = angular.module('grafana.controllers'); var module = angular.module('grafana.controllers');
module.controller('SharePanelCtrl', function($scope, $location, $timeout, timeSrv, $element) { module.controller('SharePanelCtrl', function($scope, $location, $timeout, timeSrv, $element, templateSrv) {
$scope.init = function() { $scope.init = function() {
$scope.editor = { index: 0 }; $scope.editor = { index: 0 };
$scope.forCurrent = true; $scope.forCurrent = true;
$scope.toPanel = true; $scope.toPanel = true;
$scope.includeTemplateVars = true;
$scope.buildUrl(); $scope.buildUrl();
}; };
...@@ -27,7 +28,7 @@ function (angular, _) { ...@@ -27,7 +28,7 @@ function (angular, _) {
var panelId = $scope.panel.id; var panelId = $scope.panel.id;
var range = timeSrv.timeRange(false); var range = timeSrv.timeRange(false);
var params = $location.search(); var params = angular.copy($location.search());
if (_.isString(range.to) && range.to.indexOf('now')) { if (_.isString(range.to) && range.to.indexOf('now')) {
range = timeSrv.timeRange(); range = timeSrv.timeRange();
...@@ -39,6 +40,17 @@ function (angular, _) { ...@@ -39,6 +40,17 @@ function (angular, _) {
if (_.isDate(params.from)) { params.from = params.from.getTime(); } if (_.isDate(params.from)) { params.from = params.from.getTime(); }
if (_.isDate(params.to)) { params.to = params.to.getTime(); } if (_.isDate(params.to)) { params.to = params.to.getTime(); }
if ($scope.includeTemplateVars) {
_.each(templateSrv.variables, function(variable) {
params['var-' + variable.name] = variable.current.text;
});
}
else {
_.each(templateSrv.variables, function(variable) {
delete params['var-' + variable.name];
});
}
if (!$scope.forCurrent) { if (!$scope.forCurrent) {
delete params.from; delete params.from;
delete params.to; delete params.to;
......
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
<div class="modal-body"> <div class="modal-body">
<div class="editor-row"> <div class="editor-row">
<editor-opt-bool name="currentTime" text="Current time range" model="forCurrent" change="buildUrl()"></editor-opt-bool> <editor-opt-bool text="Current time range" model="forCurrent" change="buildUrl()"></editor-opt-bool>
<editor-opt-bool name="toPanel" text="To this panel only" model="toPanel" change="buildUrl()"></editor-opt-bool> <editor-opt-bool text="To this panel only" model="toPanel" change="buildUrl()"></editor-opt-bool>
<editor-opt-bool text="Include template variables" model="includeTemplateVars" change="buildUrl()"></editor-opt-bool>
</div> </div>
<div class="editor-row" style="margin-top: 20px;"> <div class="editor-row" style="margin-top: 20px;">
......
...@@ -51,6 +51,18 @@ define([ ...@@ -51,6 +51,18 @@ define([
expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now'); expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now');
}); });
it('should include template variables in url', function() {
ctx.$location.path('/test');
ctx.scope.panel = { id: 22 };
ctx.scope.includeTemplateVars = true;
ctx.scope.toPanel = false;
ctx.templateSrv.variables = [{ name: 'app', current: {text: 'mupp' }}, {name: 'server', current: {text: 'srv-01'}}];
ctx.timeSrv.time = { from: 'now-1h', to: 'now' };
ctx.scope.buildUrl();
expect(ctx.scope.shareUrl).to.be('http://server/#/test?from=now-1h&to=now&var-app=mupp&var-server=srv-01');
});
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment