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
1929490d
Commit
1929490d
authored
Aug 27, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed filterSrv to timeSrv and made it a service again
parent
bb3b3182
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
89 additions
and
92 deletions
+89
-92
src/app/controllers/dashboardCtrl.js
+2
-3
src/app/controllers/dashboardNavCtrl.js
+3
-3
src/app/controllers/graphiteTarget.js
+2
-2
src/app/directives/grafanaGraph.js
+2
-2
src/app/panels/graph/module.js
+5
-5
src/app/panels/text/module.js
+0
-1
src/app/panels/timepicker/module.html
+1
-2
src/app/panels/timepicker/module.js
+8
-8
src/app/services/all.js
+1
-1
src/app/services/annotationsSrv.js
+2
-2
src/app/services/graphite/graphiteDatasource.js
+11
-11
src/app/services/influxdb/influxdbDatasource.js
+4
-4
src/app/services/timeSrv.js
+19
-22
src/test/specs/grafanaGraph-specs.js
+3
-0
src/test/specs/graphiteTargetCtrl-specs.js
+1
-1
src/test/specs/helpers.js
+4
-4
src/test/specs/influxdb-datasource-specs.js
+2
-2
src/test/specs/timeSrv-specs.js
+18
-18
src/test/test-main.js
+1
-1
No files found.
src/app/controllers/dashboardCtrl.js
View file @
1929490d
...
...
@@ -14,7 +14,7 @@ function (angular, $, config, _) {
$scope
,
$rootScope
,
dashboardKeybindings
,
filter
Srv
,
time
Srv
,
templateSrv
,
dashboardSrv
,
dashboardViewStateSrv
,
...
...
@@ -52,8 +52,7 @@ function (angular, $, config, _) {
$scope
.
grafana
.
style
=
$scope
.
dashboard
.
style
;
$scope
.
filter
=
filterSrv
;
$scope
.
filter
.
init
(
$scope
.
dashboard
);
timeSrv
.
init
(
$scope
.
dashboard
);
templateSrv
.
init
(
$scope
.
dashboard
);
$scope
.
submenuEnabled
=
$scope
.
dashboard
.
templating
.
enable
||
$scope
.
dashboard
.
annotations
.
enable
;
...
...
src/app/controllers/dashboardNavCtrl.js
View file @
1929490d
...
...
@@ -11,7 +11,7 @@ function (angular, _, moment, config, store) {
var
module
=
angular
.
module
(
'grafana.controllers'
);
module
.
controller
(
'DashboardNavCtrl'
,
function
(
$scope
,
$rootScope
,
alertSrv
,
$location
,
playlistSrv
,
datasourceSrv
)
{
module
.
controller
(
'DashboardNavCtrl'
,
function
(
$scope
,
$rootScope
,
alertSrv
,
$location
,
playlistSrv
,
datasourceSrv
,
timeSrv
)
{
$scope
.
init
=
function
()
{
$scope
.
db
=
datasourceSrv
.
getGrafanaDB
();
...
...
@@ -114,7 +114,7 @@ function (angular, _, moment, config, store) {
// function $scope.zoom
// factor :: Zoom factor, so 0.5 = cuts timespan in half, 2 doubles timespan
$scope
.
zoom
=
function
(
factor
)
{
var
_range
=
$scope
.
filter
.
timeRange
();
var
_range
=
timeSrv
.
timeRange
();
var
_timespan
=
(
_range
.
to
.
valueOf
()
-
_range
.
from
.
valueOf
());
var
_center
=
_range
.
to
.
valueOf
()
-
_timespan
/
2
;
...
...
@@ -128,7 +128,7 @@ function (angular, _, moment, config, store) {
_to
=
Date
.
now
();
}
$scope
.
filter
.
setTime
({
timeSrv
.
setTime
({
from
:
moment
.
utc
(
_from
).
toDate
(),
to
:
moment
.
utc
(
_to
).
toDate
(),
});
...
...
src/app/controllers/graphiteTarget.js
View file @
1929490d
...
...
@@ -110,7 +110,7 @@ function (angular, _, config, gfunc, Parser) {
}
var
path
=
getSegmentPathUpTo
(
fromIndex
+
1
);
return
$scope
.
datasource
.
metricFindQuery
(
$scope
.
filter
,
path
)
return
$scope
.
datasource
.
metricFindQuery
(
path
)
.
then
(
function
(
segments
)
{
if
(
segments
.
length
===
0
)
{
$scope
.
segments
=
$scope
.
segments
.
splice
(
0
,
fromIndex
);
...
...
@@ -147,7 +147,7 @@ function (angular, _, config, gfunc, Parser) {
var
query
=
index
===
0
?
'*'
:
getSegmentPathUpTo
(
index
)
+
'.*'
;
return
$scope
.
datasource
.
metricFindQuery
(
$scope
.
filter
,
query
)
return
$scope
.
datasource
.
metricFindQuery
(
query
)
.
then
(
function
(
segments
)
{
$scope
.
altSegments
=
_
.
map
(
segments
,
function
(
segment
)
{
return
new
MetricSegment
({
value
:
segment
.
text
,
expandable
:
segment
.
expandable
});
...
...
src/app/directives/grafanaGraph.js
View file @
1929490d
...
...
@@ -10,7 +10,7 @@ function (angular, $, kbn, moment, _) {
var
module
=
angular
.
module
(
'grafana.directives'
);
module
.
directive
(
'grafanaGraph'
,
function
(
$rootScope
)
{
module
.
directive
(
'grafanaGraph'
,
function
(
$rootScope
,
timeSrv
)
{
return
{
restrict
:
'A'
,
template
:
'<div> </div>'
,
...
...
@@ -416,7 +416,7 @@ function (angular, $, kbn, moment, _) {
elem
.
bind
(
"plotselected"
,
function
(
event
,
ranges
)
{
scope
.
$apply
(
function
()
{
scope
.
filter
.
setTime
({
timeSrv
.
setTime
({
from
:
moment
.
utc
(
ranges
.
xaxis
.
from
).
toDate
(),
to
:
moment
.
utc
(
ranges
.
xaxis
.
to
).
toDate
(),
});
...
...
src/app/panels/graph/module.js
View file @
1929490d
...
...
@@ -23,7 +23,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
var
module
=
angular
.
module
(
'grafana.panels.graph'
);
app
.
useModule
(
module
);
module
.
controller
(
'GraphCtrl'
,
function
(
$scope
,
$rootScope
,
$timeout
,
panelSrv
,
annotations
Srv
)
{
module
.
controller
(
'GraphCtrl'
,
function
(
$scope
,
$rootScope
,
panelSrv
,
annotationsSrv
,
time
Srv
)
{
$scope
.
panelMeta
=
{
modals
:
[],
...
...
@@ -179,8 +179,8 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
$scope
.
hiddenSeries
=
{};
$scope
.
updateTimeRange
=
function
()
{
$scope
.
range
=
$scope
.
filter
.
timeRange
();
$scope
.
rangeUnparsed
=
$scope
.
filter
.
timeRange
(
false
);
$scope
.
range
=
timeSrv
.
timeRange
();
$scope
.
rangeUnparsed
=
timeSrv
.
timeRange
(
false
);
$scope
.
resolution
=
Math
.
ceil
(
$
(
window
).
width
()
*
(
$scope
.
panel
.
span
/
12
));
$scope
.
interval
=
'10m'
;
...
...
@@ -203,9 +203,9 @@ function (angular, app, $, _, kbn, moment, TimeSeries) {
cacheTimeout
:
$scope
.
panel
.
cacheTimeout
};
$scope
.
annotationsPromise
=
annotationsSrv
.
getAnnotations
(
$scope
.
filter
,
$scope
.
rangeUnparsed
,
$scope
.
dashboard
);
$scope
.
annotationsPromise
=
annotationsSrv
.
getAnnotations
(
$scope
.
rangeUnparsed
,
$scope
.
dashboard
);
return
$scope
.
datasource
.
query
(
$scope
.
filter
,
metricsQuery
)
return
$scope
.
datasource
.
query
(
metricsQuery
)
.
then
(
$scope
.
dataHandler
)
.
then
(
null
,
function
(
err
)
{
$scope
.
panelMeta
.
loading
=
false
;
...
...
src/app/panels/text/module.js
View file @
1929490d
...
...
@@ -3,7 +3,6 @@ define([
'app'
,
'lodash'
,
'require'
,
'services/filterSrv'
],
function
(
angular
,
app
,
_
,
require
)
{
'use strict'
;
...
...
src/app/panels/timepicker/module.html
View file @
1929490d
...
...
@@ -16,8 +16,7 @@
<li
class=
"dropdown"
>
<a
class=
"dropdown-toggle timepicker-dropdown"
data-toggle=
"dropdown"
href=
""
bs-tooltip=
"time.tooltip"
data-placement=
"bottom"
ng-click=
"dismiss();"
>
<span
ng-show=
"filter.time"
ng-bind=
"time.rangeString"
></span>
<span
ng-hide=
"filter.time"
>
Time filter
</span>
<span
ng-bind=
"time.rangeString"
></span>
<span
ng-show=
"dashboard.refresh"
class=
"text-warning"
>
refreshed every {{dashboard.refresh}}
</span>
<i
class=
"icon-caret-down"
></i>
</a>
...
...
src/app/panels/timepicker/module.js
View file @
1929490d
...
...
@@ -25,11 +25,11 @@ function (angular, app, _, moment, kbn) {
var
module
=
angular
.
module
(
'grafana.panels.timepicker'
,
[]);
app
.
useModule
(
module
);
module
.
controller
(
'timepicker'
,
function
(
$scope
)
{
module
.
controller
(
'timepicker'
,
function
(
$scope
,
timeSrv
)
{
$scope
.
panelMeta
=
{
status
:
"Stable"
,
description
:
"A panel for controlling the time range filters. If you have time based data, "
+
" or if you're using time stamped indices, you need one of these"
description
:
""
};
// Set and populate defaults
...
...
@@ -55,9 +55,9 @@ function (angular, app, _, moment, kbn) {
});
$scope
.
init
=
function
()
{
var
time
=
t
his
.
filter
.
timeRange
(
true
);
var
time
=
t
imeSrv
.
timeRange
(
true
);
if
(
time
)
{
$scope
.
panel
.
now
=
t
his
.
filter
.
timeRange
(
false
).
to
===
"now"
?
true
:
false
;
$scope
.
panel
.
now
=
t
imeSrv
.
timeRange
(
false
).
to
===
"now"
?
true
:
false
;
$scope
.
time
=
getScopeTimeObj
(
time
.
from
,
time
.
to
);
}
};
...
...
@@ -126,7 +126,7 @@ function (angular, app, _, moment, kbn) {
}
// Set the filter
$scope
.
panel
.
filter_id
=
$scope
.
filter
.
setTime
(
_filter
);
$scope
.
panel
.
filter_id
=
timeSrv
.
setTime
(
_filter
);
// Update our representation
$scope
.
time
=
getScopeTimeObj
(
time
.
from
,
time
.
to
);
...
...
@@ -140,7 +140,7 @@ function (angular, app, _, moment, kbn) {
to
:
"now"
};
t
his
.
filter
.
setTime
(
_filter
);
t
imeSrv
.
setTime
(
_filter
);
$scope
.
time
=
getScopeTimeObj
(
kbn
.
parseDate
(
_filter
.
from
),
new
Date
());
};
...
...
@@ -173,7 +173,7 @@ function (angular, app, _, moment, kbn) {
model
.
tooltip
=
'Click to set time filter'
;
}
if
(
$scope
.
filter
.
time
)
{
if
(
timeSrv
.
time
)
{
if
(
$scope
.
panel
.
now
)
{
model
.
rangeString
=
moment
(
model
.
from
.
date
).
fromNow
()
+
' to '
+
moment
(
model
.
to
.
date
).
fromNow
();
...
...
src/app/services/all.js
View file @
1929490d
define
([
'./alertSrv'
,
'./datasourceSrv'
,
'./
filter
Srv'
,
'./
time
Srv'
,
'./templateSrv'
,
'./panelSrv'
,
'./timer'
,
...
...
src/app/services/annotationsSrv.js
View file @
1929490d
...
...
@@ -21,7 +21,7 @@ define([
list
=
[];
};
this
.
getAnnotations
=
function
(
filterSrv
,
rangeUnparsed
,
dashboard
)
{
this
.
getAnnotations
=
function
(
rangeUnparsed
,
dashboard
)
{
if
(
!
dashboard
.
annotations
.
enable
)
{
return
$q
.
when
(
null
);
}
...
...
@@ -36,7 +36,7 @@ define([
var
promises
=
_
.
map
(
annotations
,
function
(
annotation
)
{
var
datasource
=
datasourceSrv
.
get
(
annotation
.
datasource
);
return
datasource
.
annotationQuery
(
annotation
,
filterSrv
,
rangeUnparsed
)
return
datasource
.
annotationQuery
(
annotation
,
rangeUnparsed
)
.
then
(
this
.
receiveAnnotationResults
)
.
then
(
null
,
errorHandler
);
},
this
);
...
...
src/app/services/graphite/graphiteDatasource.js
View file @
1929490d
...
...
@@ -11,7 +11,7 @@ function (angular, _, $, config, kbn, moment) {
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
factory
(
'GraphiteDatasource'
,
function
(
$q
,
$http
)
{
module
.
factory
(
'GraphiteDatasource'
,
function
(
$q
,
$http
,
timeSrv
)
{
function
GraphiteDatasource
(
datasource
)
{
this
.
type
=
'graphite'
;
...
...
@@ -26,7 +26,7 @@ function (angular, _, $, config, kbn, moment) {
this
.
cacheTimeout
=
datasource
.
cacheTimeout
;
}
GraphiteDatasource
.
prototype
.
query
=
function
(
filterSrv
,
options
)
{
GraphiteDatasource
.
prototype
.
query
=
function
(
options
)
{
try
{
var
graphOptions
=
{
from
:
this
.
translateTime
(
options
.
range
.
from
,
'round-down'
),
...
...
@@ -37,7 +37,7 @@ function (angular, _, $, config, kbn, moment) {
maxDataPoints
:
options
.
maxDataPoints
,
};
var
params
=
this
.
buildGraphiteParams
(
filterSrv
,
graphOptions
);
var
params
=
this
.
buildGraphiteParams
(
graphOptions
);
if
(
options
.
format
===
'png'
)
{
return
$q
.
when
(
this
.
url
+
'/render'
+
'?'
+
params
.
join
(
'&'
));
...
...
@@ -60,10 +60,10 @@ function (angular, _, $, config, kbn, moment) {
}
};
GraphiteDatasource
.
prototype
.
annotationQuery
=
function
(
annotation
,
filterSrv
,
rangeUnparsed
)
{
GraphiteDatasource
.
prototype
.
annotationQuery
=
function
(
annotation
,
rangeUnparsed
)
{
// Graphite metric as annotation
if
(
annotation
.
target
)
{
var
target
=
filter
Srv
.
applyTemplateToTarget
(
annotation
.
target
);
var
target
=
time
Srv
.
applyTemplateToTarget
(
annotation
.
target
);
var
graphiteQuery
=
{
range
:
rangeUnparsed
,
targets
:
[{
target
:
target
}],
...
...
@@ -71,7 +71,7 @@ function (angular, _, $, config, kbn, moment) {
maxDataPoints
:
100
};
return
this
.
query
(
filter
Srv
,
graphiteQuery
)
return
this
.
query
(
time
Srv
,
graphiteQuery
)
.
then
(
function
(
result
)
{
var
list
=
[];
...
...
@@ -95,7 +95,7 @@ function (angular, _, $, config, kbn, moment) {
}
// Graphite event as annotation
else
{
var
tags
=
filter
Srv
.
applyTemplateToTarget
(
annotation
.
tags
);
var
tags
=
time
Srv
.
applyTemplateToTarget
(
annotation
.
tags
);
return
this
.
events
({
range
:
rangeUnparsed
,
tags
:
tags
})
.
then
(
function
(
results
)
{
var
list
=
[];
...
...
@@ -166,10 +166,10 @@ function (angular, _, $, config, kbn, moment) {
return
date
.
unix
();
};
GraphiteDatasource
.
prototype
.
metricFindQuery
=
function
(
filterSrv
,
query
)
{
GraphiteDatasource
.
prototype
.
metricFindQuery
=
function
(
query
)
{
var
interpolated
;
try
{
interpolated
=
encodeURIComponent
(
filter
Srv
.
applyTemplateToTarget
(
query
));
interpolated
=
encodeURIComponent
(
time
Srv
.
applyTemplateToTarget
(
query
));
}
catch
(
err
)
{
return
$q
.
reject
(
err
);
...
...
@@ -210,7 +210,7 @@ function (angular, _, $, config, kbn, moment) {
return
$http
(
options
);
};
GraphiteDatasource
.
prototype
.
buildGraphiteParams
=
function
(
filterSrv
,
options
)
{
GraphiteDatasource
.
prototype
.
buildGraphiteParams
=
function
(
options
)
{
var
clean_options
=
[];
var
graphite_options
=
[
'target'
,
'targets'
,
'from'
,
'until'
,
'rawData'
,
'format'
,
'maxDataPoints'
,
'cacheTimeout'
];
...
...
@@ -226,7 +226,7 @@ function (angular, _, $, config, kbn, moment) {
if
(
key
===
"targets"
)
{
_
.
each
(
value
,
function
(
value
)
{
if
(
value
.
target
&&
!
value
.
hide
)
{
var
targetValue
=
filter
Srv
.
applyTemplateToTarget
(
value
.
target
);
var
targetValue
=
time
Srv
.
applyTemplateToTarget
(
value
.
target
);
clean_options
.
push
(
"target="
+
encodeURIComponent
(
targetValue
));
}
},
this
);
...
...
src/app/services/influxdb/influxdbDatasource.js
View file @
1929490d
...
...
@@ -9,7 +9,7 @@ function (angular, _, kbn, InfluxSeries) {
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
factory
(
'InfluxDatasource'
,
function
(
$q
,
$http
)
{
module
.
factory
(
'InfluxDatasource'
,
function
(
$q
,
$http
,
timeSrv
)
{
function
InfluxDatasource
(
datasource
)
{
this
.
type
=
'influxDB'
;
...
...
@@ -31,7 +31,7 @@ function (angular, _, kbn, InfluxSeries) {
this
.
annotationEditorSrc
=
'app/partials/influxdb/annotation_editor.html'
;
}
InfluxDatasource
.
prototype
.
query
=
function
(
filterSrv
,
options
)
{
InfluxDatasource
.
prototype
.
query
=
function
(
options
)
{
var
promises
=
_
.
map
(
options
.
targets
,
function
(
target
)
{
var
query
;
var
alias
=
''
;
...
...
@@ -73,7 +73,7 @@ function (angular, _, kbn, InfluxSeries) {
}
query
=
queryElements
.
join
(
" "
);
query
=
filter
Srv
.
applyTemplateToTarget
(
query
);
query
=
time
Srv
.
applyTemplateToTarget
(
query
);
}
else
{
...
...
@@ -100,7 +100,7 @@ function (angular, _, kbn, InfluxSeries) {
}
query
=
_
.
template
(
template
,
templateData
,
this
.
templateSettings
);
query
=
filter
Srv
.
applyTemplateToTarget
(
query
);
query
=
time
Srv
.
applyTemplateToTarget
(
query
);
if
(
target
.
groupby_field_add
)
{
groupByField
=
target
.
groupby_field
;
...
...
src/app/services/
filter
Srv.js
→
src/app/services/
time
Srv.js
View file @
1929490d
...
...
@@ -8,10 +8,17 @@ define([
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
factory
(
'filterSrv'
,
function
(
$rootScope
,
$timeout
,
$routeParams
)
{
var
result
=
{
module
.
service
(
'timeSrv'
,
function
(
$rootScope
,
$timeout
,
$routeParams
)
{
updateTemplateData
:
function
(
initial
)
{
this
.
init
=
function
(
dashboard
)
{
this
.
dashboard
=
dashboard
;
this
.
templateSettings
=
{
interpolate
:
/
\[\[([\s\S]
+
?)\]\]
/g
};
this
.
time
=
dashboard
.
time
;
this
.
templateParameters
=
dashboard
.
templating
.
list
;
this
.
updateTemplateData
(
true
);
};
this
.
updateTemplateData
=
function
(
initial
)
{
var
_templateData
=
{};
_
.
each
(
this
.
templateParameters
,
function
(
templateParameter
)
{
if
(
initial
)
{
...
...
@@ -26,22 +33,22 @@ define([
_templateData
[
templateParameter
.
name
]
=
templateParameter
.
current
.
value
;
});
this
.
_templateData
=
_templateData
;
}
,
}
;
addTemplateParameter
:
function
(
templateParameter
)
{
this
.
addTemplateParameter
=
function
(
templateParameter
)
{
this
.
templateParameters
.
push
(
templateParameter
);
this
.
updateTemplateData
();
}
,
}
;
applyTemplateToTarget
:
function
(
target
)
{
this
.
applyTemplateToTarget
=
function
(
target
)
{
if
(
!
target
||
target
.
indexOf
(
'[['
)
===
-
1
)
{
return
target
;
}
return
_
.
template
(
target
,
this
.
_templateData
,
this
.
templateSettings
);
}
,
}
;
setTime
:
function
(
time
)
{
this
.
setTime
=
function
(
time
)
{
_
.
extend
(
this
.
time
,
time
);
// disable refresh if we have an absolute time
...
...
@@ -55,9 +62,9 @@ define([
}
$timeout
(
this
.
dashboard
.
emit_refresh
,
0
);
}
,
}
;
t
imeRange
:
function
(
parse
)
{
t
his
.
timeRange
=
function
(
parse
)
{
var
_t
=
this
.
time
;
if
(
_
.
isUndefined
(
_t
)
||
_
.
isUndefined
(
_t
.
from
))
{
return
false
;
...
...
@@ -76,18 +83,8 @@ define([
to
:
kbn
.
parseDate
(
_to
)
};
}
},
init
:
function
(
dashboard
)
{
this
.
dashboard
=
dashboard
;
this
.
templateSettings
=
{
interpolate
:
/
\[\[([\s\S]
+
?)\]\]
/g
};
this
.
time
=
dashboard
.
time
;
this
.
templateParameters
=
dashboard
.
templating
.
list
;
this
.
updateTemplateData
(
true
);
}
};
};
return
result
;
});
});
src/test/specs/grafanaGraph-specs.js
View file @
1929490d
...
...
@@ -15,6 +15,9 @@ define([
describe
(
desc
,
function
()
{
var
ctx
=
{};
ctx
.
setup
=
function
(
setupFunc
)
{
beforeEach
(
module
(
function
(
$provide
)
{
$provide
.
value
(
"timeSrv"
,
new
helpers
.
TimeSrvStub
());
}));
beforeEach
(
inject
(
function
(
$rootScope
,
$compile
)
{
var
scope
=
$rootScope
.
$new
();
var
element
=
angular
.
element
(
"<div style='width:500px' grafana-graph><div>"
);
...
...
src/test/specs/graphiteTargetCtrl-specs.js
View file @
1929490d
...
...
@@ -28,7 +28,7 @@ define([
});
it
(
'should validate metric key exists'
,
function
()
{
expect
(
ctx
.
scope
.
datasource
.
metricFindQuery
.
getCall
(
0
).
args
[
1
]).
to
.
be
(
'test.prod.*'
);
expect
(
ctx
.
scope
.
datasource
.
metricFindQuery
.
getCall
(
0
).
args
[
0
]).
to
.
be
(
'test.prod.*'
);
});
it
(
'should delete last segment if no metrics are found'
,
function
()
{
...
...
src/test/specs/helpers.js
View file @
1929490d
...
...
@@ -8,6 +8,7 @@ define([
this
.
datasource
=
{};
this
.
annotationsSrv
=
{};
this
.
timeSrv
=
new
TimeSrvStub
();
this
.
datasourceSrv
=
{
getMetricSources
:
function
()
{},
get
:
function
()
{
return
self
.
datasource
;
}
...
...
@@ -17,6 +18,7 @@ define([
return
module
(
function
(
$provide
)
{
$provide
.
value
(
'datasourceSrv'
,
self
.
datasourceSrv
);
$provide
.
value
(
'annotationsSrv'
,
self
.
annotationsSrv
);
$provide
.
value
(
'timeSrv'
,
self
.
timeSrv
);
});
};
...
...
@@ -25,7 +27,6 @@ define([
self
.
scope
=
$rootScope
.
$new
();
self
.
scope
.
panel
=
{};
self
.
scope
.
row
=
{
panels
:[]
};
self
.
scope
.
filter
=
new
FilterSrvStub
();
self
.
scope
.
dashboard
=
{};
self
.
scope
.
dashboardViewState
=
new
DashboardViewStateStub
();
...
...
@@ -50,7 +51,6 @@ define([
self
.
service
=
InfluxDatasource
;
self
.
$q
=
$q
;
self
.
$rootScope
=
$rootScope
;
self
.
filterSrv
=
new
FilterSrvStub
();
self
.
$httpBackend
=
$httpBackend
;
}]);
};
...
...
@@ -61,7 +61,7 @@ define([
};
}
function
Filter
SrvStub
()
{
function
Time
SrvStub
()
{
this
.
time
=
{
from
:
'now-1h'
,
to
:
'now'
};
this
.
timeRange
=
function
(
parse
)
{
if
(
parse
===
false
)
{
...
...
@@ -81,7 +81,7 @@ define([
return
{
ControllerTestContext
:
ControllerTestContext
,
FilterSrvStub
:
Filter
SrvStub
,
TimeSrvStub
:
Time
SrvStub
,
ServiceTestContext
:
ServiceTestContext
};
...
...
src/test/specs/influxdb-datasource-specs.js
View file @
1929490d
...
...
@@ -29,7 +29,7 @@ define([
var
ds
=
new
ctx
.
service
({
urls
:
[
''
],
user
:
'test'
,
password
:
'mupp'
});
ctx
.
$httpBackend
.
expect
(
'GET'
,
urlExpected
).
respond
(
response
);
ds
.
query
(
ctx
.
filterSrv
,
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ds
.
query
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
});
...
...
@@ -59,7 +59,7 @@ define([
var
ds
=
new
ctx
.
service
({
urls
:
[
''
],
user
:
'test'
,
password
:
'mupp'
});
ctx
.
$httpBackend
.
expect
(
'GET'
,
urlExpected
).
respond
(
response
);
ds
.
query
(
ctx
.
filterSrv
,
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ds
.
query
(
query
).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
});
...
...
src/test/specs/
filter
Srv-specs.js
→
src/test/specs/
time
Srv-specs.js
View file @
1929490d
define
([
'mocks/dashboard-mock'
,
'lodash'
,
'services/
filter
Srv'
'services/
time
Srv'
],
function
(
dashboardMock
,
_
)
{
'use strict'
;
describe
(
'
filter
Srv'
,
function
()
{
var
_
filter
Srv
;
describe
(
'
time
Srv'
,
function
()
{
var
_
time
Srv
;
var
_dashboard
;
beforeEach
(
module
(
'grafana.services'
));
...
...
@@ -14,52 +14,52 @@ define([
_dashboard
=
dashboardMock
.
create
();
}));
beforeEach
(
inject
(
function
(
filter
Srv
)
{
_
filterSrv
=
filter
Srv
;
beforeEach
(
inject
(
function
(
time
Srv
)
{
_
timeSrv
=
time
Srv
;
}));
beforeEach
(
function
()
{
_
filter
Srv
.
init
(
_dashboard
);
_
time
Srv
.
init
(
_dashboard
);
});
describe
(
'init'
,
function
()
{
beforeEach
(
function
()
{
_
filter
Srv
.
addTemplateParameter
({
name
:
'test'
,
current
:
{
value
:
'oogle'
}
});
_
time
Srv
.
addTemplateParameter
({
name
:
'test'
,
current
:
{
value
:
'oogle'
}
});
});
it
(
'should initialize template data'
,
function
()
{
var
target
=
_
filter
Srv
.
applyTemplateToTarget
(
'this.[[test]].filters'
);
var
target
=
_
time
Srv
.
applyTemplateToTarget
(
'this.[[test]].filters'
);
expect
(
target
).
to
.
be
(
'this.oogle.filters'
);
});
});
describe
(
'updateTemplateData'
,
function
()
{
beforeEach
(
function
()
{
_
filter
Srv
.
addTemplateParameter
({
_
time
Srv
.
addTemplateParameter
({
name
:
'test'
,
value
:
'muuu'
,
current
:
{
value
:
'muuuu'
}
});
_
filter
Srv
.
updateTemplateData
();
_
time
Srv
.
updateTemplateData
();
});
it
(
'should set current value and update template data'
,
function
()
{
var
target
=
_
filter
Srv
.
applyTemplateToTarget
(
'this.[[test]].filters'
);
var
target
=
_
time
Srv
.
applyTemplateToTarget
(
'this.[[test]].filters'
);
expect
(
target
).
to
.
be
(
'this.muuuu.filters'
);
});
});
describe
(
'timeRange'
,
function
()
{
it
(
'should return unparsed when parse is false'
,
function
()
{
_
filter
Srv
.
setTime
({
from
:
'now'
,
to
:
'now-1h'
});
var
time
=
_
filter
Srv
.
timeRange
(
false
);
_
time
Srv
.
setTime
({
from
:
'now'
,
to
:
'now-1h'
});
var
time
=
_
time
Srv
.
timeRange
(
false
);
expect
(
time
.
from
).
to
.
be
(
'now'
);
expect
(
time
.
to
).
to
.
be
(
'now-1h'
);
});
it
(
'should return parsed when parse is true'
,
function
()
{
_
filter
Srv
.
setTime
({
from
:
'now'
,
to
:
'now-1h'
});
var
time
=
_
filter
Srv
.
timeRange
(
true
);
_
time
Srv
.
setTime
({
from
:
'now'
,
to
:
'now-1h'
});
var
time
=
_
time
Srv
.
timeRange
(
true
);
expect
(
_
.
isDate
(
time
.
from
)).
to
.
be
(
true
);
expect
(
_
.
isDate
(
time
.
to
)).
to
.
be
(
true
);
});
...
...
@@ -69,15 +69,15 @@ define([
it
(
'should return disable refresh for absolute times'
,
function
()
{
_dashboard
.
refresh
=
true
;
_
filter
Srv
.
setTime
({
from
:
'2011-01-01'
,
to
:
'2015-01-01'
});
_
time
Srv
.
setTime
({
from
:
'2011-01-01'
,
to
:
'2015-01-01'
});
expect
(
_dashboard
.
refresh
).
to
.
be
(
false
);
});
it
(
'should restore refresh after relative time range is set'
,
function
()
{
_dashboard
.
refresh
=
true
;
_
filter
Srv
.
setTime
({
from
:
'2011-01-01'
,
to
:
'2015-01-01'
});
_
time
Srv
.
setTime
({
from
:
'2011-01-01'
,
to
:
'2015-01-01'
});
expect
(
_dashboard
.
refresh
).
to
.
be
(
false
);
_
filter
Srv
.
setTime
({
from
:
'2011-01-01'
,
to
:
'now'
});
_
time
Srv
.
setTime
({
from
:
'2011-01-01'
,
to
:
'now'
});
expect
(
_dashboard
.
refresh
).
to
.
be
(
true
);
});
});
...
...
src/test/test-main.js
View file @
1929490d
...
...
@@ -125,7 +125,7 @@ require([
'specs/graph-ctrl-specs'
,
'specs/grafanaGraph-specs'
,
'specs/seriesOverridesCtrl-specs'
,
'specs/
filter
Srv-specs'
,
'specs/
time
Srv-specs'
,
'specs/kbn-format-specs'
,
'specs/dashboardSrv-specs'
,
'specs/dashboardViewStateSrv-specs'
,
...
...
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