2016-02-25 07:55:31 -06:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
2017-08-31 07:05:52 -05:00
|
|
|
import Remarkable from 'remarkable';
|
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;
|
2017-12-13 04:12:09 -06:00
|
|
|
tab: string;
|
2017-06-02 07:00:42 -05:00
|
|
|
navModel: any;
|
2016-03-13 14:18:45 -05:00
|
|
|
hasDashboards: any;
|
2016-03-02 00:21:25 -06:00
|
|
|
preUpdateHook: () => any;
|
|
|
|
postUpdateHook: () => any;
|
2016-02-25 07:55:31 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-06-02 07:00:42 -05:00
|
|
|
constructor(
|
|
|
|
private $scope,
|
|
|
|
private $rootScope,
|
|
|
|
private backendSrv,
|
|
|
|
private $sce,
|
2017-12-13 04:12:09 -06:00
|
|
|
private $routeParams,
|
2017-09-21 09:40:18 -05:00
|
|
|
navModelSrv,
|
2017-06-02 07:00:42 -05:00
|
|
|
) {
|
2016-03-25 09:35:58 -05:00
|
|
|
|
2017-12-13 04:12:09 -06:00
|
|
|
this.pluginId = $routeParams.pluginId;
|
2016-03-25 09:35:58 -05:00
|
|
|
this.preUpdateHook = () => Promise.resolve();
|
|
|
|
this.postUpdateHook = () => Promise.resolve();
|
2017-12-13 04:12:09 -06:00
|
|
|
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
setNavModel(model) {
|
|
|
|
let defaultTab = 'readme';
|
|
|
|
|
|
|
|
this.navModel = {
|
|
|
|
main: {
|
|
|
|
img: model.info.logos.large,
|
|
|
|
subTitle: model.info.description,
|
|
|
|
url: '',
|
|
|
|
text: '',
|
|
|
|
breadcrumbs: [
|
|
|
|
{ title: 'Plugins', url: '/plugins' },
|
|
|
|
{ title: model.name },
|
|
|
|
],
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
icon: 'fa fa-fw fa-file-text-o',
|
|
|
|
id: 'readme',
|
|
|
|
text: 'Readme',
|
|
|
|
url: `plugins/${this.model.id}/edit?tab=readme`
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (model.type === 'app') {
|
|
|
|
this.navModel.main.children.push({
|
2017-12-13 16:48:44 -06:00
|
|
|
icon: 'gicon gicon-cog',
|
2017-12-13 04:12:09 -06:00
|
|
|
id: 'config',
|
|
|
|
text: 'Config',
|
|
|
|
url: `plugins/${this.model.id}/edit?tab=config`
|
|
|
|
});
|
|
|
|
|
|
|
|
let hasDashboards = _.find(model.includes, {type: 'dashboard'});
|
|
|
|
|
|
|
|
if (hasDashboards) {
|
|
|
|
this.navModel.main.children.push({
|
|
|
|
icon: 'gicon gicon-dashboard',
|
|
|
|
id: 'dashboards',
|
|
|
|
text: 'Dashboards',
|
|
|
|
url: `plugins/${this.model.id}/edit?tab=dashboards`
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultTab = 'config';
|
|
|
|
}
|
|
|
|
|
|
|
|
this.tab = this.$routeParams.tab || defaultTab;
|
|
|
|
|
|
|
|
for (let tab of this.navModel.main.children) {
|
|
|
|
if (tab.id === this.tab) {
|
|
|
|
tab.active = true;
|
|
|
|
}
|
|
|
|
}
|
2017-06-02 07:00:42 -05: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;
|
|
|
|
});
|
|
|
|
|
2017-12-13 04:12:09 -06:00
|
|
|
this.setNavModel(this.model);
|
2016-03-07 11:03:45 -06:00
|
|
|
return this.initReadme();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initReadme() {
|
2017-08-31 07:05:52 -05:00
|
|
|
return this.backendSrv.get(`/api/plugins/${this.pluginId}/markdown/readme`).then(res => {
|
|
|
|
var md = new Remarkable();
|
|
|
|
this.readmeHtml = this.$sce.trustAsHtml(md.render(res));
|
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-04-11 18:01:18 -05:00
|
|
|
case 'page': return 'icon-gf icon-gf-endpoint-tiny';
|
2016-03-13 14:18:45 -05:00
|
|
|
case 'dashboard': return 'icon-gf icon-gf-dashboard';
|
2017-09-26 04:24:58 -05:00
|
|
|
default: return 'icon-gf icon-gf-apps';
|
2016-03-07 07:31:02 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-25 07:55:31 -06:00
|
|
|
update() {
|
2016-05-12 07:45:32 -05:00
|
|
|
this.preUpdateHook().then(() => {
|
|
|
|
var updateCmd = _.extend({
|
|
|
|
enabled: this.model.enabled,
|
|
|
|
pinned: this.model.pinned,
|
|
|
|
jsonData: this.model.jsonData,
|
|
|
|
secureJsonData: this.model.secureJsonData,
|
|
|
|
}, {});
|
|
|
|
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() {
|
2016-07-08 05:26:51 -05:00
|
|
|
return Promise.resolve();
|
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-04-11 19:33:58 -05:00
|
|
|
updateAvailable() {
|
|
|
|
var modalScope = this.$scope.$new(true);
|
|
|
|
modalScope.plugin = this.model;
|
|
|
|
|
|
|
|
this.$rootScope.appEvent('show-modal', {
|
|
|
|
src: 'public/app/features/plugins/partials/update_instructions.html',
|
|
|
|
scope: modalScope
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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);
|