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
61017fc2
Commit
61017fc2
authored
Mar 25, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(plugins): import all dashboards feature
parent
1ff90b71
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
33 deletions
+78
-33
public/app/core/utils/emitter.ts
+10
-2
public/app/features/plugins/import_list/import_list.ts
+27
-2
public/app/features/plugins/plugin_edit_ctrl.ts
+41
-29
No files found.
public/app/core/utils/emitter.ts
View file @
61017fc2
...
...
@@ -21,10 +21,18 @@ export class Emitter {
this
.
subjects
[
fnName
].
next
(
data
);
}
on
(
name
,
handler
)
{
on
(
name
,
handler
,
$scope
)
{
var
fnName
=
createName
(
name
);
this
.
subjects
[
fnName
]
||
(
this
.
subjects
[
fnName
]
=
new
Subject
());
this
.
subjects
[
fnName
].
subscribe
(
handler
);
var
subscription
=
this
.
subjects
[
fnName
].
subscribe
(
handler
);
if
(
$scope
)
{
$scope
.
$on
(
'$destroy'
,
function
()
{
subscription
.
unsubscribe
();
});
}
return
subscription
;
};
off
(
name
,
handler
)
{
...
...
public/app/features/plugins/import_list/import_list.ts
View file @
61017fc2
...
...
@@ -3,18 +3,43 @@
import
angular
from
'angular'
;
import
_
from
'lodash'
;
import
coreModule
from
'app/core/core_module'
;
import
appEvents
from
'app/core/app_events'
;
export
class
DashImportListCtrl
{
dashboards
:
any
[];
plugin
:
any
;
datasource
:
any
;
constructor
(
private
$http
,
private
backendSrv
,
private
$rootScope
)
{
constructor
(
$scope
,
private
$http
,
private
backendSrv
,
private
$rootScope
)
{
this
.
dashboards
=
[];
backendSrv
.
get
(
`/api/plugins/
${
this
.
plugin
.
id
}
/dashboards`
).
then
(
dashboards
=>
{
this
.
dashboards
=
dashboards
;
});
appEvents
.
on
(
'dashboard-list-import-all'
,
this
.
importAll
.
bind
(
this
),
$scope
);
}
importAll
(
payload
)
{
return
this
.
importNext
(
0
).
then
(()
=>
{
payload
.
resolve
(
"All dashboards imported"
);
}).
catch
(
err
=>
{
payload
.
reject
(
err
);
});
}
importNext
(
index
)
{
return
this
.
import
(
this
.
dashboards
[
index
],
true
).
then
(()
=>
{
if
(
index
+
1
<
this
.
dashboards
.
length
)
{
return
new
Promise
(
resolve
=>
{
setTimeout
(()
=>
{
this
.
importNext
(
index
+
1
).
then
(()
=>
{
resolve
();
});
},
500
);
});
}
});
}
import
(
dash
,
reinstall
)
{
...
...
@@ -34,7 +59,7 @@ export class DashImportListCtrl {
});
}
this
.
backendSrv
.
post
(
`/api/dashboards/import`
,
installCmd
).
then
(
res
=>
{
return
this
.
backendSrv
.
post
(
`/api/dashboards/import`
,
installCmd
).
then
(
res
=>
{
this
.
$rootScope
.
appEvent
(
'alert-success'
,
[
'Dashboard Installed'
,
dash
.
title
]);
_
.
extend
(
dash
,
res
);
});
...
...
public/app/features/plugins/plugin_edit_ctrl.ts
View file @
61017fc2
...
...
@@ -2,6 +2,7 @@
import
angular
from
'angular'
;
import
_
from
'lodash'
;
import
appEvents
from
'app/core/app_events'
;
export
class
PluginEditCtrl
{
model
:
any
;
...
...
@@ -17,11 +18,18 @@ export class PluginEditCtrl {
postUpdateHook
:
()
=>
any
;
/** @ngInject */
constructor
(
private
backendSrv
,
private
$routeParams
,
private
$sce
,
private
$http
)
{
constructor
(
private
$scope
,
private
backendSrv
,
private
$routeParams
,
private
$sce
,
private
$http
)
{
this
.
model
=
{};
this
.
pluginId
=
$routeParams
.
pluginId
;
this
.
tabIndex
=
0
;
this
.
tabs
=
[
'Overview'
];
this
.
preUpdateHook
=
()
=>
Promise
.
resolve
();
this
.
postUpdateHook
=
()
=>
Promise
.
resolve
();
}
init
()
{
...
...
@@ -71,40 +79,44 @@ export class PluginEditCtrl {
}
update
()
{
var
chain
=
Promise
.
resolve
();
var
self
=
this
;
// if set, handle the preUpdateHook. If this returns a promise,
// the next step of execution will block until the promise resolves.
// if the promise is rejected, this update will be aborted.
if
(
this
.
preUpdateHook
!=
null
)
{
chain
=
self
.
preUpdateHook
();
}
// Perform the core update procedure
chain
=
chain
.
then
(
function
()
{
this
.
preUpdateHook
().
then
(()
=>
{
var
updateCmd
=
_
.
extend
({
enabled
:
self
.
model
.
enabled
,
pinned
:
self
.
model
.
pinned
,
jsonData
:
self
.
model
.
jsonData
,
secureJsonData
:
self
.
model
.
secureJsonData
,
enabled
:
this
.
model
.
enabled
,
pinned
:
this
.
model
.
pinned
,
jsonData
:
this
.
model
.
jsonData
,
secureJsonData
:
this
.
model
.
secureJsonData
,
},
{});
return
self
.
backendSrv
.
post
(
`/api/plugins/
${
self
.
pluginId
}
/settings`
,
updateCmd
);
return
this
.
backendSrv
.
post
(
`/api/plugins/
${
this
.
pluginId
}
/settings`
,
updateCmd
);
})
.
then
(
this
.
postUpdateHook
)
.
then
((
res
)
=>
{
window
.
location
.
href
=
window
.
location
.
href
;
});
}
// if set, performt he postUpdate hook. If a promise is returned it will block
// the final step of the update procedure (reloading the page) until the promise
// resolves. If the promise is rejected the page will not be reloaded.
if
(
this
.
postUpdateHook
!=
null
)
{
chain
=
chain
.
then
(
function
()
{
return
this
.
postUpdateHook
();
});
}
importDashboards
()
{
// move to dashboards tab
this
.
tabIndex
=
2
;
// all stesp in the update procedure are complete, so reload the page to make changes
// take effect.
chain
.
then
(
function
()
{
window
.
location
.
href
=
window
.
location
.
href
;
return
new
Promise
((
resolve
)
=>
{
if
(
!
this
.
$scope
.
$$phase
)
{
this
.
$scope
.
$digest
();
}
// let angular load dashboards tab
setTimeout
(()
=>
{
resolve
();
},
1000
);
}).
then
(()
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
// send event to import list component
appEvents
.
emit
(
'dashboard-list-import-all'
,
{
resolve
:
resolve
,
reject
:
reject
});
});
});
}
...
...
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