mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
refactoring graphite target editor
This commit is contained in:
parent
76fa88cfd4
commit
21ef0cdcd2
@ -1,37 +1,13 @@
|
||||
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) {
|
||||
|
44
src/app/services/graphite/functions.js
Normal file
44
src/app/services/graphite/functions.js
Normal file
@ -0,0 +1,44 @@
|
||||
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]
|
||||
}
|
||||
];
|
||||
|
||||
});
|
7
src/app/services/graphite/graphiteSrv.js
Normal file
7
src/app/services/graphite/graphiteSrv.js
Normal file
@ -0,0 +1,7 @@
|
||||
define([
|
||||
],
|
||||
function () {
|
||||
|
||||
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user