2017-12-20 12:33:33 +01:00
|
|
|
import angular from 'angular';
|
|
|
|
|
import _ from 'lodash';
|
2016-02-09 11:17:49 +01:00
|
|
|
|
2016-03-23 16:37:58 +01:00
|
|
|
var pluginInfoCache = {};
|
|
|
|
|
|
2016-02-09 11:17:49 +01:00
|
|
|
export class AppPageCtrl {
|
|
|
|
|
page: any;
|
2016-02-29 15:50:02 +08:00
|
|
|
pluginId: any;
|
2016-02-09 11:17:49 +01:00
|
|
|
appModel: any;
|
2017-08-15 20:24:16 +02:00
|
|
|
navModel: any;
|
2016-02-09 11:17:49 +01:00
|
|
|
|
|
|
|
|
/** @ngInject */
|
2017-12-21 08:39:31 +01:00
|
|
|
constructor(private backendSrv, private $routeParams: any, private $rootScope, private navModelSrv) {
|
2016-02-29 15:50:02 +08:00
|
|
|
this.pluginId = $routeParams.pluginId;
|
2016-03-21 19:07:08 +01:00
|
|
|
|
2016-03-23 16:37:58 +01:00
|
|
|
if (pluginInfoCache[this.pluginId]) {
|
2016-03-23 16:43:32 +01:00
|
|
|
this.initPage(pluginInfoCache[this.pluginId]);
|
2016-03-23 16:37:58 +01:00
|
|
|
} else {
|
|
|
|
|
this.loadPluginInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-23 16:43:32 +01:00
|
|
|
initPage(app) {
|
|
|
|
|
this.appModel = app;
|
2017-12-19 16:06:54 +01:00
|
|
|
this.page = _.find(app.includes, { slug: this.$routeParams.slug });
|
2016-03-23 16:37:58 +01:00
|
|
|
|
2016-03-23 16:43:32 +01:00
|
|
|
pluginInfoCache[this.pluginId] = app;
|
2016-03-22 10:15:47 +01:00
|
|
|
|
2016-03-23 16:43:32 +01:00
|
|
|
if (!this.page) {
|
2017-12-20 12:33:33 +01:00
|
|
|
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
|
2017-06-02 14:00:42 +02:00
|
|
|
|
2017-08-15 20:24:16 +02:00
|
|
|
this.navModel = this.navModelSrv.getNotFoundNav();
|
2017-06-02 14:00:42 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
let pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
|
2017-12-13 11:12:09 +01:00
|
|
|
|
|
|
|
|
this.navModel = {
|
|
|
|
|
main: {
|
|
|
|
|
img: app.info.logos.large,
|
|
|
|
|
subTitle: app.name,
|
2017-12-20 12:33:33 +01:00
|
|
|
url: '',
|
2018-01-11 17:53:06 +01:00
|
|
|
text: this.page.name,
|
|
|
|
|
breadcrumbs: [{ title: app.name, url: pluginNav.main.url }],
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
2017-12-13 11:12:09 +01:00
|
|
|
};
|
2016-03-23 16:43:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadPluginInfo() {
|
|
|
|
|
this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
|
|
|
|
|
this.initPage(app);
|
2016-02-09 11:17:49 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);
|