Commit e5280d55 by Torkel Ödegaard

Make template variables work in row titles, #1956

parent 3675b3fc
......@@ -105,6 +105,8 @@ function (angular, _) {
_.each(selected, function(option, index) {
copy = self.getRowClone(row, index);
copy.scopedVars = {};
copy.scopedVars[variable.name] = option;
for (i = 0; i < copy.panels.length; i++) {
panel = copy.panels[i];
......
......@@ -22,7 +22,6 @@ function (angular, app, _, config) {
$scope.init = function() {
$scope.editor = {index: 0};
$scope.reset_panel();
};
$scope.togglePanelMenu = function(posX) {
......@@ -64,8 +63,18 @@ function (angular, app, _, config) {
};
$scope.add_panel_default = function(type) {
$scope.reset_panel(type);
$scope.add_panel($scope.panel);
var defaultSpan = 12;
var _as = 12 - $scope.dashboard.rowSpan($scope.row);
var panel = {
title: config.new_panel_title,
error: false,
span: _as < defaultSpan && _as > 0 ? _as : defaultSpan,
editable: true,
type: type
};
$scope.add_panel(panel);
$timeout(function() {
$scope.$broadcast('render');
......@@ -105,31 +114,6 @@ function (angular, app, _, config) {
});
};
$scope.reset_panel = function(type) {
var defaultSpan = 12;
var _as = 12 - $scope.dashboard.rowSpan($scope.row);
$scope.panel = {
title: config.new_panel_title,
error: false,
span: _as < defaultSpan && _as > 0 ? _as : defaultSpan,
editable: true,
type: type
};
function fixRowHeight(height) {
if (!height) {
return '200px';
}
if (!_.isString(height)) {
return height + 'px';
}
return height;
}
$scope.row.height = fixRowHeight($scope.row.height);
};
$scope.init();
});
......
......@@ -57,7 +57,11 @@ define(['angular', 'jquery', 'lodash', 'moment'], function (angular, $, _, momen
module.filter('interpolateTemplateVars', function(templateSrv) {
function interpolateTemplateVars(text, scope) {
if (scope.panel) {
return templateSrv.replaceWithText(text, scope.panel.scopedVars);
} else {
return templateSrv.replaceWithText(text, scope.row.scopedVars);
}
}
interpolateTemplateVars.$stateful = true;
......
......@@ -75,7 +75,7 @@
</div>
<div class="panels-wrapper" ng-if="!row.collapse">
<div class="row-text pointer" ng-click="toggle_row(row)" ng-if="row.showTitle" ng-bind="row.title">
<div class="row-text pointer" ng-click="toggle_row(row)" ng-if="row.showTitle" ng-bind="row.title | interpolateTemplateVars:this">
</div>
<!-- Panels, draggable needs to be disabled in fullscreen because Firefox bug -->
......
......@@ -135,6 +135,11 @@ define([
expect(ctx.rows[1].repeat).to.be(null);
});
it('should add scopedVars to rows', function() {
expect(ctx.rows[0].scopedVars.servers.value).to.be('se1');
expect(ctx.rows[1].scopedVars.servers.value).to.be('se2');
});
it('should generate a repeartRowId based on repeat row index', function() {
expect(ctx.rows[1].repeatRowId).to.be(1);
});
......
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