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
2c3d3d0f
Commit
2c3d3d0f
authored
Mar 01, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring out common panel metric and query code to a panelHelper service
parent
d0d995da
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
88 deletions
+91
-88
src/app/features/panel/all.js
+1
-0
src/app/features/panel/panelHelper.js
+73
-0
src/app/features/panel/panelSrv.js
+7
-2
src/app/panels/graph/module.js
+4
-63
src/app/panels/singlestat/module.js
+5
-23
src/test/specs/graph-ctrl-specs.js
+1
-0
No files found.
src/app/features/panel/all.js
View file @
2c3d3d0f
...
...
@@ -2,5 +2,6 @@ define([
'./panelMenu'
,
'./panelDirective'
,
'./panelSrv'
,
'./panelHelper'
,
'./soloPanelCtrl'
,
],
function
()
{});
src/app/features/panel/panelHelper.js
0 → 100644
View file @
2c3d3d0f
define
([
'angular'
,
'lodash'
,
'kbn'
,
'jquery'
,
],
function
(
angular
,
_
,
kbn
,
$
)
{
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
service
(
'panelHelper'
,
function
(
timeSrv
)
{
this
.
updateTimeRange
=
function
(
scope
)
{
scope
.
range
=
timeSrv
.
timeRange
();
scope
.
rangeUnparsed
=
timeSrv
.
timeRange
(
false
);
this
.
applyPanelTimeOverrides
(
scope
);
if
(
scope
.
panel
.
maxDataPoints
)
{
scope
.
resolution
=
scope
.
panel
.
maxDataPoints
;
}
else
{
scope
.
resolution
=
Math
.
ceil
(
$
(
window
).
width
()
*
(
scope
.
panel
.
span
/
12
));
}
scope
.
interval
=
kbn
.
calculateInterval
(
scope
.
range
,
scope
.
resolution
,
scope
.
panel
.
interval
);
};
this
.
applyPanelTimeOverrides
=
function
(
scope
)
{
scope
.
panelMeta
.
timeInfo
=
''
;
// check panel time overrrides
if
(
scope
.
panel
.
timeFrom
)
{
if
(
!
kbn
.
isValidTimeSpan
(
scope
.
panel
.
timeFrom
))
{
scope
.
panelMeta
.
timeInfo
=
'invalid time override'
;
return
;
}
if
(
_
.
isString
(
scope
.
rangeUnparsed
.
from
))
{
scope
.
panelMeta
.
timeInfo
=
"last "
+
scope
.
panel
.
timeFrom
;
scope
.
rangeUnparsed
.
from
=
'now-'
+
scope
.
panel
.
timeFrom
;
scope
.
range
.
from
=
kbn
.
parseDate
(
scope
.
rangeUnparsed
.
from
);
}
}
if
(
scope
.
panel
.
timeShift
)
{
if
(
!
kbn
.
isValidTimeSpan
(
scope
.
panel
.
timeFrom
))
{
scope
.
panelMeta
.
timeInfo
=
'invalid timeshift'
;
return
;
}
var
timeShift
=
'-'
+
scope
.
panel
.
timeShift
;
scope
.
panelMeta
.
timeInfo
+=
' timeshift '
+
timeShift
;
scope
.
range
.
from
=
kbn
.
parseDateMath
(
timeShift
,
scope
.
range
.
from
);
scope
.
range
.
to
=
kbn
.
parseDateMath
(
timeShift
,
scope
.
range
.
to
);
scope
.
rangeUnparsed
=
scope
.
range
;
}
};
this
.
issueMetricQuery
=
function
(
scope
,
datasource
)
{
var
metricsQuery
=
{
range
:
scope
.
rangeUnparsed
,
interval
:
scope
.
interval
,
targets
:
scope
.
panel
.
targets
,
format
:
scope
.
panel
.
renderer
===
'png'
?
'png'
:
'json'
,
maxDataPoints
:
scope
.
resolution
,
cacheTimeout
:
scope
.
panel
.
cacheTimeout
};
return
datasource
.
query
(
metricsQuery
);
};
});
});
src/app/features/panel/panelSrv.js
View file @
2c3d3d0f
...
...
@@ -7,6 +7,7 @@ function (angular, _, config) {
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
module
.
service
(
'panelSrv'
,
function
(
$rootScope
,
$timeout
,
datasourceSrv
)
{
this
.
init
=
function
(
$scope
)
{
...
...
@@ -99,10 +100,14 @@ function (angular, _, config) {
datasourceSrv
.
get
(
$scope
.
panel
.
datasource
).
then
(
function
(
datasource
)
{
$scope
.
datasource
=
datasource
;
return
$scope
.
refreshData
(
$scope
.
datasource
);
return
$scope
.
refreshData
(
$scope
.
datasource
).
then
(
function
()
{
$scope
.
panelMeta
.
loading
=
false
;
});
},
function
(
err
)
{
console
.
log
(
'Panel data error:'
,
err
);
$scope
.
panelMeta
.
loading
=
false
;
$scope
.
panelMeta
.
error
=
err
.
message
;
$scope
.
panelMeta
.
error
=
err
.
message
||
"Timeseries data request error"
;
$scope
.
inspector
.
error
=
err
;
});
};
...
...
src/app/panels/graph/module.js
View file @
2c3d3d0f
...
...
@@ -23,7 +23,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
};
});
module
.
controller
(
'GraphCtrl'
,
function
(
$scope
,
$rootScope
,
panelSrv
,
annotationsSrv
,
timeSrv
)
{
module
.
controller
(
'GraphCtrl'
,
function
(
$scope
,
$rootScope
,
panelSrv
,
annotationsSrv
,
panelHelper
)
{
$scope
.
panelMeta
=
new
PanelMeta
({
panelName
:
'Graph'
,
...
...
@@ -123,72 +123,14 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
$scope
.
render
();
};
$scope
.
applyPanelTimeOverrides
=
function
()
{
$scope
.
panelMeta
.
timeInfo
=
''
;
// check panel time overrrides
if
(
$scope
.
panel
.
timeFrom
)
{
if
(
!
kbn
.
isValidTimeSpan
(
$scope
.
panel
.
timeFrom
))
{
$scope
.
panelMeta
.
timeInfo
=
'invalid time override'
;
return
;
}
if
(
_
.
isString
(
$scope
.
rangeUnparsed
.
from
))
{
$scope
.
panelMeta
.
timeInfo
=
"last "
+
$scope
.
panel
.
timeFrom
;
$scope
.
rangeUnparsed
.
from
=
'now-'
+
$scope
.
panel
.
timeFrom
;
$scope
.
range
.
from
=
kbn
.
parseDate
(
$scope
.
rangeUnparsed
.
from
);
}
}
if
(
$scope
.
panel
.
timeShift
)
{
if
(
!
kbn
.
isValidTimeSpan
(
$scope
.
panel
.
timeFrom
))
{
$scope
.
panelMeta
.
timeInfo
=
'invalid timeshift'
;
return
;
}
var
timeShift
=
'-'
+
$scope
.
panel
.
timeShift
;
$scope
.
panelMeta
.
timeInfo
+=
' timeshift '
+
timeShift
;
$scope
.
range
.
from
=
kbn
.
parseDateMath
(
timeShift
,
$scope
.
range
.
from
);
$scope
.
range
.
to
=
kbn
.
parseDateMath
(
timeShift
,
$scope
.
range
.
to
);
$scope
.
rangeUnparsed
=
$scope
.
range
;
}
};
$scope
.
updateTimeRange
=
function
()
{
$scope
.
range
=
timeSrv
.
timeRange
();
$scope
.
rangeUnparsed
=
timeSrv
.
timeRange
(
false
);
$scope
.
applyPanelTimeOverrides
();
if
(
$scope
.
panel
.
maxDataPoints
)
{
$scope
.
resolution
=
$scope
.
panel
.
maxDataPoints
;
}
else
{
$scope
.
resolution
=
Math
.
ceil
(
$
(
window
).
width
()
*
(
$scope
.
panel
.
span
/
12
));
}
$scope
.
interval
=
kbn
.
calculateInterval
(
$scope
.
range
,
$scope
.
resolution
,
$scope
.
panel
.
interval
);
};
$scope
.
refreshData
=
function
(
datasource
)
{
$scope
.
updateTimeRange
();
var
metricsQuery
=
{
range
:
$scope
.
rangeUnparsed
,
interval
:
$scope
.
interval
,
targets
:
$scope
.
panel
.
targets
,
format
:
$scope
.
panel
.
renderer
===
'png'
?
'png'
:
'json'
,
maxDataPoints
:
$scope
.
resolution
,
cacheTimeout
:
$scope
.
panel
.
cacheTimeout
};
panelHelper
.
updateTimeRange
(
$scope
);
$scope
.
annotationsPromise
=
annotationsSrv
.
getAnnotations
(
$scope
.
rangeUnparsed
,
$scope
.
dashboard
);
return
datasource
.
query
(
metricsQuery
)
return
panelHelper
.
issueMetricQuery
(
$scope
,
datasource
)
.
then
(
$scope
.
dataHandler
)
.
then
(
null
,
function
(
err
)
{
$scope
.
panelMeta
.
loading
=
false
;
$scope
.
panelMeta
.
error
=
err
.
message
||
"Timeseries data request error"
;
$scope
.
inspector
.
error
=
err
;
.
then
(
null
,
function
()
{
$scope
.
seriesList
=
[];
$scope
.
render
([]);
});
...
...
@@ -197,7 +139,6 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) {
$scope
.
dataHandler
=
function
(
results
)
{
// png renderer returns just a url
if
(
_
.
isString
(
results
))
{
$scope
.
panelMeta
.
loading
=
false
;
$scope
.
render
(
results
);
return
;
}
...
...
src/app/panels/singlestat/module.js
View file @
2c3d3d0f
...
...
@@ -20,7 +20,7 @@ function (angular, app, _, TimeSeries, kbn, PanelMeta) {
};
});
module
.
controller
(
'SingleStatCtrl'
,
function
(
$scope
,
panelSrv
,
timeSrv
)
{
module
.
controller
(
'SingleStatCtrl'
,
function
(
$scope
,
panelSrv
,
panelHelper
)
{
$scope
.
panelMeta
=
new
PanelMeta
({
panelName
:
'Singlestat'
,
...
...
@@ -32,6 +32,7 @@ function (angular, app, _, TimeSeries, kbn, PanelMeta) {
$scope
.
fontSizes
=
[
'20%'
,
'30%'
,
'50%'
,
'70%'
,
'80%'
,
'100%'
,
'110%'
,
'120%'
,
'150%'
,
'170%'
,
'200%'
];
$scope
.
panelMeta
.
addEditorTab
(
'Options'
,
'app/panels/singlestat/editor.html'
);
$scope
.
panelMeta
.
addEditorTab
(
'Time range'
,
'app/features/panel/partials/panelTime.html'
);
// Set and populate defaults
var
_d
=
{
...
...
@@ -76,31 +77,12 @@ function (angular, app, _, TimeSeries, kbn, PanelMeta) {
panelSrv
.
init
(
$scope
);
};
$scope
.
updateTimeRange
=
function
()
{
$scope
.
range
=
timeSrv
.
timeRange
();
$scope
.
rangeUnparsed
=
timeSrv
.
timeRange
(
false
);
$scope
.
resolution
=
$scope
.
panel
.
maxDataPoints
;
$scope
.
interval
=
kbn
.
calculateInterval
(
$scope
.
range
,
$scope
.
resolution
,
$scope
.
panel
.
interval
);
};
$scope
.
refreshData
=
function
(
datasource
)
{
$scope
.
updateTimeRange
();
var
metricsQuery
=
{
range
:
$scope
.
rangeUnparsed
,
interval
:
$scope
.
interval
,
targets
:
$scope
.
panel
.
targets
,
maxDataPoints
:
$scope
.
resolution
,
cacheTimeout
:
$scope
.
panel
.
cacheTimeout
};
panelHelper
.
updateTimeRange
(
$scope
);
return
datasource
.
query
(
metricsQuery
)
return
panelHelper
.
issueMetricQuery
(
$scope
,
datasource
)
.
then
(
$scope
.
dataHandler
)
.
then
(
null
,
function
(
err
)
{
console
.
log
(
"err"
);
$scope
.
panelMeta
.
loading
=
false
;
$scope
.
panelMeta
.
error
=
err
.
message
||
"Timeseries data request error"
;
$scope
.
inspector
.
error
=
err
;
.
then
(
null
,
function
()
{
$scope
.
render
();
});
};
...
...
src/test/specs/graph-ctrl-specs.js
View file @
2c3d3d0f
define
([
'helpers'
,
'features/panel/panelSrv'
,
'features/panel/panelHelper'
,
'panels/graph/module'
],
function
(
helpers
)
{
'use strict'
;
...
...
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