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
0f4a9f1e
Commit
0f4a9f1e
authored
Sep 15, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(templating): began refactoring variables into rich behavioral classes
parent
94e5001c
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
138 additions
and
27 deletions
+138
-27
public/app/features/dashboard/dashboard_ctrl.ts
+2
-2
public/app/features/dashboard/submenu/submenu.ts
+4
-4
public/app/features/templating/editorCtrl.js
+3
-3
public/app/features/templating/specs/variable_srv_specs.ts
+4
-0
public/app/features/templating/templateSrv.js
+1
-0
public/app/features/templating/templateValuesSrv.js
+1
-2
public/app/features/templating/variable_srv.ts
+107
-0
public/test/specs/templateValuesSrv-specs.js
+16
-16
No files found.
public/app/features/dashboard/dashboard_ctrl.ts
View file @
0f4a9f1e
...
...
@@ -15,7 +15,7 @@ export class DashboardCtrl {
private
$rootScope
,
dashboardKeybindings
,
timeSrv
,
templateValues
Srv
,
variable
Srv
,
dashboardSrv
,
unsavedChangesSrv
,
dynamicDashboardSrv
,
...
...
@@ -46,7 +46,7 @@ export class DashboardCtrl {
// template values service needs to initialize completely before
// the rest of the dashboard can load
templateValues
Srv
.
init
(
dashboard
)
variable
Srv
.
init
(
dashboard
)
// template values failes are non fatal
.
catch
(
$scope
.
onInitFailed
.
bind
(
this
,
'Templating init failed'
,
false
))
// continue
...
...
public/app/features/dashboard/submenu/submenu.ts
View file @
0f4a9f1e
...
...
@@ -10,11 +10,11 @@ export class SubmenuCtrl {
/** @ngInject */
constructor
(
private
$rootScope
,
private
templateValues
Srv
,
private
variable
Srv
,
private
templateSrv
,
private
$location
)
{
this
.
annotations
=
this
.
dashboard
.
templating
.
list
;
this
.
variables
=
this
.
dashboard
.
templating
.
list
;
this
.
variables
=
this
.
variableSrv
.
variables
;
}
disableAnnotation
(
annotation
)
{
...
...
@@ -23,11 +23,11 @@ export class SubmenuCtrl {
}
getValuesForTag
(
variable
,
tagKey
)
{
return
this
.
templateValues
Srv
.
getValuesForTag
(
variable
,
tagKey
);
return
this
.
variable
Srv
.
getValuesForTag
(
variable
,
tagKey
);
}
variableUpdated
(
variable
)
{
this
.
templateValues
Srv
.
variableUpdated
(
variable
).
then
(()
=>
{
this
.
variable
Srv
.
variableUpdated
(
variable
).
then
(()
=>
{
this
.
$rootScope
.
$emit
(
'template-variable-value-updated'
);
this
.
$rootScope
.
$broadcast
(
'refresh'
);
});
...
...
public/app/features/templating/editorCtrl.js
View file @
0f4a9f1e
...
...
@@ -7,7 +7,7 @@ function (angular, _) {
var
module
=
angular
.
module
(
'grafana.controllers'
);
module
.
controller
(
'TemplateEditorCtrl'
,
function
(
$scope
,
datasourceSrv
,
templateSrv
,
templateValues
Srv
)
{
module
.
controller
(
'TemplateEditorCtrl'
,
function
(
$scope
,
datasourceSrv
,
variable
Srv
)
{
var
replacementDefaults
=
{
type
:
'query'
,
...
...
@@ -63,7 +63,7 @@ function (angular, _) {
return
value
;
});
$scope
.
variables
=
templat
eSrv
.
variables
;
$scope
.
variables
=
variabl
eSrv
.
variables
;
$scope
.
reset
();
$scope
.
$watch
(
'mode'
,
function
(
val
)
{
...
...
@@ -113,7 +113,7 @@ function (angular, _) {
};
$scope
.
runQuery
=
function
()
{
return
templateValues
Srv
.
updateOptions
(
$scope
.
current
).
then
(
null
,
function
(
err
)
{
return
variable
Srv
.
updateOptions
(
$scope
.
current
).
then
(
null
,
function
(
err
)
{
if
(
err
.
data
&&
err
.
data
.
message
)
{
err
.
message
=
err
.
data
.
message
;
}
$scope
.
appEvent
(
"alert-error"
,
[
'Templating'
,
'Template variables could not be initialized: '
+
err
.
message
]);
});
...
...
public/app/features/templating/specs/variable_srv_specs.ts
0 → 100644
View file @
0f4a9f1e
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
describe
(
'VariableSrv'
,
function
()
{
});
public/app/features/templating/templateSrv.js
View file @
0f4a9f1e
...
...
@@ -2,6 +2,7 @@ define([
'angular'
,
'lodash'
,
'./editorCtrl'
,
'./variable_srv'
,
'./templateValuesSrv'
,
],
function
(
angular
,
_
)
{
...
...
public/app/features/templating/templateValuesSrv.js
View file @
0f4a9f1e
...
...
@@ -166,8 +166,7 @@ function (angular, _, $, kbn) {
if
(
otherVariable
===
updatedVariable
)
{
return
;
}
if
((
otherVariable
.
type
===
"datasource"
&&
templateSrv
.
containsVariable
(
otherVariable
.
regex
,
updatedVariable
.
name
))
||
if
(
templateSrv
.
containsVariable
(
otherVariable
.
regex
,
updatedVariable
.
name
)
||
templateSrv
.
containsVariable
(
otherVariable
.
query
,
updatedVariable
.
name
)
||
templateSrv
.
containsVariable
(
otherVariable
.
datasource
,
updatedVariable
.
name
))
{
return
self
.
updateOptions
(
otherVariable
);
...
...
public/app/features/templating/variable_srv.ts
0 → 100644
View file @
0f4a9f1e
///<reference path="../../headers/common.d.ts" />
import
angular
from
'angular'
;
import
_
from
'lodash'
;
import
$
from
'jquery'
;
import
coreModule
from
'app/core/core_module'
;
import
appEvents
from
'app/core/app_events'
;
interface
Variable
{
}
class
ConstantVariable
implements
Variable
{
constructor
(
private
model
)
{
}
}
class
CustomVariable
implements
Variable
{
constructor
(
private
model
)
{
}
}
class
IntervalVariable
implements
Variable
{
constructor
(
private
model
)
{
}
}
class
QueryVariable
implements
Variable
{
constructor
(
private
model
,
private
variableSrv
:
VariableSrv
,
private
datasourceSrv
)
{
_
.
extend
(
this
,
model
);
}
updateOptions
()
{
return
this
.
datasourceSrv
.
get
(
this
.
datasource
)
.
then
(
_
.
partial
(
this
.
updateOptionsFromMetricFindQuery
,
variable
))
.
then
(
_
.
partial
(
this
.
updateTags
,
variable
))
.
then
(
_
.
partial
(
this
.
validateVariableSelectionState
,
variable
));
}
}
class
DatasourceVariable
implements
Variable
{
constructor
(
private
model
)
{
}
}
export
class
VariableSrv
{
dashboard
:
any
;
variables
:
any
;
variableLock
:
any
;
/** @ngInject */
constructor
(
private
$q
,
private
$rootScope
,
private
datasourceSrv
,
private
$location
,
private
templateSrv
,
private
timeSrv
)
{
}
init
(
dashboard
)
{
this
.
variableLock
=
{};
this
.
dashboard
=
dashboard
;
this
.
variables
=
dashboard
.
templating
.
list
.
map
(
item
=>
{
return
new
QueryVariable
(
item
,
this
);
});
this
.
templateSrv
.
init
(
this
.
variables
);
return
this
.
$q
.
when
();
}
updateOptions
(
variable
)
{
return
variable
.
updateOptions
();
}
variableUpdated
(
variable
)
{
// if there is a variable lock ignore cascading update because we are in a boot up scenario
if
(
this
.
variableLock
[
variable
.
name
])
{
return
this
.
$q
.
when
();
}
var
promises
=
_
.
map
(
this
.
variables
,
otherVariable
=>
{
if
(
otherVariable
===
variable
)
{
return
;
}
if
(
this
.
templateSrv
.
containsVariable
(
otherVariable
.
regex
,
variable
.
name
)
||
this
.
templateSrv
.
containsVariable
(
otherVariable
.
query
,
variable
.
name
)
||
this
.
templateSrv
.
containsVariable
(
otherVariable
.
datasource
,
variable
.
name
))
{
return
this
.
updateOptions
(
otherVariable
);
}
});
return
this
.
$q
.
all
(
promises
);
}
}
coreModule
.
service
(
'variableSrv'
,
VariableSrv
);
public/test/specs/templateValuesSrv-specs.js
View file @
0f4a9f1e
...
...
@@ -50,22 +50,22 @@ define([
});
});
describe
(
'and setting adhoc variable'
,
function
()
{
var
variable
=
{
name
:
'filters'
,
type
:
'adhoc'
};
beforeEach
(
function
(
done
)
{
var
dashboard
=
{
templating
:
{
list
:
[
variable
]
}
};
var
urlParams
=
{};
urlParams
[
"var-filters"
]
=
"hostname|gt|server2"
;
ctx
.
$location
.
search
=
sinon
.
stub
().
returns
(
urlParams
);
ctx
.
service
.
init
(
dashboard
).
then
(
function
()
{
done
();
});
ctx
.
$rootScope
.
$digest
();
});
it
(
'should update current value'
,
function
()
{
expect
(
variable
.
tags
[
0
]).
to
.
eq
({
tag
:
'hostname'
,
value
:
'server2'
});
});
});
//
describe('and setting adhoc variable', function() {
//
var variable = {name: 'filters', type: 'adhoc'};
//
//
beforeEach(function(done) {
//
var dashboard = { templating: { list: [variable] } };
//
var urlParams = {};
//
urlParams["var-filters"] = "hostname|gt|server2";
//
ctx.$location.search = sinon.stub().returns(urlParams);
//
ctx.service.init(dashboard).then(function() { done(); });
//
ctx.$rootScope.$digest();
//
});
//
//
it('should update current value', function() {
//
expect(variable.tags[0]).to.eq({tag: 'hostname', value: 'server2'});
//
});
//
});
});
describe
(
'when template variable is present in url multiple times'
,
function
()
{
...
...
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