Added initial metric functions directives based on graphite query

editor.
This commit is contained in:
Alexander Zobnin
2016-01-26 21:51:12 +03:00
parent 38f8e04d22
commit fcf0bdfaca
6 changed files with 597 additions and 19 deletions

View File

@@ -1,9 +1,10 @@
define([
'angular',
'lodash',
'./metricFunctions',
'./utils'
],
function (angular, _, Utils) {
function (angular, _, metricFunctions, Utils) {
'use strict';
var module = angular.module('grafana.controllers');
@@ -16,22 +17,7 @@ define([
$scope.init = function () {
$scope.targetLetters = targetLetters;
$scope.metric = {};
$scope.optionsMenu = [
{text: "Transformations", submenu: [
{text: "groupBy", value: null},
{text: "scale", value: null}
]},
{text: "Aggregations", submenu: [
{text: "sum", value: null},
{text: "average", value: null},
{text: "min", value: null},
{text: "max", value: null}
]},
{text: "Alias", submenu: [
{text: "set alias", value: null},
]},
];
$scope.target.functions = [];
// Load default values
var targetDefaults = {
@@ -274,9 +260,45 @@ define([
// Parse target
};
$scope.targetChanged = function() {
console.log($scope.target.functions);
};
// Validate target and set validation info
$scope.validateTarget = function () {};
$scope.addFunction = function(funcDef) {
var newFunc = metricFunctions.createFuncInstance(funcDef, { withDefaultParams: true });
newFunc.added = true;
$scope.target.functions.push(newFunc);
$scope.moveAliasFuncLast();
if (!newFunc.params.length && newFunc.added) {
$scope.targetChanged();
}
};
$scope.removeFunction = function(func) {
$scope.target.functions = _.without($scope.target.functions, func);
$scope.targetChanged();
};
$scope.moveAliasFuncLast = function() {
var aliasFunc = _.find($scope.target.functions, function(func) {
return func.def.name === 'alias' ||
func.def.name === 'aliasByNode' ||
func.def.name === 'aliasByMetric';
});
if (aliasFunc) {
$scope.target.functions = _.without($scope.target.functions, aliasFunc);
$scope.target.functions.push(aliasFunc);
}
};
$scope.functionChanged = function() {};
/**
* Switch query editor to specified mode.
* Modes: