grafana/public/app/features/plugins/plugin_page_ctrl.ts
teajo 80cca9c12e AppPlugin: avoid app plugin navigation slowness (#16675)
navigation between pages in app plugin is slow, due to use of non angular native promise

Fixes #16672
2019-04-19 08:41:59 -07:00

58 lines
1.6 KiB
TypeScript

import angular from 'angular';
import _ from 'lodash';
import { getPluginSettings } from './PluginSettingsCache';
import { PluginMeta } from '@grafana/ui';
export class AppPageCtrl {
page: any;
pluginId: any;
appModel: any;
navModel: any;
/** @ngInject */
constructor(private $routeParams: any, private $rootScope, private navModelSrv, private $q) {
this.pluginId = $routeParams.pluginId;
this.$q
.when(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) {
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', '']);
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,
url: '',
text: this.page.name,
breadcrumbs: [{ title: app.name, url: pluginNav.main.url }],
},
};
}
}
angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);