Merge pull request #4222 from raintank/pluginSettingEditHooks
Add support for pre/post update hooks in the PluginEditCtrl.
This commit is contained in:
@@ -9,6 +9,8 @@ export class PluginEditCtrl {
|
|||||||
includedPanels: any;
|
includedPanels: any;
|
||||||
includedDatasources: any;
|
includedDatasources: any;
|
||||||
tabIndex: number;
|
tabIndex: number;
|
||||||
|
preUpdateHook: () => any;
|
||||||
|
postUpdateHook: () => any;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private backendSrv: any, private $routeParams: any) {
|
constructor(private backendSrv: any, private $routeParams: any) {
|
||||||
@@ -24,20 +26,55 @@ export class PluginEditCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
var updateCmd = _.extend({
|
var chain = Promise.resolve();
|
||||||
pluginId: this.model.pluginId,
|
var self = this;
|
||||||
orgId: this.model.orgId,
|
// if set, handle the preUpdateHook. If this returns a promise,
|
||||||
enabled: this.model.enabled,
|
// the next step of execution will block until the promise resolves.
|
||||||
pinned: this.model.pinned,
|
// if the promise is rejected, this update will be aborted.
|
||||||
jsonData: this.model.jsonData,
|
if (this.preUpdateHook != null) {
|
||||||
secureJsonData: this.model.secureJsonData,
|
chain = chain.then(function() {
|
||||||
}, {});
|
return Promise.resolve(self.preUpdateHook());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.backendSrv.post(`/api/org/plugins/${this.pluginId}/settings`, updateCmd).then(function() {
|
// Perform the core update procedure
|
||||||
|
chain = chain.then(function() {
|
||||||
|
var updateCmd = _.extend({
|
||||||
|
pluginId: self.model.pluginId,
|
||||||
|
orgId: self.model.orgId,
|
||||||
|
enabled: self.model.enabled,
|
||||||
|
pinned: self.model.pinned,
|
||||||
|
jsonData: self.model.jsonData,
|
||||||
|
secureJsonData: self.model.secureJsonData,
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
return self.backendSrv.post(`/api/org/plugins/${self.pluginId}/settings`, updateCmd);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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 Promise.resolve(this.postUpdateHook());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
window.location.href = window.location.href;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPreUpdateHook(callback: () => any) {
|
||||||
|
this.preUpdateHook = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPOstUpdateHook(callback: () => any) {
|
||||||
|
this.postUpdateHook = callback;
|
||||||
|
}
|
||||||
|
|
||||||
toggleEnabled() {
|
toggleEnabled() {
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user