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
2475ca8f
Commit
2475ca8f
authored
Mar 08, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(templaing): refactoring PR #4283
parent
dc4743a3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
31 deletions
+28
-31
public/app/features/templating/templateValuesSrv.js
+28
-31
No files found.
public/app/features/templating/templateValuesSrv.js
View file @
2475ca8f
...
...
@@ -27,10 +27,9 @@ function (angular, _, kbn) {
var
queryParams
=
$location
.
search
();
var
promises
=
[];
//use promises to delay processing variables that
//depend on other variables.
//
use promises to delay processing variables that
//
depend on other variables.
this
.
variableLock
=
{};
var
self
=
this
;
_
.
forEach
(
this
.
variables
,
function
(
variable
)
{
self
.
variableLock
[
variable
.
name
]
=
$q
.
defer
();
});
...
...
@@ -45,7 +44,8 @@ function (angular, _, kbn) {
this
.
processVariable
=
function
(
variable
,
queryParams
)
{
var
dependencies
=
[];
var
self
=
this
;
var
lock
=
self
.
variableLock
[
variable
.
name
];
// determine our dependencies.
if
(
variable
.
type
===
"query"
)
{
_
.
forEach
(
this
.
variables
,
function
(
v
)
{
...
...
@@ -54,49 +54,44 @@ function (angular, _, kbn) {
}
});
}
return
$q
.
all
(
dependencies
).
then
(
function
()
{
var
variableName
=
variable
.
name
;
var
urlValue
=
queryParams
[
'var-'
+
variable
.
name
];
if
(
urlValue
!==
void
0
)
{
return
self
.
setVariableFromUrl
(
variable
,
urlValue
).
then
(
function
()
{
self
.
variableLock
[
variableName
].
resolve
();
});
return
self
.
setVariableFromUrl
(
variable
,
urlValue
).
then
(
lock
.
resolve
);
}
else
if
(
variable
.
refresh
)
{
return
self
.
updateOptions
(
variable
).
then
(
function
()
{
if
(
_
.
isEmpty
(
variable
.
current
)
&&
variable
.
options
.
length
)
{
console
.
log
(
"setting current for %s"
,
variable
.
name
);
self
.
setVariableValue
(
variable
,
variable
.
options
[
0
]
,
true
);
self
.
setVariableValue
(
variable
,
variable
.
options
[
0
]);
}
self
.
variableLock
[
variableName
]
.
resolve
();
lock
.
resolve
();
});
}
else
if
(
variable
.
type
===
'interval'
)
{
self
.
updateAutoInterval
(
variable
);
self
.
variableLock
[
variableName
]
.
resolve
();
lock
.
resolve
();
}
else
{
self
.
variableLock
[
variableName
]
.
resolve
();
lock
.
resolve
();
}
});
};
this
.
setVariableFromUrl
=
function
(
variable
,
urlValue
)
{
if
(
variable
.
refresh
)
{
var
self
=
this
;
//refresh the list of options before setting the value
return
this
.
updateOptions
(
variable
).
then
(
function
()
{
var
option
=
_
.
findWhere
(
variable
.
options
,
{
text
:
urlValue
});
option
=
option
||
{
text
:
urlValue
,
value
:
urlValue
};
var
promise
=
$q
.
when
(
true
);
self
.
updateAutoInterval
(
variable
);
return
self
.
setVariableValue
(
variable
,
option
,
true
);
});
if
(
variable
.
refresh
)
{
promise
=
this
.
updateOptions
(
variable
);
}
var
option
=
_
.
findWhere
(
variable
.
options
,
{
text
:
urlValue
});
option
=
option
||
{
text
:
urlValue
,
value
:
urlValue
};
this
.
updateAutoInterval
(
variable
);
return
this
.
setVariableValue
(
variable
,
option
,
true
);
return
promise
.
then
(
function
()
{
var
option
=
_
.
findWhere
(
variable
.
options
,
{
text
:
urlValue
});
option
=
option
||
{
text
:
urlValue
,
value
:
urlValue
};
self
.
updateAutoInterval
(
variable
);
return
self
.
setVariableValue
(
variable
,
option
,
true
);
});
};
this
.
updateAutoInterval
=
function
(
variable
)
{
...
...
@@ -111,7 +106,7 @@ function (angular, _, kbn) {
templateSrv
.
setGrafanaVariable
(
'$__auto_interval'
,
interval
);
};
this
.
setVariableValue
=
function
(
variable
,
option
,
firstLoad
)
{
this
.
setVariableValue
=
function
(
variable
,
option
,
initPhase
)
{
variable
.
current
=
angular
.
copy
(
option
);
if
(
_
.
isArray
(
variable
.
current
.
value
))
{
...
...
@@ -119,13 +114,14 @@ function (angular, _, kbn) {
}
self
.
selectOptionsForCurrentValue
(
variable
);
templateSrv
.
updateTemplateData
();
// on first load, variable loading is ordered to ensure
// that parents are updated before children.
if
(
firstLoad
)
{
if
(
initPhase
)
{
return
$q
.
when
();
}
return
self
.
updateOptionsInChildVariables
(
variable
);
};
...
...
@@ -171,7 +167,8 @@ function (angular, _, kbn) {
return
datasourceSrv
.
get
(
variable
.
datasource
)
.
then
(
_
.
partial
(
this
.
updateOptionsFromMetricFindQuery
,
variable
))
.
then
(
_
.
partial
(
this
.
updateTags
,
variable
));
.
then
(
_
.
partial
(
this
.
updateTags
,
variable
))
.
then
(
_
.
partial
(
this
.
validateVariableSelectionState
,
variable
));
};
this
.
selectOptionsForCurrentValue
=
function
(
variable
)
{
...
...
@@ -196,7 +193,7 @@ function (angular, _, kbn) {
this
.
validateVariableSelectionState
=
function
(
variable
)
{
if
(
!
variable
.
current
)
{
if
(
!
variable
.
options
.
length
)
{
return
;
}
return
self
.
setVariableValue
(
variable
,
variable
.
options
[
0
]);
return
self
.
setVariableValue
(
variable
,
variable
.
options
[
0
]
,
true
);
}
if
(
_
.
isArray
(
variable
.
current
.
value
))
{
...
...
@@ -204,7 +201,7 @@ function (angular, _, kbn) {
}
else
{
var
currentOption
=
_
.
findWhere
(
variable
.
options
,
{
text
:
variable
.
current
.
text
});
if
(
currentOption
)
{
return
self
.
setVariableValue
(
variable
,
currentOption
);
return
self
.
setVariableValue
(
variable
,
currentOption
,
true
);
}
else
{
if
(
!
variable
.
options
.
length
)
{
return
;
}
return
self
.
setVariableValue
(
variable
,
variable
.
options
[
0
]);
...
...
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