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
721b37a0
Commit
721b37a0
authored
Nov 30, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(influxdb): new editor now supports field and tag lookup again
parent
b3d494d4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
24 deletions
+59
-24
public/app/plugins/datasource/influxdb/influx_query.ts
+18
-4
public/app/plugins/datasource/influxdb/partials/query.editor.html
+2
-2
public/app/plugins/datasource/influxdb/query_ctrl.js
+13
-6
public/app/plugins/datasource/influxdb/query_part.ts
+2
-2
public/app/plugins/datasource/influxdb/query_part_editor.js
+24
-10
No files found.
public/app/plugins/datasource/influxdb/influx_query.ts
View file @
721b37a0
///<reference path="../../../headers/common.d.ts" />
///<reference path="../../../headers/common.d.ts" />
///<amd-dependency path="./query_builder" name="InfluxQueryBuilder" />
import
_
=
require
(
'lodash'
);
import
_
=
require
(
'lodash'
);
import
queryPart
=
require
(
'./query_part'
);
import
queryPart
=
require
(
'./query_part'
);
declare
var
InfluxQueryBuilder
:
any
;
class
InfluxQuery
{
class
InfluxQuery
{
target
:
any
;
target
:
any
;
selectModels
:
any
[];
selectModels
:
any
[];
...
@@ -76,6 +73,23 @@ class InfluxQuery {
...
@@ -76,6 +73,23 @@ class InfluxQuery {
}
}
removeGroupByPart
(
part
,
index
)
{
removeGroupByPart
(
part
,
index
)
{
var
categories
=
queryPart
.
getCategories
();
if
(
part
.
def
.
type
===
'time'
)
{
// remove fill
this
.
target
.
groupBy
=
_
.
filter
(
this
.
target
.
groupBy
,
(
g
:
any
)
=>
g
.
type
!==
'fill'
);
// remove aggregations
this
.
target
.
select
=
_
.
map
(
this
.
target
.
select
,
(
s
:
any
)
=>
{
return
_
.
filter
(
s
,
(
part
:
any
)
=>
{
var
partModel
=
queryPart
.
create
(
part
);
if
(
partModel
.
def
.
category
===
categories
.
Aggregations
)
{
return
false
;
}
return
true
;
});
});
}
this
.
target
.
groupBy
.
splice
(
index
,
1
);
this
.
target
.
groupBy
.
splice
(
index
,
1
);
this
.
updateProjection
();
this
.
updateProjection
();
}
}
...
@@ -166,7 +180,7 @@ class InfluxQuery {
...
@@ -166,7 +180,7 @@ class InfluxQuery {
var
measurement
=
target
.
measurement
;
var
measurement
=
target
.
measurement
;
if
(
!
measurement
.
match
(
'^/.*/'
)
&&
!
measurement
.
match
(
/^merge
\(
.*
\)
/
))
{
if
(
!
measurement
.
match
(
'^/.*/'
)
&&
!
measurement
.
match
(
/^merge
\(
.*
\)
/
))
{
measurement
=
'"'
+
measurement
+
'"'
;
measurement
=
'"'
+
measurement
+
'"'
;
}
}
query
+=
' FROM '
+
measurement
+
' WHERE '
;
query
+=
' FROM '
+
measurement
+
' WHERE '
;
...
...
public/app/plugins/datasource/influxdb/partials/query.editor.html
View file @
721b37a0
...
@@ -71,7 +71,7 @@
...
@@ -71,7 +71,7 @@
<span
ng-show=
"$index === 0"
>
SELECT
</span>
<span
ng-show=
"$index === 0"
>
SELECT
</span>
</li>
</li>
<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)"
get-options=
"getPartOptions(part)"
></influx-query-part-editor>
</li>
</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>
...
@@ -85,7 +85,7 @@
...
@@ -85,7 +85,7 @@
<span
ng-show=
"$index === 0"
>
GROUP BY
</span>
<span
ng-show=
"$index === 0"
>
GROUP BY
</span>
</li>
</li>
<li
ng-repeat=
"part in queryModel.groupByParts"
>
<li
ng-repeat=
"part in queryModel.groupByParts"
>
<influx-query-part-editor
part=
"part"
class=
"tight-form-item tight-form-func"
remove-action=
"removeGroupByPart(part, $index)"
part-updated=
"get_data();"
></influx-query-part-editor>
<influx-query-part-editor
part=
"part"
class=
"tight-form-item tight-form-func"
remove-action=
"removeGroupByPart(part, $index)"
part-updated=
"get_data();"
get-options=
"getPartOptions(part)"
></influx-query-part-editor>
</li>
</li>
<li>
<li>
<metric-segment
segment=
"groupBySegment"
get-options=
"getGroupByOptions()"
on-change=
"groupByAction(part, $index)"
></metric-segment>
<metric-segment
segment=
"groupBySegment"
get-options=
"getGroupByOptions()"
on-change=
"groupByAction(part, $index)"
></metric-segment>
...
...
public/app/plugins/datasource/influxdb/query_ctrl.js
View file @
721b37a0
...
@@ -124,12 +124,6 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
...
@@ -124,12 +124,6 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
$scope
.
get_data
();
$scope
.
get_data
();
};
};
$scope
.
getFields
=
function
()
{
var
fieldsQuery
=
$scope
.
queryBuilder
.
buildExploreQuery
(
'FIELDS'
);
return
$scope
.
datasource
.
metricFindQuery
(
fieldsQuery
)
.
then
(
$scope
.
transformToSegments
(
false
),
$scope
.
handleQueryError
);
};
$scope
.
toggleQueryMode
=
function
()
{
$scope
.
toggleQueryMode
=
function
()
{
$scope
.
target
.
rawQuery
=
!
$scope
.
target
.
rawQuery
;
$scope
.
target
.
rawQuery
=
!
$scope
.
target
.
rawQuery
;
};
};
...
@@ -140,6 +134,19 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
...
@@ -140,6 +134,19 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
.
then
(
$scope
.
transformToSegments
(
true
),
$scope
.
handleQueryError
);
.
then
(
$scope
.
transformToSegments
(
true
),
$scope
.
handleQueryError
);
};
};
$scope
.
getPartOptions
=
function
(
part
)
{
if
(
part
.
def
.
type
===
'field'
)
{
var
fieldsQuery
=
$scope
.
queryBuilder
.
buildExploreQuery
(
'FIELDS'
);
return
$scope
.
datasource
.
metricFindQuery
(
fieldsQuery
)
.
then
(
$scope
.
transformToSegments
(
true
),
$scope
.
handleQueryError
);
}
if
(
part
.
def
.
type
===
'tag'
)
{
var
tagsQuery
=
$scope
.
queryBuilder
.
buildExploreQuery
(
'TAG_KEYS'
);
return
$scope
.
datasource
.
metricFindQuery
(
tagsQuery
)
.
then
(
$scope
.
transformToSegments
(
true
),
$scope
.
handleQueryError
);
}
};
$scope
.
handleQueryError
=
function
(
err
)
{
$scope
.
handleQueryError
=
function
(
err
)
{
$scope
.
parserError
=
err
.
message
||
'Failed to issue metric query'
;
$scope
.
parserError
=
err
.
message
||
'Failed to issue metric query'
;
return
[];
return
[];
...
...
public/app/plugins/datasource/influxdb/query_part.ts
View file @
721b37a0
...
@@ -151,7 +151,7 @@ QueryPartDef.register({
...
@@ -151,7 +151,7 @@ QueryPartDef.register({
type
:
'field'
,
type
:
'field'
,
addStrategy
:
addFieldStrategy
,
addStrategy
:
addFieldStrategy
,
category
:
categories
.
Fields
,
category
:
categories
.
Fields
,
params
:
[{
type
:
'field'
}],
params
:
[{
type
:
'field'
,
dynamicLookup
:
true
}],
defaultParams
:
[
'value'
],
defaultParams
:
[
'value'
],
renderer
:
fieldRenderer
,
renderer
:
fieldRenderer
,
});
});
...
@@ -202,7 +202,7 @@ QueryPartDef.register({
...
@@ -202,7 +202,7 @@ QueryPartDef.register({
QueryPartDef
.
register
({
QueryPartDef
.
register
({
type
:
'tag'
,
type
:
'tag'
,
category
:
groupByTimeFunctions
,
category
:
groupByTimeFunctions
,
params
:
[{
name
:
'tag'
,
type
:
'string'
}],
params
:
[{
name
:
'tag'
,
type
:
'string'
,
dynamicLookup
:
true
}],
defaultParams
:
[
'tag'
],
defaultParams
:
[
'tag'
],
renderer
:
fieldRenderer
,
renderer
:
fieldRenderer
,
});
});
...
...
public/app/plugins/datasource/influxdb/query_part_editor.js
View file @
721b37a0
...
@@ -19,6 +19,7 @@ function (angular, _, $) {
...
@@ -19,6 +19,7 @@ function (angular, _, $) {
part
:
"="
,
part
:
"="
,
removeAction
:
"&"
,
removeAction
:
"&"
,
partUpdated
:
"&"
,
partUpdated
:
"&"
,
getOptions
:
"&"
,
},
},
link
:
function
postLink
(
$scope
,
elem
)
{
link
:
function
postLink
(
$scope
,
elem
)
{
var
part
=
$scope
.
part
;
var
part
=
$scope
.
part
;
...
@@ -75,18 +76,32 @@ function (angular, _, $) {
...
@@ -75,18 +76,32 @@ function (angular, _, $) {
this
.
style
.
width
=
(
3
+
this
.
value
.
length
)
*
8
+
'px'
;
this
.
style
.
width
=
(
3
+
this
.
value
.
length
)
*
8
+
'px'
;
}
}
function
addTypeahead
(
$input
,
paramIndex
)
{
function
addTypeahead
(
$input
,
param
,
paramIndex
)
{
$input
.
attr
(
'data-provide'
,
'typeahead'
);
if
(
!
param
.
options
&&
!
param
.
dynamicLookup
)
{
return
;
}
var
typeaheadSource
=
function
(
query
,
callback
)
{
if
(
param
.
options
)
{
return
param
.
options
;
}
var
options
=
partDef
.
params
[
paramIndex
].
options
;
$scope
.
$apply
(
function
()
{
if
(
partDef
.
params
[
paramIndex
].
type
===
'int'
)
{
$scope
.
getOptions
().
then
(
function
(
result
)
{
var
dynamicOptions
=
_
.
map
(
result
,
function
(
op
)
{
return
op
.
value
;
});
callback
(
dynamicOptions
);
});
});
};
$input
.
attr
(
'data-provide'
,
'typeahead'
);
var
options
=
param
.
options
;
if
(
param
.
type
===
'int'
)
{
options
=
_
.
map
(
options
,
function
(
val
)
{
return
val
.
toString
();
});
options
=
_
.
map
(
options
,
function
(
val
)
{
return
val
.
toString
();
});
}
}
$input
.
typeahead
({
$input
.
typeahead
({
source
:
options
,
source
:
typeaheadSource
,
minLength
:
0
,
minLength
:
0
,
items
:
2
0
,
items
:
100
0
,
updater
:
function
(
value
)
{
updater
:
function
(
value
)
{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
inputBlur
.
call
(
$input
[
0
],
paramIndex
);
inputBlur
.
call
(
$input
[
0
],
paramIndex
);
...
@@ -98,7 +113,8 @@ function (angular, _, $) {
...
@@ -98,7 +113,8 @@ function (angular, _, $) {
var
typeahead
=
$input
.
data
(
'typeahead'
);
var
typeahead
=
$input
.
data
(
'typeahead'
);
typeahead
.
lookup
=
function
()
{
typeahead
.
lookup
=
function
()
{
this
.
query
=
this
.
$element
.
val
()
||
''
;
this
.
query
=
this
.
$element
.
val
()
||
''
;
return
this
.
process
(
this
.
source
);
var
items
=
this
.
source
(
this
.
query
,
$
.
proxy
(
this
.
process
,
this
));
return
items
?
this
.
process
(
items
)
:
items
;
};
};
}
}
...
@@ -144,9 +160,7 @@ function (angular, _, $) {
...
@@ -144,9 +160,7 @@ function (angular, _, $) {
$input
.
keypress
(
_
.
partial
(
inputKeyPress
,
index
));
$input
.
keypress
(
_
.
partial
(
inputKeyPress
,
index
));
$paramLink
.
click
(
_
.
partial
(
clickFuncParam
,
index
));
$paramLink
.
click
(
_
.
partial
(
clickFuncParam
,
index
));
if
(
partDef
.
params
[
index
].
options
)
{
addTypeahead
(
$input
,
param
,
index
);
addTypeahead
(
$input
,
index
);
}
});
});
}
}
...
...
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