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

57 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import angular from 'angular';
import _ from 'lodash';
2016-02-09 04:17:49 -06:00
import { getPluginSettings } from './PluginSettingsCache';
import { PluginMeta } from '@grafana/ui';
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 */
constructor(private $routeParams: any, private $rootScope, private navModelSrv) {
this.pluginId = $routeParams.pluginId;
getPluginSettings(this.pluginId)
.then(settings => {
this.initPage(settings);
})
.catch(err => {
this.$rootScope.appEvent('alert-error', ['Unknown Plugin', '']);
this.navModel = this.navModelSrv.getNotFoundNav();
});
}
initPage(app: PluginMeta) {
this.appModel = app;
this.page = _.find(app.includes, { slug: this.$routeParams.slug });
if (!this.page) {
2017-12-20 05:33:33 -06:00
this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
this.navModel = this.navModelSrv.getNotFoundNav();
return;
}
if (app.type !== 'app' || !app.enabled) {
this.$rootScope.appEvent('alert-error', ['Applicaiton Not Enabled', '']);
2017-08-15 13:24:16 -05:00
this.navModel = this.navModelSrv.getNotFoundNav();
return;
}
const pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
this.navModel = {
main: {
img: app.info.logos.large,
subTitle: app.name,
2017-12-20 05:33:33 -06:00
url: '',
text: this.page.name,
breadcrumbs: [{ title: app.name, url: pluginNav.main.url }],
2017-12-20 05:33:33 -06:00
},
};
}
2016-02-09 04:17:49 -06:00
}
2017-12-20 05:33:33 -06:00
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);