2016-02-25 07:55:31 -06:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
export class PluginEditCtrl {
|
|
|
|
model: any;
|
2016-03-07 07:31:02 -06:00
|
|
|
pluginIcon: string;
|
2016-02-25 07:55:31 -06:00
|
|
|
pluginId: any;
|
|
|
|
includedPanels: any;
|
2016-03-07 11:03:45 -06:00
|
|
|
readmeHtml: any;
|
2016-02-25 07:55:31 -06:00
|
|
|
includedDatasources: any;
|
2016-02-26 11:25:39 -06:00
|
|
|
tabIndex: number;
|
2016-03-02 00:21:25 -06:00
|
|
|
preUpdateHook: () => any;
|
|
|
|
postUpdateHook: () => any;
|
2016-02-25 07:55:31 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
2016-03-07 11:03:45 -06:00
|
|
|
constructor(private backendSrv, private $routeParams, private $sce, private $http) {
|
2016-02-25 07:55:31 -06:00
|
|
|
this.model = {};
|
|
|
|
this.pluginId = $routeParams.pluginId;
|
2016-02-26 11:25:39 -06:00
|
|
|
this.tabIndex = 0;
|
2016-03-07 11:03:45 -06:00
|
|
|
}
|
2016-02-25 07:55:31 -06:00
|
|
|
|
2016-03-07 11:03:45 -06:00
|
|
|
init() {
|
|
|
|
return this.backendSrv.get(`/api/org/plugins/${this.pluginId}/settings`).then(result => {
|
2016-02-25 07:55:31 -06:00
|
|
|
this.model = result;
|
|
|
|
this.includedPanels = _.where(result.includes, {type: 'panel'});
|
|
|
|
this.includedDatasources = _.where(result.includes, {type: 'datasource'});
|
2016-03-07 07:31:02 -06:00
|
|
|
this.pluginIcon = this.getPluginIcon(this.model.type);
|
|
|
|
|
|
|
|
this.model.dependencies.plugins.forEach(plug => {
|
|
|
|
plug.icon = this.getPluginIcon(plug.type);
|
|
|
|
});
|
2016-03-07 11:03:45 -06:00
|
|
|
|
|
|
|
return this.initReadme();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initReadme() {
|
|
|
|
return this.$http.get(this.model.baseUrl + '/readme.md').then(res => {
|
|
|
|
return System.import('remarkable').then(Remarkable => {
|
|
|
|
var md = new Remarkable();
|
|
|
|
this.readmeHtml = this.$sce.trustAsHtml(md.render(res.data));
|
|
|
|
});
|
2016-02-25 07:55:31 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-07 07:31:02 -06:00
|
|
|
getPluginIcon(type) {
|
|
|
|
switch (type) {
|
|
|
|
case 'datasource': return 'icon-gf icon-gf-datasources';
|
|
|
|
case 'panel': return 'icon-gf icon-gf-panel';
|
|
|
|
case 'app': return 'icon-gf icon-gf-apps';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 07:55:31 -06:00
|
|
|
update() {
|
2016-03-02 00:21:25 -06:00
|
|
|
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 = chain.then(function() {
|
|
|
|
return Promise.resolve(self.preUpdateHook());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2016-03-07 07:31:02 -06:00
|
|
|
// resolves. If the promise is rejected the page will not be reloaded.
|
2016-03-02 00:21:25 -06:00
|
|
|
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() {
|
2016-02-25 07:55:31 -06:00
|
|
|
window.location.href = window.location.href;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-02 00:21:25 -06:00
|
|
|
setPreUpdateHook(callback: () => any) {
|
|
|
|
this.preUpdateHook = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
setPOstUpdateHook(callback: () => any) {
|
|
|
|
this.postUpdateHook = callback;
|
|
|
|
}
|
|
|
|
|
2016-02-25 07:55:31 -06:00
|
|
|
toggleEnabled() {
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
togglePinned() {
|
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
angular.module('grafana.controllers').controller('PluginEditCtrl', PluginEditCtrl);
|
|
|
|
|