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
8ca589cd
Commit
8ca589cd
authored
Apr 16, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for async scripted dashboards, and accesss to jquery, window & document, Closes #274)
parent
390c4eed
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
13 deletions
+117
-13
src/app/dashboards/scripted.js
+12
-5
src/app/dashboards/scripted_async.js
+82
-0
src/app/services/dashboard.js
+21
-7
tasks/options/jshint.js
+2
-1
No files found.
src/app/dashboards/scripted.js
View file @
8ca589cd
...
@@ -5,18 +5,25 @@
...
@@ -5,18 +5,25 @@
* This script generates a dashboard object that Grafana can load. It also takes a number of user
* This script generates a dashboard object that Grafana can load. It also takes a number of user
* supplied URL parameters (int ARGS variable)
* supplied URL parameters (int ARGS variable)
*
*
* Return a dashboard object, or a function
*
* For async scripts, return a function, this function must take a single callback function as argument,
* call this callback function with the dashboard object (look at scripted_async.js for an example)
*/
*/
'use strict'
;
'use strict'
;
// accessable variables in this scope
var
window
,
document
,
ARGS
,
$
,
jQuery
,
moment
,
kbn
;
// Setup some variables
// Setup some variables
var
dashboard
,
_d_time
span
;
var
dashboard
,
tim
span
;
// All url parameters are available via the ARGS object
// All url parameters are available via the ARGS object
var
ARGS
;
var
ARGS
;
// Set a default timespan if one isn't specified
// Set a default timespan if one isn't specified
_d_time
span
=
'1d'
;
tim
span
=
'1d'
;
// Intialize a skeleton with nothing but a rows array and service object
// Intialize a skeleton with nothing but a rows array and service object
dashboard
=
{
dashboard
=
{
...
@@ -28,7 +35,7 @@ dashboard = {
...
@@ -28,7 +35,7 @@ dashboard = {
dashboard
.
title
=
'Scripted dash'
;
dashboard
.
title
=
'Scripted dash'
;
dashboard
.
services
.
filter
=
{
dashboard
.
services
.
filter
=
{
time
:
{
time
:
{
from
:
"now-"
+
(
ARGS
.
from
||
_d_time
span
),
from
:
"now-"
+
(
ARGS
.
from
||
tim
span
),
to
:
"now"
to
:
"now"
}
}
};
};
...
@@ -67,8 +74,7 @@ for (var i = 0; i < rows; i++) {
...
@@ -67,8 +74,7 @@ for (var i = 0; i < rows; i++) {
}
}
]
]
});
});
}
}
// Now return the object and we're good!
return
dashboard
;
return
dashboard
;
\ No newline at end of file
src/app/dashboards/scripted_async.js
0 → 100644
View file @
8ca589cd
/* global _ */
/*
* Complex scripted dashboard
* This script generates a dashboard object that Grafana can load. It also takes a number of user
* supplied URL parameters (int ARGS variable)
*
* Global accessable variables
* window, document, $, jQuery, ARGS, moment
*
* Return a dashboard object, or a function
*
* For async scripts, return a function, this function must take a single callback function,
* call this function with the dasboard object
*/
'use strict'
;
// accessable variables in this scope
var
window
,
document
,
ARGS
,
$
,
jQuery
,
moment
,
kbn
;
return
function
(
callback
)
{
// Setup some variables
var
dashboard
,
timspan
;
// Set a default timespan if one isn't specified
timspan
=
'1d'
;
// Intialize a skeleton with nothing but a rows array and service object
dashboard
=
{
rows
:
[],
services
:
{}
};
// Set a title
dashboard
.
title
=
'Scripted dash'
;
dashboard
.
services
.
filter
=
{
time
:
{
from
:
"now-"
+
(
ARGS
.
from
||
timspan
),
to
:
"now"
}
};
var
rows
=
1
;
var
seriesName
=
'argName'
;
if
(
!
_
.
isUndefined
(
ARGS
.
rows
))
{
rows
=
parseInt
(
ARGS
.
rows
,
10
);
}
if
(
!
_
.
isUndefined
(
ARGS
.
name
))
{
seriesName
=
ARGS
.
name
;
}
$
.
ajax
({
method
:
'GET'
,
url
:
'/'
})
.
done
(
function
(
result
)
{
dashboard
.
rows
.
push
({
title
:
'Chart'
,
height
:
'300px'
,
panels
:
[
{
title
:
'Async dashboard test'
,
type
:
'text'
,
span
:
12
,
fill
:
1
,
content
:
'# Async test'
}
]
});
// when dashboard is composed call the callback
// function and pass the dashboard
callback
(
dashboard
);
});
}
\ No newline at end of file
src/app/services/dashboard.js
View file @
8ca589cd
...
@@ -15,7 +15,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
...
@@ -15,7 +15,7 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
module
.
service
(
'dashboard'
,
function
(
module
.
service
(
'dashboard'
,
function
(
$routeParams
,
$http
,
$rootScope
,
$injector
,
$location
,
$timeout
,
$routeParams
,
$http
,
$rootScope
,
$injector
,
$location
,
$timeout
,
ejsResource
,
timer
,
alertSrv
ejsResource
,
timer
,
alertSrv
,
$q
)
{
)
{
// A hash of defaults to use when loading a dashboard
// A hash of defaults to use when loading a dashboard
...
@@ -332,13 +332,27 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
...
@@ -332,13 +332,27 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
this
.
script_load
=
function
(
file
)
{
this
.
script_load
=
function
(
file
)
{
return
$http
({
return
$http
({
url
:
"app/dashboards/"
+
file
.
replace
(
/
\.(?!
js
)
/
,
"/"
),
url
:
"app/dashboards/"
+
file
.
replace
(
/
\.(?!
js
)
/
,
"/"
),
method
:
"GET"
,
method
:
"GET"
transformResponse
:
function
(
response
)
{
})
/*jshint -W054 */
.
then
(
function
(
result
)
{
var
_f
=
new
Function
(
'ARGS'
,
'kbn'
,
'_'
,
'moment'
,
'window'
,
'document'
,
'angular'
,
'require'
,
'define'
,
'$'
,
'jQuery'
,
response
);
/*jshint -W054 */
return
_f
(
$routeParams
,
kbn
,
_
,
moment
);
var
script_func
=
new
Function
(
'ARGS'
,
'kbn'
,
'_'
,
'moment'
,
'window'
,
'document'
,
'$'
,
'jQuery'
,
result
.
data
);
var
script_result
=
script_func
(
$routeParams
,
kbn
,
_
,
moment
,
window
,
document
,
$
,
$
);
// Handle async dashboard scripts
if
(
_
.
isFunction
(
script_result
))
{
var
deferred
=
$q
.
defer
();
script_result
(
function
(
dashboard
)
{
$rootScope
.
$apply
(
function
()
{
deferred
.
resolve
({
data
:
dashboard
});
});
});
return
deferred
.
promise
;
}
}
}).
then
(
function
(
result
)
{
return
{
data
:
script_result
};
})
.
then
(
function
(
result
)
{
if
(
!
result
)
{
if
(
!
result
)
{
return
false
;
return
false
;
}
}
...
...
tasks/options/jshint.js
View file @
8ca589cd
...
@@ -18,7 +18,8 @@ module.exports = function(config) {
...
@@ -18,7 +18,8 @@ module.exports = function(config) {
'dist/*'
,
'dist/*'
,
'sample/*'
,
'sample/*'
,
'<%= srcDir %>/vendor/*'
,
'<%= srcDir %>/vendor/*'
,
'<%= srcDir %>/app/panels/*/{lib,leaflet}/*'
'<%= srcDir %>/app/panels/*/{lib,leaflet}/*'
,
'<%= srcDir %>/app/dashboards/*'
]
]
}
}
};
};
...
...
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