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
5ba19144
Commit
5ba19144
authored
Nov 25, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(influxdb): more work on query editor
parent
c9ba856c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
46 deletions
+66
-46
public/app/plugins/datasource/influxdb/influx_query.ts
+22
-20
public/app/plugins/datasource/influxdb/partials/query.editor.html
+3
-0
public/app/plugins/datasource/influxdb/partials/query_part.html
+1
-1
public/app/plugins/datasource/influxdb/query_ctrl.js
+11
-1
public/app/plugins/datasource/influxdb/query_part.ts
+29
-24
No files found.
public/app/plugins/datasource/influxdb/influx_query.ts
View file @
5ba19144
...
@@ -18,13 +18,13 @@ class InfluxQuery {
...
@@ -18,13 +18,13 @@ class InfluxQuery {
target
.
tags
=
target
.
tags
||
[];
target
.
tags
=
target
.
tags
||
[];
target
.
groupBy
=
target
.
groupBy
||
[{
type
:
'time'
,
interval
:
'auto'
}];
target
.
groupBy
=
target
.
groupBy
||
[{
type
:
'time'
,
interval
:
'auto'
}];
target
.
select
=
target
.
select
||
[[
target
.
select
=
target
.
select
||
[[
{
nam
e
:
'field'
,
params
:
[
'value'
]},
{
typ
e
:
'field'
,
params
:
[
'value'
]},
{
nam
e
:
'mean'
,
params
:
[]},
{
typ
e
:
'mean'
,
params
:
[]},
]];
]];
this
.
updateSelectParts
();
this
.
updateSelectParts
();
this
.
groupByParts
=
[
this
.
groupByParts
=
[
queryPart
.
create
({
nam
e
:
'time'
,
params
:
[
'$interval'
]})
queryPart
.
create
({
typ
e
:
'time'
,
params
:
[
'$interval'
]})
];
];
}
}
...
@@ -37,7 +37,7 @@ class InfluxQuery {
...
@@ -37,7 +37,7 @@ class InfluxQuery {
updatePersistedParts
()
{
updatePersistedParts
()
{
this
.
target
.
select
=
_
.
map
(
this
.
selectModels
,
function
(
selectParts
)
{
this
.
target
.
select
=
_
.
map
(
this
.
selectModels
,
function
(
selectParts
)
{
return
_
.
map
(
selectParts
,
function
(
part
:
any
)
{
return
_
.
map
(
selectParts
,
function
(
part
:
any
)
{
return
{
name
:
part
.
def
.
nam
e
,
params
:
part
.
params
};
return
{
type
:
part
.
def
.
typ
e
,
params
:
part
.
params
};
});
});
});
});
}
}
...
@@ -48,22 +48,24 @@ class InfluxQuery {
...
@@ -48,22 +48,24 @@ class InfluxQuery {
}
}
removeSelectPart
(
selectParts
,
part
)
{
removeSelectPart
(
selectParts
,
part
)
{
var
partIndex
=
_
.
indexOf
(
selectParts
,
part
);
// if we remove the field remove the whole statement
selectParts
.
splice
(
partIndex
,
1
);
if
(
part
.
def
.
type
===
'field'
)
{
this
.
updatePersistedParts
();
if
(
this
.
selectModels
.
length
>
1
)
{
}
var
modelsIndex
=
_
.
indexOf
(
this
.
selectModels
,
selectParts
);
this
.
selectModels
.
splice
(
modelsIndex
,
1
);
}
}
else
{
var
partIndex
=
_
.
indexOf
(
selectParts
,
part
);
selectParts
.
splice
(
partIndex
,
1
);
}
addSelectPart
(
selectParts
,
name
)
{
var
partModel
=
queryPart
.
create
({
name
:
name
});
partModel
.
def
.
addStrategy
(
selectParts
,
partModel
);
this
.
updatePersistedParts
();
this
.
updatePersistedParts
();
}
}
addSelect
()
{
addSelectPart
(
selectParts
,
type
)
{
this
.
target
.
select
.
push
([
var
partModel
=
queryPart
.
create
({
type
:
type
});
{
name
:
'mean'
,
params
:
[
'value'
]},
partModel
.
def
.
addStrategy
(
selectParts
,
partModel
,
this
);
]);
this
.
updatePersistedParts
();
this
.
updateSelectParts
();
}
}
private
renderTagCondition
(
tag
,
index
)
{
private
renderTagCondition
(
tag
,
index
)
{
...
@@ -100,12 +102,12 @@ class InfluxQuery {
...
@@ -100,12 +102,12 @@ class InfluxQuery {
render
()
{
render
()
{
var
target
=
this
.
target
;
var
target
=
this
.
target
;
if
(
!
target
.
measurement
)
{
if
(
target
.
rawQuery
)
{
throw
"Metric measurement is missing"
;
return
target
.
query
;
}
}
if
(
!
target
.
fields
)
{
if
(
!
target
.
measurement
)
{
t
arget
.
fields
=
[{
name
:
'value'
,
func
:
target
.
function
||
'mean'
}]
;
t
hrow
"Metric measurement is missing"
;
}
}
var
query
=
'SELECT '
;
var
query
=
'SELECT '
;
...
...
public/app/plugins/datasource/influxdb/partials/query.editor.html
View file @
5ba19144
...
@@ -73,6 +73,9 @@
...
@@ -73,6 +73,9 @@
<li
ng-repeat=
"part in selectParts"
>
<li
ng-repeat=
"part in selectParts"
>
<influx-query-part-editor
part=
"part"
class=
"tight-form-item tight-form-func"
remove-action=
"removeSelectPart(selectParts, part)"
part-updated=
"selectPartUpdated(selectParts, part)"
></influx-query-part-editor>
<influx-query-part-editor
part=
"part"
class=
"tight-form-item tight-form-func"
remove-action=
"removeSelectPart(selectParts, part)"
part-updated=
"selectPartUpdated(selectParts, part)"
></influx-query-part-editor>
</li>
</li>
<li>
<metric-segment
segment=
"selectPlusButton"
get-options=
"getSelectOptions(selectParts)"
on-change=
"selectAction(selectParts, $index)"
></metric-segment>
</li>
<li
class=
"dropdown"
dropdown-typeahead=
"selectMenu"
dropdown-typeahead-on-select=
"addSelectPart(selectParts, $item, $subItem)"
>
<li
class=
"dropdown"
dropdown-typeahead=
"selectMenu"
dropdown-typeahead-on-select=
"addSelectPart(selectParts, $item, $subItem)"
>
</li>
</li>
</ul>
</ul>
...
...
public/app/plugins/datasource/influxdb/partials/query_part.html
View file @
5ba19144
...
@@ -2,4 +2,4 @@
...
@@ -2,4 +2,4 @@
<span
class=
"pointer fa fa-remove"
ng-click=
"removeActionInternal()"
></span>
<span
class=
"pointer fa fa-remove"
ng-click=
"removeActionInternal()"
></span>
</div>
</div>
<a
ng-click=
"toggleControls()"
>
{{part.def.
nam
e}}
</a><span>
(
</span><span
class=
"query-part-parameters"
></span><span>
)
</span>
<a
ng-click=
"toggleControls()"
>
{{part.def.
typ
e}}
</a><span>
(
</span><span
class=
"query-part-parameters"
></span><span>
)
</span>
public/app/plugins/datasource/influxdb/query_ctrl.js
View file @
5ba19144
...
@@ -55,11 +55,21 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
...
@@ -55,11 +55,21 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
$scope
.
selectMenu
=
_
.
reduce
(
categories
,
function
(
memo
,
cat
,
key
)
{
$scope
.
selectMenu
=
_
.
reduce
(
categories
,
function
(
memo
,
cat
,
key
)
{
var
menu
=
{
text
:
key
};
var
menu
=
{
text
:
key
};
menu
.
submenu
=
_
.
map
(
cat
,
function
(
item
)
{
menu
.
submenu
=
_
.
map
(
cat
,
function
(
item
)
{
return
{
text
:
item
.
name
,
value
:
item
.
nam
e
};
return
{
text
:
item
.
type
,
value
:
item
.
typ
e
};
});
});
memo
.
push
(
menu
);
memo
.
push
(
menu
);
return
memo
;
return
memo
;
},
[]);
},
[]);
$scope
.
groupByMenu
=
_
.
reduce
(
categories
,
function
(
memo
,
cat
,
key
)
{
var
menu
=
{
text
:
key
};
menu
.
submenu
=
_
.
map
(
cat
,
function
(
item
)
{
return
{
text
:
item
.
type
,
value
:
item
.
type
};
});
memo
.
push
(
menu
);
return
memo
;
},
[]);
};
};
$scope
.
addSelectPart
=
function
(
selectParts
,
cat
,
subitem
)
{
$scope
.
addSelectPart
=
function
(
selectParts
,
cat
,
subitem
)
{
...
...
public/app/plugins/datasource/influxdb/query_part.ts
View file @
5ba19144
...
@@ -14,7 +14,7 @@ var categories = {
...
@@ -14,7 +14,7 @@ var categories = {
var
groupByTimeFunctions
=
[];
var
groupByTimeFunctions
=
[];
class
QueryPartDef
{
class
QueryPartDef
{
nam
e
:
string
;
typ
e
:
string
;
params
:
any
[];
params
:
any
[];
defaultParams
:
any
[];
defaultParams
:
any
[];
renderer
:
any
;
renderer
:
any
;
...
@@ -22,7 +22,7 @@ class QueryPartDef {
...
@@ -22,7 +22,7 @@ class QueryPartDef {
addStrategy
:
any
;
addStrategy
:
any
;
constructor
(
options
:
any
)
{
constructor
(
options
:
any
)
{
this
.
name
=
options
.
nam
e
;
this
.
type
=
options
.
typ
e
;
this
.
params
=
options
.
params
;
this
.
params
=
options
.
params
;
this
.
defaultParams
=
options
.
defaultParams
;
this
.
defaultParams
=
options
.
defaultParams
;
this
.
renderer
=
options
.
renderer
;
this
.
renderer
=
options
.
renderer
;
...
@@ -31,13 +31,13 @@ class QueryPartDef {
...
@@ -31,13 +31,13 @@ class QueryPartDef {
}
}
static
register
(
options
:
any
)
{
static
register
(
options
:
any
)
{
index
[
options
.
nam
e
]
=
new
QueryPartDef
(
options
);
index
[
options
.
typ
e
]
=
new
QueryPartDef
(
options
);
options
.
category
.
push
(
index
[
options
.
nam
e
]);
options
.
category
.
push
(
index
[
options
.
typ
e
]);
}
}
}
}
function
functionRenderer
(
part
,
innerExpr
)
{
function
functionRenderer
(
part
,
innerExpr
)
{
var
str
=
part
.
def
.
nam
e
+
'('
;
var
str
=
part
.
def
.
typ
e
+
'('
;
var
parameters
=
_
.
map
(
part
.
params
,
(
value
,
index
)
=>
{
var
parameters
=
_
.
map
(
part
.
params
,
(
value
,
index
)
=>
{
var
paramType
=
part
.
def
.
params
[
index
];
var
paramType
=
part
.
def
.
params
[
index
];
if
(
paramType
.
quote
===
'single'
)
{
if
(
paramType
.
quote
===
'single'
)
{
...
@@ -101,17 +101,17 @@ function addMathStrategy(selectParts, partModel) {
...
@@ -101,17 +101,17 @@ function addMathStrategy(selectParts, partModel) {
var
partCount
=
selectParts
.
length
;
var
partCount
=
selectParts
.
length
;
if
(
partCount
>
0
)
{
if
(
partCount
>
0
)
{
// if last is math, replace it
// if last is math, replace it
if
(
selectParts
[
partCount
-
1
].
def
.
nam
e
===
'math'
)
{
if
(
selectParts
[
partCount
-
1
].
def
.
typ
e
===
'math'
)
{
selectParts
[
partCount
-
1
]
=
partModel
;
selectParts
[
partCount
-
1
]
=
partModel
;
return
;
return
;
}
}
// if next to last is math, replace it
// if next to last is math, replace it
if
(
selectParts
[
partCount
-
2
].
def
.
nam
e
===
'math'
)
{
if
(
selectParts
[
partCount
-
2
].
def
.
typ
e
===
'math'
)
{
selectParts
[
partCount
-
2
]
=
partModel
;
selectParts
[
partCount
-
2
]
=
partModel
;
return
;
return
;
}
}
// if last is alias add it before
// if last is alias add it before
else
if
(
selectParts
[
partCount
-
1
].
def
.
nam
e
===
'alias'
)
{
else
if
(
selectParts
[
partCount
-
1
].
def
.
typ
e
===
'alias'
)
{
selectParts
.
splice
(
partCount
-
1
,
0
,
partModel
);
selectParts
.
splice
(
partCount
-
1
,
0
,
partModel
);
return
;
return
;
}
}
...
@@ -123,7 +123,7 @@ function addAliasStrategy(selectParts, partModel) {
...
@@ -123,7 +123,7 @@ function addAliasStrategy(selectParts, partModel) {
var
partCount
=
selectParts
.
length
;
var
partCount
=
selectParts
.
length
;
if
(
partCount
>
0
)
{
if
(
partCount
>
0
)
{
// if last is alias, replace it
// if last is alias, replace it
if
(
selectParts
[
partCount
-
1
].
def
.
nam
e
===
'alias'
)
{
if
(
selectParts
[
partCount
-
1
].
def
.
typ
e
===
'alias'
)
{
selectParts
[
partCount
-
1
]
=
partModel
;
selectParts
[
partCount
-
1
]
=
partModel
;
return
;
return
;
}
}
...
@@ -131,9 +131,18 @@ function addAliasStrategy(selectParts, partModel) {
...
@@ -131,9 +131,18 @@ function addAliasStrategy(selectParts, partModel) {
selectParts
.
push
(
partModel
);
selectParts
.
push
(
partModel
);
}
}
function
addFieldStrategy
(
selectParts
,
partModel
,
query
)
{
// copy all parts
var
parts
=
_
.
map
(
selectParts
,
function
(
part
:
any
)
{
return
new
QueryPart
({
type
:
part
.
def
.
type
,
params
:
_
.
clone
(
part
.
params
)});
});
query
.
selectModels
.
push
(
parts
);
}
QueryPartDef
.
register
({
QueryPartDef
.
register
({
name
:
'field'
,
type
:
'field'
,
addStrategy
:
addFieldStrategy
,
category
:
categories
.
Fields
,
category
:
categories
.
Fields
,
params
:
[{
type
:
'field'
}],
params
:
[{
type
:
'field'
}],
defaultParams
:
[
'value'
],
defaultParams
:
[
'value'
],
...
@@ -141,7 +150,7 @@ QueryPartDef.register({
...
@@ -141,7 +150,7 @@ QueryPartDef.register({
});
});
QueryPartDef
.
register
({
QueryPartDef
.
register
({
nam
e
:
'mean'
,
typ
e
:
'mean'
,
addStrategy
:
replaceAggregationAddStrategy
,
addStrategy
:
replaceAggregationAddStrategy
,
category
:
categories
.
Aggregations
,
category
:
categories
.
Aggregations
,
params
:
[],
params
:
[],
...
@@ -150,7 +159,7 @@ QueryPartDef.register({
...
@@ -150,7 +159,7 @@ QueryPartDef.register({
});
});
QueryPartDef
.
register
({
QueryPartDef
.
register
({
nam
e
:
'sum'
,
typ
e
:
'sum'
,
addStrategy
:
replaceAggregationAddStrategy
,
addStrategy
:
replaceAggregationAddStrategy
,
category
:
categories
.
Aggregations
,
category
:
categories
.
Aggregations
,
params
:
[],
params
:
[],
...
@@ -159,7 +168,7 @@ QueryPartDef.register({
...
@@ -159,7 +168,7 @@ QueryPartDef.register({
});
});
QueryPartDef
.
register
({
QueryPartDef
.
register
({
nam
e
:
'derivative'
,
typ
e
:
'derivative'
,
addStrategy
:
addTransformationStrategy
,
addStrategy
:
addTransformationStrategy
,
category
:
categories
.
Transformations
,
category
:
categories
.
Transformations
,
params
:
[{
name
:
"duration"
,
type
:
"interval"
,
options
:
[
'1s'
,
'10s'
,
'1m'
,
'5min'
,
'10m'
,
'15m'
,
'1h'
]}],
params
:
[{
name
:
"duration"
,
type
:
"interval"
,
options
:
[
'1s'
,
'10s'
,
'1m'
,
'5min'
,
'10m'
,
'15m'
,
'1h'
]}],
...
@@ -168,7 +177,7 @@ QueryPartDef.register({
...
@@ -168,7 +177,7 @@ QueryPartDef.register({
});
});
QueryPartDef
.
register
({
QueryPartDef
.
register
({
nam
e
:
'time'
,
typ
e
:
'time'
,
category
:
groupByTimeFunctions
,
category
:
groupByTimeFunctions
,
params
:
[{
name
:
"rate"
,
type
:
"interval"
,
options
:
[
'$interval'
,
'1s'
,
'10s'
,
'1m'
,
'5min'
,
'10m'
,
'15m'
,
'1h'
]
}],
params
:
[{
name
:
"rate"
,
type
:
"interval"
,
options
:
[
'$interval'
,
'1s'
,
'10s'
,
'1m'
,
'5min'
,
'10m'
,
'15m'
,
'1h'
]
}],
defaultParams
:
[
'$interval'
],
defaultParams
:
[
'$interval'
],
...
@@ -176,7 +185,7 @@ QueryPartDef.register({
...
@@ -176,7 +185,7 @@ QueryPartDef.register({
});
});
QueryPartDef
.
register
({
QueryPartDef
.
register
({
nam
e
:
'math'
,
typ
e
:
'math'
,
addStrategy
:
addMathStrategy
,
addStrategy
:
addMathStrategy
,
category
:
categories
.
Math
,
category
:
categories
.
Math
,
params
:
[{
name
:
"expr"
,
type
:
"string"
}],
params
:
[{
name
:
"expr"
,
type
:
"string"
}],
...
@@ -185,7 +194,7 @@ QueryPartDef.register({
...
@@ -185,7 +194,7 @@ QueryPartDef.register({
});
});
QueryPartDef
.
register
({
QueryPartDef
.
register
({
nam
e
:
'alias'
,
typ
e
:
'alias'
,
addStrategy
:
addAliasStrategy
,
addStrategy
:
addAliasStrategy
,
category
:
categories
.
Aliasing
,
category
:
categories
.
Aliasing
,
params
:
[{
name
:
"name"
,
type
:
"string"
,
quote
:
'double'
}],
params
:
[{
name
:
"name"
,
type
:
"string"
,
quote
:
'double'
}],
...
@@ -202,9 +211,9 @@ class QueryPart {
...
@@ -202,9 +211,9 @@ class QueryPart {
constructor
(
part
:
any
)
{
constructor
(
part
:
any
)
{
this
.
part
=
part
;
this
.
part
=
part
;
this
.
def
=
index
[
part
.
nam
e
];
this
.
def
=
index
[
part
.
typ
e
];
if
(
!
this
.
def
)
{
if
(
!
this
.
def
)
{
throw
{
message
:
'Could not find query part '
+
part
.
nam
e
};
throw
{
message
:
'Could not find query part '
+
part
.
typ
e
};
}
}
part
.
params
=
part
.
params
||
_
.
clone
(
this
.
def
.
defaultParams
);
part
.
params
=
part
.
params
||
_
.
clone
(
this
.
def
.
defaultParams
);
...
@@ -247,11 +256,11 @@ class QueryPart {
...
@@ -247,11 +256,11 @@ class QueryPart {
updateText
()
{
updateText
()
{
if
(
this
.
params
.
length
===
0
)
{
if
(
this
.
params
.
length
===
0
)
{
this
.
text
=
this
.
def
.
nam
e
+
'()'
;
this
.
text
=
this
.
def
.
typ
e
+
'()'
;
return
;
return
;
}
}
var
text
=
this
.
def
.
nam
e
+
'('
;
var
text
=
this
.
def
.
typ
e
+
'('
;
text
+=
this
.
params
.
join
(
', '
);
text
+=
this
.
params
.
join
(
', '
);
text
+=
')'
;
text
+=
')'
;
this
.
text
=
text
;
this
.
text
=
text
;
...
@@ -263,10 +272,6 @@ export = {
...
@@ -263,10 +272,6 @@ export = {
return
new
QueryPart
(
part
);
return
new
QueryPart
(
part
);
},
},
getFuncDef
:
function
(
name
)
{
return
index
[
name
];
},
getCategories
:
function
()
{
getCategories
:
function
()
{
return
categories
;
return
categories
;
}
}
...
...
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