grafana/public/app/features/plugins/plugin_page_ctrl.ts

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2016-02-09 04:17:49 -06:00
import angular from 'angular';
import _ from 'lodash';
var pluginInfoCache = {};
2016-02-09 04:17:49 -06:00
export class AppPageCtrl {
page: any;
pluginId: any;
2016-02-09 04:17:49 -06:00
appModel: any;
2017-08-15 13:24:16 -05:00
navModel: any;
2016-02-09 04:17:49 -06:00
/** @ngInject */
2017-08-15 13:24:16 -05:00
constructor(private backendSrv, private $routeParams: any, private $rootScope, private navModelSrv) {
this.pluginId = $routeParams.pluginId;
if (pluginInfoCache[this.pluginId]) {
this.initPage(pluginInfoCache[this.pluginId]);
} else {
this.loadPluginInfo();
}
}
initPage(app) {
this.appModel = app;
2016-09-13 15:10:44 -05:00
this.page = _.find(app.includes, {slug: this.$routeParams.slug});
pluginInfoCache[this.pluginId] = app;
if (!this.page) {
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
2017-08-15 13:24:16 -05:00
this.navModel = this.navModelSrv.getNotFoundNav();
return;
}
let pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
this.navModel = {
main: {
img: app.info.logos.large,
subTitle: app.name,
url: '',
text: '',
breadcrumbs: [
{ title: app.name, url: pluginNav.main.url },
{ title: this.page.name },
],
}
};
}
loadPluginInfo() {
this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
this.initPage(app);
2016-02-09 04:17:49 -06:00
});
}
}
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);