Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
b2aca66e
Commit
b2aca66e
authored
Mar 24, 2014
by
Torkel Ödegaard
Committed by
Bruce Sherrod
Mar 26, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aliasByNode support for second node param, Closes #167
parent
add61cf7
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
8 deletions
+100
-8
src/app/directives/graphiteFuncEditor.js
+35
-5
src/app/services/graphite/gfunc.js
+29
-2
src/test/specs/gfunc-specs.js
+36
-1
No files found.
src/app/directives/graphiteFuncEditor.js
View file @
b2aca66e
...
@@ -29,6 +29,8 @@ function (angular, _, $) {
...
@@ -29,6 +29,8 @@ function (angular, _, $) {
var
$funcControls
=
$
(
funcControlsTemplate
);
var
$funcControls
=
$
(
funcControlsTemplate
);
var
func
=
$scope
.
func
;
var
func
=
$scope
.
func
;
var
funcDef
=
func
.
def
;
var
funcDef
=
func
.
def
;
var
scheduledRelink
=
false
;
var
paramCountAtLink
=
0
;
function
clickFuncParam
(
paramIndex
)
{
function
clickFuncParam
(
paramIndex
)
{
/*jshint validthis:true */
/*jshint validthis:true */
...
@@ -51,16 +53,32 @@ function (angular, _, $) {
...
@@ -51,16 +53,32 @@ function (angular, _, $) {
}
}
}
}
function
scheduledRelinkIfNeeded
()
{
if
(
paramCountAtLink
===
func
.
params
.
length
)
{
return
;
}
if
(
!
scheduledRelink
)
{
scheduledRelink
=
true
;
setTimeout
(
function
()
{
relink
();
scheduledRelink
=
false
;
},
200
);
}
}
function
inputBlur
(
paramIndex
)
{
function
inputBlur
(
paramIndex
)
{
/*jshint validthis:true */
/*jshint validthis:true */
var
$input
=
$
(
this
);
var
$input
=
$
(
this
);
var
$link
=
$input
.
prev
();
var
$link
=
$input
.
prev
();
if
(
$input
.
val
()
!==
''
)
{
if
(
$input
.
val
()
!==
''
||
func
.
def
.
params
[
paramIndex
].
optional
)
{
$link
.
text
(
$input
.
val
());
$link
.
text
(
$input
.
val
());
func
.
updateParam
(
$input
.
val
(),
paramIndex
);
func
.
updateParam
(
$input
.
val
(),
paramIndex
);
scheduledRelinkIfNeeded
();
$scope
.
$apply
(
$scope
.
targetChanged
);
$scope
.
$apply
(
$scope
.
targetChanged
);
}
}
...
@@ -129,9 +147,19 @@ function (angular, _, $) {
...
@@ -129,9 +147,19 @@ function (angular, _, $) {
$funcLink
.
appendTo
(
elem
);
$funcLink
.
appendTo
(
elem
);
_
.
each
(
funcDef
.
params
,
function
(
param
,
index
)
{
_
.
each
(
funcDef
.
params
,
function
(
param
,
index
)
{
if
(
param
.
optional
&&
!
func
.
params
[
index
])
{
return
;
}
if
(
index
>
0
)
{
$
(
'<span>, </span>'
).
appendTo
(
elem
);
}
var
$paramLink
=
$
(
'<a ng-click="" class="graphite-func-param-link">'
+
func
.
params
[
index
]
+
'</a>'
);
var
$paramLink
=
$
(
'<a ng-click="" class="graphite-func-param-link">'
+
func
.
params
[
index
]
+
'</a>'
);
var
$input
=
$
(
paramTemplate
);
var
$input
=
$
(
paramTemplate
);
paramCountAtLink
++
;
$paramLink
.
appendTo
(
elem
);
$paramLink
.
appendTo
(
elem
);
$input
.
appendTo
(
elem
);
$input
.
appendTo
(
elem
);
...
@@ -140,10 +168,6 @@ function (angular, _, $) {
...
@@ -140,10 +168,6 @@ function (angular, _, $) {
$input
.
keypress
(
_
.
partial
(
inputKeyPress
,
index
));
$input
.
keypress
(
_
.
partial
(
inputKeyPress
,
index
));
$paramLink
.
click
(
_
.
partial
(
clickFuncParam
,
index
));
$paramLink
.
click
(
_
.
partial
(
clickFuncParam
,
index
));
if
(
index
!==
funcDef
.
params
.
length
-
1
)
{
$
(
'<span>, </span>'
).
appendTo
(
elem
);
}
if
(
funcDef
.
params
[
index
].
options
)
{
if
(
funcDef
.
params
[
index
].
options
)
{
addTypeahead
(
$input
,
index
);
addTypeahead
(
$input
,
index
);
}
}
...
@@ -200,11 +224,17 @@ function (angular, _, $) {
...
@@ -200,11 +224,17 @@ function (angular, _, $) {
});
});
}
}
function
relink
()
{
elem
.
children
().
remove
();
addElementsAndCompile
();
addElementsAndCompile
();
ifJustAddedFocusFistParam
();
ifJustAddedFocusFistParam
();
registerFuncControlsToggle
();
registerFuncControlsToggle
();
registerFuncControlsActions
();
registerFuncControlsActions
();
}
}
relink
();
}
};
};
});
});
...
...
src/app/services/graphite/gfunc.js
View file @
b2aca66e
...
@@ -132,7 +132,10 @@ function (_) {
...
@@ -132,7 +132,10 @@ function (_) {
addFuncDef
({
addFuncDef
({
name
:
'aliasByNode'
,
name
:
'aliasByNode'
,
category
:
categories
.
Special
,
category
:
categories
.
Special
,
params
:
[
{
name
:
"node"
,
type
:
"int"
,
options
:
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
12
]
}
],
params
:
[
{
name
:
"node"
,
type
:
"int"
,
options
:
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
12
]
},
{
name
:
"node"
,
type
:
"int"
,
options
:
[
0
,
-
1
,
-
2
,
-
3
,
-
4
,
-
5
,
-
6
,
-
7
],
optional
:
true
},
],
defaultParams
:
[
3
]
defaultParams
:
[
3
]
});
});
...
@@ -340,8 +343,28 @@ function (_) {
...
@@ -340,8 +343,28 @@ function (_) {
return
str
+
parameters
.
join
(
','
)
+
')'
;
return
str
+
parameters
.
join
(
','
)
+
')'
;
};
};
FuncInstance
.
prototype
.
_hasMultipleParamsInString
=
function
(
strValue
,
index
)
{
if
(
strValue
.
indexOf
(
','
)
===
-
1
)
{
return
false
;
}
return
this
.
def
.
params
[
index
+
1
]
&&
this
.
def
.
params
[
index
+
1
].
optional
;
};
FuncInstance
.
prototype
.
updateParam
=
function
(
strValue
,
index
)
{
FuncInstance
.
prototype
.
updateParam
=
function
(
strValue
,
index
)
{
if
(
this
.
def
.
params
[
index
].
type
===
'int'
)
{
// handle optional parameters
// if string contains ',' and next param is optional, split and update both
if
(
this
.
_hasMultipleParamsInString
(
strValue
,
index
))
{
_
.
each
(
strValue
.
split
(
','
),
function
(
partVal
,
idx
)
{
this
.
updateParam
(
partVal
.
trim
(),
idx
);
},
this
);
return
;
}
if
(
strValue
===
''
&&
this
.
def
.
params
[
index
].
optional
)
{
this
.
params
.
splice
(
index
,
1
);
}
else
if
(
this
.
def
.
params
[
index
].
type
===
'int'
)
{
this
.
params
[
index
]
=
parseInt
(
strValue
,
10
);
this
.
params
[
index
]
=
parseInt
(
strValue
,
10
);
}
}
else
{
else
{
...
@@ -359,6 +382,10 @@ function (_) {
...
@@ -359,6 +382,10 @@ function (_) {
var
text
=
this
.
def
.
name
+
'('
;
var
text
=
this
.
def
.
name
+
'('
;
_
.
each
(
this
.
def
.
params
,
function
(
param
,
index
)
{
_
.
each
(
this
.
def
.
params
,
function
(
param
,
index
)
{
if
(
param
.
optional
&&
this
.
params
[
index
]
===
undefined
)
{
return
;
}
text
+=
this
.
params
[
index
]
+
', '
;
text
+=
this
.
params
[
index
]
+
', '
;
},
this
);
},
this
);
text
=
text
.
substring
(
0
,
text
.
length
-
2
);
text
=
text
.
substring
(
0
,
text
.
length
-
2
);
...
...
src/test/specs/gfunc-specs.js
View file @
b2aca66e
...
@@ -57,12 +57,47 @@ define([
...
@@ -57,12 +57,47 @@ define([
});
});
describe
(
'when requesting function categories'
,
function
()
{
describe
(
'when requesting function categories'
,
function
()
{
it
(
'should return function categories'
,
function
()
{
it
(
'should return function categories'
,
function
()
{
var
catIndex
=
gfunc
.
getCategories
();
var
catIndex
=
gfunc
.
getCategories
();
expect
(
catIndex
.
Special
.
length
).
to
.
be
.
greaterThan
(
8
);
expect
(
catIndex
.
Special
.
length
).
to
.
be
.
greaterThan
(
8
);
});
});
});
describe
(
'when updating func param'
,
function
()
{
it
(
'should update param value and update text representation'
,
function
()
{
var
func
=
gfunc
.
createFuncInstance
(
'summarize'
);
func
.
updateParam
(
'1h'
,
0
);
expect
(
func
.
params
[
0
]).
to
.
be
(
'1h'
);
expect
(
func
.
text
).
to
.
be
(
'summarize(1h, sum)'
);
});
});
describe
(
'when updating func param with optional second parameter'
,
function
()
{
it
(
'should update value and text'
,
function
()
{
var
func
=
gfunc
.
createFuncInstance
(
'aliasByNode'
);
func
.
updateParam
(
'1'
,
0
);
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
.
text
).
to
.
be
(
'aliasByNode(4, -5)'
);
});
it
(
'should remove second param when empty string is set'
,
function
()
{
var
func
=
gfunc
.
createFuncInstance
(
'aliasByNode'
);
func
.
updateParam
(
'4,-5'
,
0
);
func
.
updateParam
(
''
,
1
);
expect
(
func
.
params
[
0
]).
to
.
be
(
4
);
expect
(
func
.
params
[
1
]).
to
.
be
(
undefined
);
expect
(
func
.
text
).
to
.
be
(
'aliasByNode(4)'
);
});
});
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment