Commit 939e957f by Torkel Ödegaard

Made regex match work for per series overrides, #425, #700

parent 062fe720
......@@ -183,6 +183,16 @@ function (angular, $, kbn, moment, _) {
}
}
function matchSeriesOverride(aliasOrRegex, seriesAlias) {
if (aliasOrRegex[0] === '/') {
var match = aliasOrRegex.match(new RegExp('^/(.*?)/(g?i?m?y?)$'));
var regex = new RegExp(match[1], match[2]);
return seriesAlias.match(regex) != null;
}
return aliasOrRegex === seriesAlias;
}
function applySeriesOverrideOptions(series) {
series.lines = {};
series.points = {};
......@@ -191,7 +201,7 @@ function (angular, $, kbn, moment, _) {
for (var i = 0; i < scope.panel.seriesOverrides.length; i++) {
var override = scope.panel.seriesOverrides[i];
if (override.alias !== series.info.alias) {
if (!matchSeriesOverride(override.alias, series.info.alias)) {
continue;
}
if (override.lines !== void 0) { series.lines.show = override.lines; }
......
......@@ -47,13 +47,13 @@ define([
$scope.updateCurrentOverrides = function() {
$scope.currentOverrides = [];
_.each($scope.overrideMenu, function(option) {
if (!_.isUndefined($scope.override[option.propertyName])) {
$scope.currentOverrides.push({
name: option.text,
propertyName: option.propertyName,
value: String($scope.override[option.propertyName])
});
}
var value = $scope.override[option.propertyName];
if (_.isUndefined(value)) { return; }
$scope.currentOverrides.push({
name: option.text,
propertyName: option.propertyName,
value: String(value)
});
});
};
......
......@@ -65,7 +65,7 @@
<div class="editor-row">
<div class="section">
<h5>Series specific overrides</h5>
<h5>Series specific overrides <tip>Regex match example: /server[0-3]/i </tip></h5>
<div class="grafana-target" ng-repeat="override in panel.seriesOverrides" ng-controller="SeriesOverridesCtrl">
<div class="grafana-target-inner-wrapper">
......
......@@ -143,7 +143,21 @@ define([
});
});
graphScenario('override match on regex', function(ctx) {
ctx.setup(function(scope, data) {
scope.panel.lines = true;
scope.panel.seriesOverrides = [
{ alias: '/.*01/', lines: false }
];
data[1].info.alias = 'test_01';
});
it('should match second series and set pointradius, and set steppedLine', function() {
expect(ctx.plotData[0].lines.show).to.be(undefined);
expect(ctx.plotData[1].lines.show).to.be(false);
});
});
});
});
......
......@@ -37,6 +37,14 @@ define([
});
});
describe('When removing overide', function() {
it('click should include option and value index', function() {
ctx.scope.setOverride(1,0);
ctx.scope.removeOverride({ propertyName: 'lines' });
expect(ctx.scope.currentOverrides.length).to.be(0);
});
});
});
});
......
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