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
1ad4b44e
Commit
1ad4b44e
authored
Dec 04, 2018
by
Johannes Schill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
POC on how to save away settings from a viztype and restore when switching back to it #14274
parent
9cbdd073
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
public/app/features/dashboard/panel_model.ts
+41
-0
No files found.
public/app/features/dashboard/panel_model.ts
View file @
1ad4b44e
...
...
@@ -15,6 +15,7 @@ const notPersistedProperties: { [str: string]: boolean } = {
fullscreen
:
true
,
isEditing
:
true
,
hasRefreshed
:
true
,
cachedPluginOptions
:
true
,
};
// For angular panels we need to clean up properties when changing type
...
...
@@ -51,12 +52,14 @@ const mustKeepProps: { [str: string]: boolean } = {
events
:
true
,
cacheTimeout
:
true
,
nullPointMode
:
true
,
cachedPluginOptions
:
true
,
};
const
defaults
:
any
=
{
gridPos
:
{
x
:
0
,
y
:
0
,
h
:
3
,
w
:
6
},
datasource
:
null
,
targets
:
[{}],
cachedPluginOptions
:
{},
};
export
class
PanelModel
{
...
...
@@ -96,6 +99,9 @@ export class PanelModel {
events
:
Emitter
;
cacheTimeout
?:
any
;
// cache props between plugins
cachedPluginOptions
?:
any
;
constructor
(
model
)
{
this
.
events
=
new
Emitter
();
...
...
@@ -184,7 +190,40 @@ export class PanelModel {
this
.
events
.
emit
(
'panel-initialized'
);
}
getPanelOptions
()
{
return
Object
.
keys
(
this
).
reduce
((
acc
,
property
)
=>
{
if
(
notPersistedProperties
[
property
])
{
return
acc
;
}
return
{
...
acc
,
[
property
]:
this
[
property
],
};
},
{});
}
saveCurrentPanelOptions
()
{
const
currentOptions
=
this
.
getPanelOptions
();
this
.
cachedPluginOptions
[
this
.
type
]
=
currentOptions
;
}
restorePanelOptions
(
pluginId
:
string
)
{
const
currentOptions
=
this
.
getPanelOptions
();
const
prevOptions
=
this
.
cachedPluginOptions
[
pluginId
];
const
newOptions
=
Object
.
keys
(
prevOptions
).
reduce
((
acc
,
currKey
:
string
)
=>
{
return
{
...
acc
,
[
currKey
]:
currentOptions
[
currKey
]
||
prevOptions
[
currKey
],
};
},
{});
Object
.
keys
(
newOptions
).
map
(
property
=>
{
this
[
property
]
=
newOptions
[
property
];
});
}
changeType
(
pluginId
:
string
,
fromAngularPanel
:
boolean
)
{
this
.
saveCurrentPanelOptions
();
this
.
type
=
pluginId
;
// for now we need to remove alert rules when changing type
...
...
@@ -202,6 +241,8 @@ export class PanelModel {
delete
this
[
key
];
}
}
this
.
restorePanelOptions
(
pluginId
);
}
destroy
()
{
...
...
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