Commit 76fa88cf by Torkel Ödegaard

add function works

parent 2032ff66
...@@ -7,18 +7,29 @@ function (angular, _, config) { ...@@ -7,18 +7,29 @@ function (angular, _, config) {
'use strict'; 'use strict';
var module = angular.module('kibana.controllers'); var module = angular.module('kibana.controllers');
var graphiteFunctions = [ var funcDefs = [
{ {
name: "scaleToSeconds", name: "scaleToSeconds",
params: [ { name: "seconds", type: "int" } ] params: [ { name: "seconds", type: "int" } ],
defaultParams: [1]
}, },
{ {
name: "sumSeries", name: "sumSeries",
params: [] params: [],
}, },
{ {
name: "groupByNode", name: "groupByNode",
params: [ { name: "node", type: "node" }, { name: "function", type: "function" }] params: [
{
name: "node",
type: "node",
},
{
name: "function",
type: "function",
}
],
defaultParams: [3, "sumSeries"]
} }
]; ];
...@@ -32,22 +43,8 @@ function (angular, _, config) { ...@@ -32,22 +43,8 @@ function (angular, _, config) {
}; };
}); });
$scope.functions = [ $scope.funcDefs = funcDefs;
{ $scope.functions = [];
text: "scaleToSeconds(1)",
def: graphiteFunctions[0],
params: {
seconds: 1
}
},
{
text: "groupByNode",
def: graphiteFunctions[2],
params: {
}
}
];
}; };
function getSegmentPathUpTo(index) { function getSegmentPathUpTo(index) {
...@@ -89,6 +86,20 @@ function (angular, _, config) { ...@@ -89,6 +86,20 @@ function (angular, _, config) {
}); });
} }
function getFuncText(funcDef, params) {
if (params.length === 0) {
return funcDef.name + '()';
}
var text = funcDef.name + '(';
_.each(funcDef.params, function(param, index) {
text += params[index] + ', ';
});
text = text.substring(0, text.length - 2);
text += ')';
return text;
}
$scope.getAltSegments = function (index) { $scope.getAltSegments = function (index) {
$scope.altSegments = []; $scope.altSegments = [];
...@@ -133,20 +144,15 @@ function (angular, _, config) { ...@@ -133,20 +144,15 @@ function (angular, _, config) {
}; };
$scope.functionParamsChanged = function(func) { $scope.functionParamsChanged = function(func) {
func.text = func.def.name + '('; func.text = getFuncText(func.def, func.params);
_.each(func.def.params, function(param) {
func.text += func.params[param.name] + ', ';
});
func.text = func.text.substring(0, func.text.length - 2);
func.text += ')';
}; };
$scope.addFunction = function() { $scope.addFunction = function(funcDef) {
console.log($scope.functions); $scope.functions.push({
}; def: funcDef,
params: funcDef.defaultParams,
$scope.editFunction = function() { text: getFuncText(funcDef, funcDef.defaultParams)
//func.edit = true; });
}; };
}); });
...@@ -157,7 +163,6 @@ function (angular, _, config) { ...@@ -157,7 +163,6 @@ function (angular, _, config) {
link: function(scope, element, attrs) { link: function(scope, element, attrs) {
var model = $parse(attrs.focusMe); var model = $parse(attrs.focusMe);
scope.$watch(model, function(value) { scope.$watch(model, function(value) {
console.log('value=',value);
if(value === true) { if(value === true) {
$timeout(function() { $timeout(function() {
element[0].focus(); element[0].focus();
......
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
</span> </span>
<ul class="grafana-segment-list" role="menu"> <ul class="grafana-segment-list" role="menu">
<li class="dropdown" ng-repeat="segment in segments" role="menuitem"> <li class="dropdown" ng-repeat="segment in segments" role="menuitem">
<a tabindex="1" class="grafana-target-segment dropdown-toggle" <a tabindex="1"
data-toggle="dropdown" ng-click="getAltSegments($index)" focus-me="segment.focus" class="grafana-target-segment dropdown-toggle"
data-placement="bottom" ng-bind-html-unsafe="segment.html"></a> data-toggle="dropdown"
ng-click="getAltSegments($index)"
focus-me="segment.focus"
ng-bind-html-unsafe="segment.html">
</a>
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<li ng-repeat="altSegment in altSegments" role="menuitem"> <li ng-repeat="altSegment in altSegments" role="menuitem">
<a href="javascript:void(0)" tabindex="1" ng-click="setSegment($index, $parent.$index)" ng-bind-html-unsafe="altSegment.html"></a> <a href="javascript:void(0)" tabindex="1" ng-click="setSegment($index, $parent.$index)" ng-bind-html-unsafe="altSegment.html"></a>
...@@ -34,8 +38,22 @@ ...@@ -34,8 +38,22 @@
<a bs-popover="'app/panels/graphite/funcEditor.html'" data-placement="top">{{func.text}}</a> <a bs-popover="'app/panels/graphite/funcEditor.html'" data-placement="top">{{func.text}}</a>
<i class="icon-long-arrow-right"></i> <i class="icon-long-arrow-right"></i>
</li> </li>
<li> <li class="dropdown">
<a ng-click="addFunction">add function</a> <a class="dropdown-toggle"
data-toggle="dropdown"
tabindex="1"
ng-click="addFunction">
add function
</a>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="funcDef in funcDefs" role="menuitem">
<a href="javascript:void(0)"
tabindex="1"
ng-click="addFunction(funcDef)">
{{funcDef.name}}
</a>
</li>
</ul>
</li> </li>
</ul> </ul>
<div class="clearfix"></div> <div class="clearfix"></div>
......
<div class="grafana-func-editor"> <div class="grafana-func-editor">
<div class="grafana-func-editor-header"> <div class="grafana-func-editor-header">
<a ng-click="removeFunction(func)"> <a ng-click="removeFunction(func)">
Remove Remove
</a> </a>
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
<a ng-click="dismiss()"> <a ng-click="dismiss()">
Close Close
</a> </a>
</div> </div>
<div class="editor-row"> <div class="editor-row">
<div class="section"> <div class="section">
<div class="editor-option" ng-repeat="param in func.def.params"> <div class="editor-option" ng-repeat="param in func.def.params">
<label class="small">{{param.name}}</label> <label class="small">{{param.name}}</label>
...@@ -28,43 +28,23 @@ ...@@ -28,43 +28,23 @@
focus-me="true" focus-me="true"
class="input-mini" class="input-mini"
ng-change="functionParamsChanged(func)" ng-model-onblur ng-change="functionParamsChanged(func)" ng-model-onblur
ng-model="func.params[param.name]" /> ng-model="func.params[$index]" />
<select ng-if="param.type === 'node'" <select ng-if="param.type === 'node'"
class="input-mini" class="input-mini"
ng-model="func.params[param.name]" ng-model="func.params[$index]"
ng-change="functionParamsChanged(func)" ng-change="functionParamsChanged(func)"
focus-me="true"
ng-options="f for f in [1,2,3,4,5,6,7,8,9,10]"> ng-options="f for f in [1,2,3,4,5,6,7,8,9,10]">
</select> </select>
<select ng-if="param.type === 'function'" <select ng-if="param.type === 'function'"
style="width: 110px" style="width: 110px"
ng-change="functionParamsChanged(func)" ng-change="functionParamsChanged(func)"
ng-model="func.params[param.name]" ng-model="func.params[$index]"
ng-options="f for f in ['sumSeries', 'avgSeries']"> ng-options="f for f in ['sumSeries', 'avgSeries']">
</select> </select>
</div> </div>
</div> </div>
</div>
<!-- <div class="row-fluid">
<div class="pull-left">
<input ng-if="param.type === 'int'"
placeholder="seconds"
focus-me="true"
class="input-mini"
ng-model="func.params[param.name]" />
<select ng-if="param.type === 'node'"
class="input-mini"
ng-model="func.params[param.name]"
ng-options="f for f in [1,2,3,4,5,6,7,8,9,10]">
</select>
<select ng-if="param.type === 'function'"
class="input-small"
ng-model="func.params[param.name]"
ng-options="f for f in ['sumSeries', 'avgSeries']">
</select>
</div> </div>
</div> </div>
--></div> \ No newline at end of file
\ 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