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
8b68ba5c
Commit
8b68ba5c
authored
Jan 29, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactoring and adding some typing
parent
78cb3239
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
30 additions
and
19 deletions
+30
-19
public/app/features/templating/editor_ctrl.ts
+1
-1
public/app/features/templating/specs/template_srv.test.ts
+2
-2
public/app/features/templating/specs/variable_srv.test.ts
+1
-1
public/app/features/templating/specs/variable_srv_init.test.ts
+2
-1
public/app/features/templating/template_srv.ts
+5
-5
public/app/features/templating/variable_srv.ts
+18
-8
public/test/specs/helpers.ts
+1
-1
No files found.
public/app/features/templating/editor_ctrl.ts
View file @
8b68ba5c
...
@@ -135,7 +135,7 @@ export class VariableEditorCtrl {
...
@@ -135,7 +135,7 @@ export class VariableEditorCtrl {
$scope
.
runQuery
().
then
(()
=>
{
$scope
.
runQuery
().
then
(()
=>
{
$scope
.
reset
();
$scope
.
reset
();
$scope
.
mode
=
'list'
;
$scope
.
mode
=
'list'
;
templateSrv
.
update
TemplateData
();
templateSrv
.
update
Index
();
});
});
}
}
};
};
...
...
public/app/features/templating/specs/template_srv.test.ts
View file @
8b68ba5c
...
@@ -348,7 +348,7 @@ describe('templateSrv', () => {
...
@@ -348,7 +348,7 @@ describe('templateSrv', () => {
});
});
});
});
describe
(
'update
TemplateData
with simple value'
,
()
=>
{
describe
(
'update
Index
with simple value'
,
()
=>
{
beforeEach
(()
=>
{
beforeEach
(()
=>
{
initTemplateSrv
([{
type
:
'query'
,
name
:
'test'
,
current
:
{
value
:
'muuuu'
}
}]);
initTemplateSrv
([{
type
:
'query'
,
name
:
'test'
,
current
:
{
value
:
'muuuu'
}
}]);
});
});
...
@@ -476,7 +476,7 @@ describe('templateSrv', () => {
...
@@ -476,7 +476,7 @@ describe('templateSrv', () => {
}
}
]);
]);
_templateSrv
.
setGrafanaVariable
(
'$__auto_interval_interval'
,
'13m'
);
_templateSrv
.
setGrafanaVariable
(
'$__auto_interval_interval'
,
'13m'
);
_templateSrv
.
update
TemplateData
();
_templateSrv
.
update
Index
();
});
});
it
(
'should replace with text except for grafanaVariables'
,
()
=>
{
it
(
'should replace with text except for grafanaVariables'
,
()
=>
{
...
...
public/app/features/templating/specs/variable_srv.test.ts
View file @
8b68ba5c
...
@@ -23,7 +23,7 @@ describe('VariableSrv', function(this: any) {
...
@@ -23,7 +23,7 @@ describe('VariableSrv', function(this: any) {
init
:
vars
=>
{
init
:
vars
=>
{
this
.
variables
=
vars
;
this
.
variables
=
vars
;
},
},
update
TemplateData
:
()
=>
{},
update
Index
:
()
=>
{},
replace
:
str
=>
replace
:
str
=>
str
.
replace
(
this
.
regex
,
match
=>
{
str
.
replace
(
this
.
regex
,
match
=>
{
return
match
;
return
match
;
...
...
public/app/features/templating/specs/variable_srv_init.test.ts
View file @
8b68ba5c
...
@@ -11,7 +11,7 @@ describe('VariableSrv init', function(this: any) {
...
@@ -11,7 +11,7 @@ describe('VariableSrv init', function(this: any) {
this
.
variables
=
vars
;
this
.
variables
=
vars
;
},
},
variableInitialized
:
()
=>
{},
variableInitialized
:
()
=>
{},
update
TemplateData
:
()
=>
{},
update
Index
:
()
=>
{},
replace
:
str
=>
replace
:
str
=>
str
.
replace
(
this
.
regex
,
match
=>
{
str
.
replace
(
this
.
regex
,
match
=>
{
return
match
;
return
match
;
...
@@ -53,6 +53,7 @@ describe('VariableSrv init', function(this: any) {
...
@@ -53,6 +53,7 @@ describe('VariableSrv init', function(this: any) {
templateSrv
,
templateSrv
,
};
};
// @ts-ignore
ctx
.
variableSrv
=
new
VariableSrv
(
$rootscope
,
$q
,
{},
$injector
,
templateSrv
,
timeSrv
);
ctx
.
variableSrv
=
new
VariableSrv
(
$rootscope
,
$q
,
{},
$injector
,
templateSrv
,
timeSrv
);
$injector
.
instantiate
=
(
variable
,
model
)
=>
{
$injector
.
instantiate
=
(
variable
,
model
)
=>
{
...
...
public/app/features/templating/template_srv.ts
View file @
8b68ba5c
...
@@ -25,10 +25,10 @@ export class TemplateSrv {
...
@@ -25,10 +25,10 @@ export class TemplateSrv {
init
(
variables
,
timeRange
?:
TimeRange
)
{
init
(
variables
,
timeRange
?:
TimeRange
)
{
this
.
variables
=
variables
;
this
.
variables
=
variables
;
this
.
timeRange
=
timeRange
;
this
.
timeRange
=
timeRange
;
this
.
update
TemplateData
();
this
.
update
Index
();
}
}
update
TemplateData
()
{
update
Index
()
{
const
existsOrEmpty
=
value
=>
value
||
value
===
''
;
const
existsOrEmpty
=
value
=>
value
||
value
===
''
;
this
.
index
=
this
.
variables
.
reduce
((
acc
,
currentValue
)
=>
{
this
.
index
=
this
.
variables
.
reduce
((
acc
,
currentValue
)
=>
{
...
@@ -54,9 +54,9 @@ export class TemplateSrv {
...
@@ -54,9 +54,9 @@ export class TemplateSrv {
}
}
}
}
updateTime
Variables
(
timeRange
:
TimeRange
)
{
updateTime
Range
(
timeRange
:
TimeRange
)
{
this
.
timeRange
=
timeRange
;
this
.
timeRange
=
timeRange
;
this
.
update
TemplateData
();
this
.
update
Index
();
}
}
variableInitialized
(
variable
)
{
variableInitialized
(
variable
)
{
...
@@ -289,7 +289,7 @@ export class TemplateSrv {
...
@@ -289,7 +289,7 @@ export class TemplateSrv {
});
});
}
}
fillVariableValuesForUrl
(
params
,
scopedVars
)
{
fillVariableValuesForUrl
(
params
,
scopedVars
?
)
{
_
.
each
(
this
.
variables
,
variable
=>
{
_
.
each
(
this
.
variables
,
variable
=>
{
if
(
scopedVars
&&
scopedVars
[
variable
.
name
]
!==
void
0
)
{
if
(
scopedVars
&&
scopedVars
[
variable
.
name
]
!==
void
0
)
{
if
(
scopedVars
[
variable
.
name
].
skipUrlSync
)
{
if
(
scopedVars
[
variable
.
name
].
skipUrlSync
)
{
...
...
public/app/features/templating/variable_srv.ts
View file @
8b68ba5c
...
@@ -6,18 +6,28 @@ import _ from 'lodash';
...
@@ -6,18 +6,28 @@ import _ from 'lodash';
import
coreModule
from
'app/core/core_module'
;
import
coreModule
from
'app/core/core_module'
;
import
{
variableTypes
}
from
'./variable'
;
import
{
variableTypes
}
from
'./variable'
;
import
{
Graph
}
from
'app/core/utils/dag'
;
import
{
Graph
}
from
'app/core/utils/dag'
;
import
{
TemplateSrv
}
from
'app/features/templating/template_srv'
;
import
{
TimeSrv
}
from
'app/features/dashboard/time_srv'
;
import
{
DashboardModel
}
from
'app/features/dashboard/dashboard_model'
;
// Types
import
{
TimeRange
}
from
'@grafana/ui/src'
;
import
{
TimeRange
}
from
'@grafana/ui/src'
;
export
class
VariableSrv
{
export
class
VariableSrv
{
dashboard
:
any
;
dashboard
:
DashboardModel
;
variables
:
any
;
variables
:
any
[]
;
/** @ngInject */
/** @ngInject */
constructor
(
private
$rootScope
,
private
$q
,
private
$location
,
private
$injector
,
private
templateSrv
,
private
timeSrv
)
{
constructor
(
private
$rootScope
,
private
$q
,
private
$location
,
private
$injector
,
private
templateSrv
:
TemplateSrv
,
private
timeSrv
:
TimeSrv
)
{
$rootScope
.
$on
(
'template-variable-value-updated'
,
this
.
updateUrlParamsWithCurrentVariables
.
bind
(
this
),
$rootScope
);
$rootScope
.
$on
(
'template-variable-value-updated'
,
this
.
updateUrlParamsWithCurrentVariables
.
bind
(
this
),
$rootScope
);
}
}
init
(
dashboard
)
{
init
(
dashboard
:
DashboardModel
)
{
this
.
dashboard
=
dashboard
;
this
.
dashboard
=
dashboard
;
this
.
dashboard
.
events
.
on
(
'time-range-updated'
,
this
.
onTimeRangeUpdated
.
bind
(
this
));
this
.
dashboard
.
events
.
on
(
'time-range-updated'
,
this
.
onTimeRangeUpdated
.
bind
(
this
));
...
@@ -38,12 +48,12 @@ export class VariableSrv {
...
@@ -38,12 +48,12 @@ export class VariableSrv {
})
})
)
)
.
then
(()
=>
{
.
then
(()
=>
{
this
.
templateSrv
.
update
TemplateData
();
this
.
templateSrv
.
update
Index
();
});
});
}
}
onTimeRangeUpdated
(
timeRange
:
TimeRange
)
{
onTimeRangeUpdated
(
timeRange
:
TimeRange
)
{
this
.
templateSrv
.
updateTime
Variables
(
timeRange
);
this
.
templateSrv
.
updateTime
Range
(
timeRange
);
const
promises
=
this
.
variables
.
filter
(
variable
=>
variable
.
refresh
===
2
).
map
(
variable
=>
{
const
promises
=
this
.
variables
.
filter
(
variable
=>
variable
.
refresh
===
2
).
map
(
variable
=>
{
const
previousOptions
=
variable
.
options
.
slice
();
const
previousOptions
=
variable
.
options
.
slice
();
...
@@ -102,14 +112,14 @@ export class VariableSrv {
...
@@ -102,14 +112,14 @@ export class VariableSrv {
addVariable
(
variable
)
{
addVariable
(
variable
)
{
this
.
variables
.
push
(
variable
);
this
.
variables
.
push
(
variable
);
this
.
templateSrv
.
update
TemplateData
();
this
.
templateSrv
.
update
Index
();
this
.
dashboard
.
updateSubmenuVisibility
();
this
.
dashboard
.
updateSubmenuVisibility
();
}
}
removeVariable
(
variable
)
{
removeVariable
(
variable
)
{
const
index
=
_
.
indexOf
(
this
.
variables
,
variable
);
const
index
=
_
.
indexOf
(
this
.
variables
,
variable
);
this
.
variables
.
splice
(
index
,
1
);
this
.
variables
.
splice
(
index
,
1
);
this
.
templateSrv
.
update
TemplateData
();
this
.
templateSrv
.
update
Index
();
this
.
dashboard
.
updateSubmenuVisibility
();
this
.
dashboard
.
updateSubmenuVisibility
();
}
}
...
...
public/test/specs/helpers.ts
View file @
8b68ba5c
...
@@ -182,7 +182,7 @@ export function TemplateSrvStub(this: any) {
...
@@ -182,7 +182,7 @@ export function TemplateSrvStub(this: any) {
return
[];
return
[];
};
};
this
.
fillVariableValuesForUrl
=
()
=>
{};
this
.
fillVariableValuesForUrl
=
()
=>
{};
this
.
update
TemplateData
=
()
=>
{};
this
.
update
Index
=
()
=>
{};
this
.
variableExists
=
()
=>
{
this
.
variableExists
=
()
=>
{
return
false
;
return
false
;
};
};
...
...
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