mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ShareModal: Added template variables to share url, and an option for it, #864
This commit is contained in:
parent
285d246c65
commit
c41aa64719
@ -62,6 +62,7 @@ function (angular, _, config, $) {
|
||||
};
|
||||
|
||||
$scope.goToDashboard = function(id) {
|
||||
$location.search({});
|
||||
$location.path("/dashboard/db/" + id);
|
||||
};
|
||||
|
||||
|
@ -7,12 +7,13 @@ function (angular, _) {
|
||||
|
||||
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.editor = { index: 0 };
|
||||
$scope.forCurrent = true;
|
||||
$scope.toPanel = true;
|
||||
$scope.includeTemplateVars = true;
|
||||
|
||||
$scope.buildUrl();
|
||||
};
|
||||
@ -27,7 +28,7 @@ function (angular, _) {
|
||||
|
||||
var panelId = $scope.panel.id;
|
||||
var range = timeSrv.timeRange(false);
|
||||
var params = $location.search();
|
||||
var params = angular.copy($location.search());
|
||||
|
||||
if (_.isString(range.to) && range.to.indexOf('now')) {
|
||||
range = timeSrv.timeRange();
|
||||
@ -39,6 +40,17 @@ function (angular, _) {
|
||||
if (_.isDate(params.from)) { params.from = params.from.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) {
|
||||
delete params.from;
|
||||
delete params.to;
|
||||
|
@ -17,8 +17,9 @@
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="editor-row">
|
||||
<editor-opt-bool name="currentTime" 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="Current time range" model="forCurrent" 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 class="editor-row" style="margin-top: 20px;">
|
||||
|
@ -51,6 +51,18 @@ define([
|
||||
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');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user