diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index 5cd1353988c..dd9e13b5701 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -54,6 +54,13 @@ function (angular, _, config, gfunc, Parser) { checkOtherSegments($scope.segments.length - 1); } + function addFunctionParameter(func, value, index, shiftBack) { + if (shiftBack) { + index = Math.max(index - 1, 0); + } + func.params[index] = value; + } + function parseTargeRecursive(astNode, func, index) { if (astNode === null) { return null; @@ -72,29 +79,19 @@ function (angular, _, config, gfunc, Parser) { break; case 'series-ref': - if ($scope.segments.length === 0) { - func.params[index] = astNode.value; - } - else { - func.params[index - 1] = astNode.value; - } + addFunctionParameter(func, astNode.value, index, $scope.segments.length > 0); break; case 'string': case 'number': if ((index-1) >= func.def.params.length) { throw { message: 'invalid number of parameters to method ' + func.def.name }; } - - if (index === 0) { - func.params[index] = astNode.value; - } - else { - func.params[index - 1] = astNode.value; - } + addFunctionParameter(func, astNode.value, index, true); break; case 'metric': if ($scope.segments.length > 0) { - throw { message: 'Multiple metric params not supported, use text editor.' }; + addFunctionParameter(func, astNode.segments[0].value, index, true); + break; } $scope.segments = _.map(astNode.segments, function(segment) { diff --git a/src/app/services/graphite/gfunc.js b/src/app/services/graphite/gfunc.js index 1fc1402cf0c..4968384a24f 100644 --- a/src/app/services/graphite/gfunc.js +++ b/src/app/services/graphite/gfunc.js @@ -555,9 +555,6 @@ function (_) { if (strValue === '' && this.def.params[index].optional) { this.params.splice(index, 1); } - else if (this.def.params[index].type === 'int') { - this.params[index] = parseFloat(strValue, 10); - } else { this.params[index] = strValue; } diff --git a/src/app/services/templateSrv.js b/src/app/services/templateSrv.js index cf76dd5bfaa..907065e2fa6 100644 --- a/src/app/services/templateSrv.js +++ b/src/app/services/templateSrv.js @@ -47,7 +47,7 @@ function (angular, _) { }; this.highlightVariablesAsHtml = function(str) { - if (!str) { return str; } + if (!str || !_.isString(str)) { return str; } this.regex.lastIndex = 0; return str.replace(this.regex, function(match, g1, g2) { diff --git a/src/app/services/templateValuesSrv.js b/src/app/services/templateValuesSrv.js index a4e79c1ca34..2f6b1cd4e94 100644 --- a/src/app/services/templateValuesSrv.js +++ b/src/app/services/templateValuesSrv.js @@ -56,7 +56,7 @@ function (angular, _, kbn) { return { text: text, value: text }; }); self.setVariableValue(variable, variable.options[0]); - return; + return $q.when([]); } var datasource = datasourceSrv.get(variable.datasource); diff --git a/src/test/specs/gfunc-specs.js b/src/test/specs/gfunc-specs.js index 21f32e56113..e0714d8376f 100644 --- a/src/test/specs/gfunc-specs.js +++ b/src/test/specs/gfunc-specs.js @@ -85,7 +85,7 @@ define([ it('should parse numbers as float', function() { var func = gfunc.createFuncInstance('scale'); func.updateParam('0.001', 0); - expect(func.params[0]).to.be(0.001); + expect(func.params[0]).to.be('0.001'); }); }); @@ -93,14 +93,14 @@ define([ it('should update value and text', function() { var func = gfunc.createFuncInstance('aliasByNode'); func.updateParam('1', 0); - expect(func.params[0]).to.be(1); + expect(func.params[0]).to.be('1'); }); it('should slit text and put value in second param', function() { var func = gfunc.createFuncInstance('aliasByNode'); func.updateParam('4,-5', 0); - expect(func.params[0]).to.be(4); - expect(func.params[1]).to.be(-5); + expect(func.params[0]).to.be('4'); + expect(func.params[1]).to.be('-5'); expect(func.text).to.be('aliasByNode(4, -5)'); }); @@ -108,7 +108,7 @@ define([ var func = gfunc.createFuncInstance('aliasByNode'); func.updateParam('4,-5', 0); func.updateParam('', 1); - expect(func.params[0]).to.be(4); + expect(func.params[0]).to.be('4'); expect(func.params[1]).to.be(undefined); expect(func.text).to.be('aliasByNode(4)'); });