2016-02-25 07:55:31 -06:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
2016-03-25 09:35:58 -05:00
|
|
|
import appEvents from 'app/core/app_events';
|
2016-02-25 07:55:31 -06:00
|
|
|
|
|
|
|
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;
|
2016-03-08 05:31:37 -06:00
|
|
|
includes: 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-13 14:18:45 -05:00
|
|
|
tabs: any;
|
|
|
|
hasDashboards: any;
|
2016-03-02 00:21:25 -06:00
|
|
|
preUpdateHook: () => any;
|
|
|
|
postUpdateHook: () => any;
|
2016-02-25 07:55:31 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
2016-03-25 09:35:58 -05:00
|
|
|
constructor(private $scope,
|
|
|
|
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-13 14:18:45 -05:00
|
|
|
this.tabs = ['Overview'];
|
2016-03-25 09:35:58 -05:00
|
|
|
|
|
|
|
this.preUpdateHook = () => Promise.resolve();
|
|
|
|
this.postUpdateHook = () => Promise.resolve();
|
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() {
|
2016-03-11 02:57:20 -06:00
|
|
|
return this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(result => {
|
2016-02-25 07:55:31 -06:00
|
|
|
this.model = result;
|
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
|
|
|
|
2016-03-08 05:31:37 -06:00
|
|
|
this.includes = _.map(result.includes, plug => {
|
|
|
|
plug.icon = this.getPluginIcon(plug.type);
|
|
|
|
return plug;
|
|
|
|
});
|
|
|
|
|
2016-03-13 14:18:45 -05:00
|
|
|
if (this.model.type === 'app') {
|
|
|
|
this.tabs.push('Config');
|
|
|
|
|
|
|
|
this.hasDashboards = _.findWhere(result.includes, {type: 'dashboard'});
|
|
|
|
if (this.hasDashboards) {
|
|
|
|
this.tabs.push('Dashboards');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 11:03:45 -06:00
|
|
|
return this.initReadme();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initReadme() {
|
2016-03-13 13:21:44 -05:00
|
|
|
return this.backendSrv.get(`/api/plugins/${this.pluginId}/readme`).then(res => {
|
2016-03-07 11:03:45 -06:00
|
|
|
return System.import('remarkable').then(Remarkable => {
|
|
|
|
var md = new Remarkable();
|
2016-03-13 13:21:44 -05:00
|
|
|
this.readmeHtml = this.$sce.trustAsHtml(md.render(res));
|
2016-03-07 11:03:45 -06:00
|
|
|
});
|
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-03-08 05:31:37 -06:00
|
|
|
case 'page': return 'icon-gf icon-gf-share';
|
2016-03-13 14:18:45 -05:00
|
|
|
case 'dashboard': return 'icon-gf icon-gf-dashboard';
|
2016-03-07 07:31:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 07:55:31 -06:00
|
|
|
update() {
|
2016-03-25 09:35:58 -05:00
|
|
|
this.preUpdateHook().then(() => {
|
2016-03-02 00:21:25 -06:00
|
|
|
var updateCmd = _.extend({
|
2016-03-25 09:35:58 -05:00
|
|
|
enabled: this.model.enabled,
|
|
|
|
pinned: this.model.pinned,
|
|
|
|
jsonData: this.model.jsonData,
|
|
|
|
secureJsonData: this.model.secureJsonData,
|
2016-03-02 00:21:25 -06:00
|
|
|
}, {});
|
|
|
|
|
2016-03-25 09:35:58 -05:00
|
|
|
return this.backendSrv.post(`/api/plugins/${this.pluginId}/settings`, updateCmd);
|
|
|
|
})
|
|
|
|
.then(this.postUpdateHook)
|
|
|
|
.then((res) => {
|
|
|
|
window.location.href = window.location.href;
|
2016-03-02 00:21:25 -06:00
|
|
|
});
|
2016-03-25 09:35:58 -05:00
|
|
|
}
|
2016-03-02 00:21:25 -06:00
|
|
|
|
2016-03-25 09:35:58 -05:00
|
|
|
importDashboards() {
|
|
|
|
// move to dashboards tab
|
|
|
|
this.tabIndex = 2;
|
2016-03-02 00:21:25 -06:00
|
|
|
|
2016-03-25 09:35:58 -05:00
|
|
|
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
|
|
|
|
});
|
|
|
|
});
|
2016-02-25 07:55:31 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-03-02 00:21:25 -06:00
|
|
|
setPreUpdateHook(callback: () => any) {
|
|
|
|
this.preUpdateHook = callback;
|
|
|
|
}
|
|
|
|
|
2016-03-13 14:18:45 -05:00
|
|
|
setPostUpdateHook(callback: () => any) {
|
2016-03-02 00:21:25 -06:00
|
|
|
this.postUpdateHook = callback;
|
|
|
|
}
|
|
|
|
|
2016-03-13 14:18:45 -05:00
|
|
|
enable() {
|
|
|
|
this.model.enabled = true;
|
|
|
|
this.model.pinned = true;
|
2016-02-25 07:55:31 -06:00
|
|
|
this.update();
|
|
|
|
}
|
|
|
|
|
2016-03-25 07:43:13 -05:00
|
|
|
disable() {
|
|
|
|
this.model.enabled = false;
|
|
|
|
this.model.pinned = false;
|
|
|
|
this.update();
|
|
|
|
}
|
2016-02-25 07:55:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
angular.module('grafana.controllers').controller('PluginEditCtrl', PluginEditCtrl);
|
|
|
|
|