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
685a2fec
Commit
685a2fec
authored
Aug 28, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trying to get new templating / filtering to work
parent
f9cd4a44
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
29 additions
and
34 deletions
+29
-34
src/app/controllers/graphiteTarget.js
+3
-3
src/app/controllers/templateEditorCtrl.js
+4
-2
src/app/directives/templateParamSelector.js
+2
-5
src/app/partials/templating_editor.html
+1
-11
src/app/services/elasticsearch/es-datasource.js
+3
-3
src/app/services/templateSrv.js
+5
-2
src/css/less/variables.dark.less
+1
-1
src/test/specs/helpers.js
+8
-0
src/test/specs/templateSrv-specs.js
+2
-7
No files found.
src/app/controllers/graphiteTarget.js
View file @
685a2fec
...
@@ -10,7 +10,7 @@ function (angular, _, config, gfunc, Parser) {
...
@@ -10,7 +10,7 @@ function (angular, _, config, gfunc, Parser) {
var
module
=
angular
.
module
(
'grafana.controllers'
);
var
module
=
angular
.
module
(
'grafana.controllers'
);
module
.
controller
(
'GraphiteTargetCtrl'
,
function
(
$scope
,
$sce
)
{
module
.
controller
(
'GraphiteTargetCtrl'
,
function
(
$scope
,
$sce
,
templateSrv
)
{
$scope
.
init
=
function
()
{
$scope
.
init
=
function
()
{
$scope
.
target
.
target
=
$scope
.
target
.
target
||
''
;
$scope
.
target
.
target
=
$scope
.
target
.
target
||
''
;
...
@@ -153,10 +153,10 @@ function (angular, _, config, gfunc, Parser) {
...
@@ -153,10 +153,10 @@ function (angular, _, config, gfunc, Parser) {
return
new
MetricSegment
({
value
:
segment
.
text
,
expandable
:
segment
.
expandable
});
return
new
MetricSegment
({
value
:
segment
.
text
,
expandable
:
segment
.
expandable
});
});
});
_
.
each
(
$scope
.
filter
.
templateParameters
,
function
(
templateParameter
)
{
_
.
each
(
templateSrv
.
variables
,
function
(
variable
)
{
$scope
.
altSegments
.
unshift
(
new
MetricSegment
({
$scope
.
altSegments
.
unshift
(
new
MetricSegment
({
type
:
'template'
,
type
:
'template'
,
value
:
'[['
+
templateParameter
.
name
+
']]'
,
value
:
'[['
+
variable
.
name
+
']]'
,
expandable
:
true
,
expandable
:
true
,
}));
}));
});
});
...
...
src/app/controllers/templateEditorCtrl.js
View file @
685a2fec
...
@@ -74,8 +74,10 @@ function (angular, _) {
...
@@ -74,8 +74,10 @@ function (angular, _) {
$scope
.
typeChanged
=
function
()
{
$scope
.
typeChanged
=
function
()
{
if
(
$scope
.
current
.
type
===
'time period'
)
{
if
(
$scope
.
current
.
type
===
'time period'
)
{
$scope
.
current
.
query
=
'auto,1m,10m,30m,1h,6h,12h,1d,7d,14d,30d'
;
$scope
.
current
.
query
=
'1m,10m,30m,1h,6h,12h,1d,7d,14d,30d'
;
$scope
.
current
.
auto_count
=
10
;
}
else
{
$scope
.
current
.
query
=
''
;
}
}
};
};
...
...
src/app/directives/templateParamSelector.js
View file @
685a2fec
...
@@ -21,9 +21,6 @@ function (angular, app, _, $) {
...
@@ -21,9 +21,6 @@ function (angular, app, _, $) {
var
$input
=
$
(
inputTemplate
);
var
$input
=
$
(
inputTemplate
);
var
$button
=
$
(
buttonTemplate
);
var
$button
=
$
(
buttonTemplate
);
var
variable
=
$scope
.
variable
;
var
variable
=
$scope
.
variable
;
var
options
=
_
.
map
(
variable
.
options
,
function
(
option
)
{
return
option
.
text
;
});
$input
.
appendTo
(
elem
);
$input
.
appendTo
(
elem
);
$button
.
appendTo
(
elem
);
$button
.
appendTo
(
elem
);
...
@@ -40,7 +37,6 @@ function (angular, app, _, $) {
...
@@ -40,7 +37,6 @@ function (angular, app, _, $) {
$input
.
attr
(
'data-provide'
,
'typeahead'
);
$input
.
attr
(
'data-provide'
,
'typeahead'
);
$input
.
typeahead
({
$input
.
typeahead
({
source
:
options
,
minLength
:
0
,
minLength
:
0
,
items
:
10
,
items
:
10
,
updater
:
function
(
value
)
{
updater
:
function
(
value
)
{
...
@@ -52,8 +48,9 @@ function (angular, app, _, $) {
...
@@ -52,8 +48,9 @@ function (angular, app, _, $) {
var
typeahead
=
$input
.
data
(
'typeahead'
);
var
typeahead
=
$input
.
data
(
'typeahead'
);
typeahead
.
lookup
=
function
()
{
typeahead
.
lookup
=
function
()
{
var
options
=
_
.
map
(
variable
.
options
,
function
(
option
)
{
return
option
.
text
;
});
this
.
query
=
this
.
$element
.
val
()
||
''
;
this
.
query
=
this
.
$element
.
val
()
||
''
;
return
this
.
process
(
this
.
source
);
return
this
.
process
(
options
);
};
};
$button
.
click
(
function
()
{
$button
.
click
(
function
()
{
...
...
src/app/partials/templating_editor.html
View file @
685a2fec
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
</div>
</div>
<div
ng-model=
"editor.index"
bs-tabs
style=
"text-transform:capitalize;"
>
<div
ng-model=
"editor.index"
bs-tabs
style=
"text-transform:capitalize;"
>
<div
ng-repeat=
"tab in ['
Overview
', 'Add', 'Edit']"
data-title=
"{{tab}}"
>
<div
ng-repeat=
"tab in ['
Variables
', 'Add', 'Edit']"
data-title=
"{{tab}}"
>
</div>
</div>
</div>
</div>
...
@@ -71,16 +71,6 @@
...
@@ -71,16 +71,6 @@
<label
class=
"small"
>
Values
</label>
<label
class=
"small"
>
Values
</label>
<input
type=
"text"
class=
"input-xxlarge"
ng-model=
'current.query'
placeholder=
"name"
></input>
<input
type=
"text"
class=
"input-xxlarge"
ng-model=
'current.query'
placeholder=
"name"
></input>
</div>
</div>
<div
class=
"editor-option"
>
<label
class=
"small"
>
Auto period count
<tip>
The number you want to divide the time range in
</tip></label>
<select
class=
"input-small"
ng-model=
"current.auto_count"
ng-options=
"f for f in [5,6,7,8,9,10,15,20,30,40,50,70,90,100]"
></select>
</div>
<p
class=
"small"
>
<br>
<i
class=
"icon-info-sign"
></i>
This special type of template replacement is useful as the auto word will be calculated depending on the time range divided by
the number of periods you wish.
</p>
</div>
</div>
<div
ng-show=
"current.type === 'query'"
>
<div
ng-show=
"current.type === 'query'"
>
...
...
src/app/services/elasticsearch/es-datasource.js
View file @
685a2fec
...
@@ -11,7 +11,7 @@ function (angular, _, $, config, kbn, moment) {
...
@@ -11,7 +11,7 @@ function (angular, _, $, config, kbn, moment) {
var
module
=
angular
.
module
(
'grafana.services'
);
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
factory
(
'ElasticDatasource'
,
function
(
$q
,
$http
)
{
module
.
factory
(
'ElasticDatasource'
,
function
(
$q
,
$http
,
templateSrv
)
{
function
ElasticDatasource
(
datasource
)
{
function
ElasticDatasource
(
datasource
)
{
this
.
type
=
'elastic'
;
this
.
type
=
'elastic'
;
...
@@ -60,7 +60,7 @@ function (angular, _, $, config, kbn, moment) {
...
@@ -60,7 +60,7 @@ function (angular, _, $, config, kbn, moment) {
});
});
};
};
ElasticDatasource
.
prototype
.
annotationQuery
=
function
(
annotation
,
filterSrv
,
rangeUnparsed
)
{
ElasticDatasource
.
prototype
.
annotationQuery
=
function
(
annotation
,
rangeUnparsed
)
{
var
range
=
{};
var
range
=
{};
var
timeField
=
annotation
.
timeField
||
'@timestamp'
;
var
timeField
=
annotation
.
timeField
||
'@timestamp'
;
var
queryString
=
annotation
.
query
||
'*'
;
var
queryString
=
annotation
.
query
||
'*'
;
...
@@ -73,7 +73,7 @@ function (angular, _, $, config, kbn, moment) {
...
@@ -73,7 +73,7 @@ function (angular, _, $, config, kbn, moment) {
to
:
rangeUnparsed
.
to
,
to
:
rangeUnparsed
.
to
,
};
};
var
queryInterpolated
=
filterSrv
.
applyTemplateToTarget
(
queryString
);
var
queryInterpolated
=
templateSrv
.
replace
(
queryString
);
var
filter
=
{
"bool"
:
{
"must"
:
[{
"range"
:
range
}]
}
};
var
filter
=
{
"bool"
:
{
"must"
:
[{
"range"
:
range
}]
}
};
var
query
=
{
"bool"
:
{
"should"
:
[{
"query_string"
:
{
"query"
:
queryInterpolated
}
}]
}
};
var
query
=
{
"bool"
:
{
"should"
:
[{
"query_string"
:
{
"query"
:
queryInterpolated
}
}]
}
};
var
data
=
{
"query"
:
{
"filtered"
:
{
"query"
:
query
,
"filter"
:
filter
}
},
"size"
:
100
};
var
data
=
{
"query"
:
{
"filtered"
:
{
"query"
:
query
,
"filter"
:
filter
}
},
"size"
:
100
};
...
...
src/app/services/templateSrv.js
View file @
685a2fec
...
@@ -2,14 +2,15 @@ define([
...
@@ -2,14 +2,15 @@ define([
'angular'
,
'angular'
,
'lodash'
,
'lodash'
,
'kbn'
,
'kbn'
,
'
store
'
'
config
'
],
],
function
(
angular
,
_
)
{
function
(
angular
,
_
,
kbn
,
config
)
{
'use strict'
;
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
service
(
'templateSrv'
,
function
(
$q
,
$routeParams
)
{
module
.
service
(
'templateSrv'
,
function
(
$q
,
$routeParams
)
{
var
self
=
this
;
this
.
init
=
function
(
variables
)
{
this
.
init
=
function
(
variables
)
{
this
.
templateSettings
=
{
interpolate
:
/
\[\[([\s\S]
+
?)\]\]
/g
};
this
.
templateSettings
=
{
interpolate
:
/
\[\[([\s\S]
+
?)\]\]
/g
};
...
@@ -29,7 +30,9 @@ function (angular, _) {
...
@@ -29,7 +30,9 @@ function (angular, _) {
if
(
!
variable
.
current
||
!
variable
.
current
.
value
)
{
if
(
!
variable
.
current
||
!
variable
.
current
.
value
)
{
return
;
return
;
}
}
_templateData
[
variable
.
name
]
=
variable
.
current
.
value
;
_templateData
[
variable
.
name
]
=
variable
.
current
.
value
;
});
});
this
.
_templateData
=
_templateData
;
this
.
_templateData
=
_templateData
;
};
};
...
...
src/css/less/variables.dark.less
View file @
685a2fec
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
// -------------------------
// -------------------------
@black: #000;
@black: #000;
@gray: #bbb;
@gray: #bbb;
@grayDark: #2
42424
;
@grayDark: #2
62626
;
@grayDarker: #1f1f1f;
@grayDarker: #1f1f1f;
@grayLight: #ADAFAE;
@grayLight: #ADAFAE;
...
...
src/test/specs/helpers.js
View file @
685a2fec
...
@@ -9,6 +9,7 @@ define([
...
@@ -9,6 +9,7 @@ define([
this
.
datasource
=
{};
this
.
datasource
=
{};
this
.
annotationsSrv
=
{};
this
.
annotationsSrv
=
{};
this
.
timeSrv
=
new
TimeSrvStub
();
this
.
timeSrv
=
new
TimeSrvStub
();
this
.
templateSrv
=
new
TemplateSrvStub
();
this
.
datasourceSrv
=
{
this
.
datasourceSrv
=
{
getMetricSources
:
function
()
{},
getMetricSources
:
function
()
{},
get
:
function
()
{
return
self
.
datasource
;
}
get
:
function
()
{
return
self
.
datasource
;
}
...
@@ -19,6 +20,7 @@ define([
...
@@ -19,6 +20,7 @@ define([
$provide
.
value
(
'datasourceSrv'
,
self
.
datasourceSrv
);
$provide
.
value
(
'datasourceSrv'
,
self
.
datasourceSrv
);
$provide
.
value
(
'annotationsSrv'
,
self
.
annotationsSrv
);
$provide
.
value
(
'annotationsSrv'
,
self
.
annotationsSrv
);
$provide
.
value
(
'timeSrv'
,
self
.
timeSrv
);
$provide
.
value
(
'timeSrv'
,
self
.
timeSrv
);
$provide
.
value
(
'templateSrv'
,
self
.
templateSrv
);
});
});
};
};
...
@@ -78,6 +80,12 @@ define([
...
@@ -78,6 +80,12 @@ define([
};
};
}
}
function
TemplateSrvStub
()
{
this
.
variables
=
[];
this
.
replace
=
function
()
{};
}
return
{
return
{
ControllerTestContext
:
ControllerTestContext
,
ControllerTestContext
:
ControllerTestContext
,
...
...
src/test/specs/templateSrv-specs.js
View file @
685a2fec
...
@@ -29,14 +29,9 @@ define([
...
@@ -29,14 +29,9 @@ define([
});
});
});
});
describe
(
'updateTemplateData'
,
function
()
{
describe
(
'updateTemplateData
with simple value
'
,
function
()
{
beforeEach
(
function
()
{
beforeEach
(
function
()
{
_templateSrv
.
init
([{
_templateSrv
.
init
([{
name
:
'test'
,
current
:
{
value
:
'muuuu'
}
}]);
name
:
'test'
,
value
:
'muuu'
,
current
:
{
value
:
'muuuu'
}
}]);
_templateSrv
.
updateTemplateData
();
_templateSrv
.
updateTemplateData
();
});
});
...
...
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