Commit 21ef0cdc by Torkel Ödegaard

refactoring graphite target editor

parent 76fa88cf
define([
'angular',
'underscore',
'config'
'config',
'/app/services/graphite/functions.js'
],
function (angular, _, config) {
function (angular, _, config, graphiteFunctions) {
'use strict';
var module = angular.module('kibana.controllers');
var funcDefs = [
{
name: "scaleToSeconds",
params: [ { name: "seconds", type: "int" } ],
defaultParams: [1]
},
{
name: "sumSeries",
params: [],
},
{
name: "groupByNode",
params: [
{
name: "node",
type: "node",
},
{
name: "function",
type: "function",
}
],
defaultParams: [3, "sumSeries"]
}
];
module.controller('GraphiteTargetCtrl', function($scope, $http) {
......@@ -43,7 +19,7 @@ function (angular, _, config) {
};
});
$scope.funcDefs = funcDefs;
$scope.funcDefs = graphiteFunctions;
$scope.functions = [];
};
......@@ -100,6 +76,19 @@ function (angular, _, config) {
return text;
}
function wrapFunction(target, func) {
var targetWrapped = func.def.name + '(' + target;
_.each(func.params, function(param) {
if (_.isString(param)) {
targetWrapped += ",'" + param + "'";
}
else {
targetWrapped += "," + param;
}
});
return targetWrapped + ')';
}
$scope.getAltSegments = function (index) {
$scope.altSegments = [];
......@@ -135,16 +124,21 @@ function (angular, _, config) {
};
$scope.targetChanged = function() {
$scope.target.target = getSegmentPathUpTo($scope.segments.length);
var target = getSegmentPathUpTo($scope.segments.length);
target = _.reduce($scope.functions, wrapFunction, target);
console.log('target: ', target);
$scope.target.target = target;
$scope.$parent.get_data();
};
$scope.removeFunction = function(func) {
$scope.functions = _.without($scope.functions, func);
$scope.targetChanged();
};
$scope.functionParamsChanged = function(func) {
func.text = getFuncText(func.def, func.params);
$scope.targetChanged();
};
$scope.addFunction = function(funcDef) {
......@@ -153,6 +147,7 @@ function (angular, _, config) {
params: funcDef.defaultParams,
text: getFuncText(funcDef, funcDef.defaultParams)
});
$scope.targetChanged();
};
});
......
......@@ -23,7 +23,7 @@
<div class="editor-option" ng-repeat="param in func.def.params">
<label class="small">{{param.name}}</label>
<input ng-if="param.type === 'int'"
type="text"
type="number"
placeholder="seconds"
focus-me="true"
class="input-mini"
......
......@@ -459,6 +459,9 @@ function (angular, app, $, _, kbn, moment, timeSeries, graphiteSrv, RQ) {
// Function for rendering panel
function render_panel(data) {
if (!data) {
return;
}
// IE doesn't work without this
elem.css({height:scope.panel.height || scope.row.height});
......@@ -476,7 +479,6 @@ function (angular, app, $, _, kbn, moment, timeSeries, graphiteSrv, RQ) {
var stack = scope.panel.stack ? true : null;
// Populate element
try {
var options = {
legend: { show: false },
series: {
......@@ -595,10 +597,6 @@ function (angular, app, $, _, kbn, moment, timeSeries, graphiteSrv, RQ) {
elem.css('margin-left', '');
}
} catch(e) {
console.log(e);
// Nothing to do here
}
}
function time_format(interval) {
......
define([
],
function () {
'use strict';
return [
{
name: "scaleToSeconds",
params: [ { name: "seconds", type: "int" } ],
defaultParams: [1]
},
{
name: "sumSeries",
params: [],
},
{
name: "groupByNode",
params: [
{
name: "node",
type: "node",
},
{
name: "function",
type: "function",
}
],
defaultParams: [3, "sumSeries"]
},
{
name: "alias",
params: [
{ name: "alias", type: 'string' }
],
defaultParams: ['alias']
},
{
name: 'aliasByNode',
params: [ { name: "node", type: "node", } ],
defaultParams: [3]
}
];
});
\ No newline at end of file
define([
],
function () {
});
\ No newline at end of file
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