plugin_page_ctrl.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. import { getPluginSettings } from './PluginSettingsCache';
  4. import { PluginMeta } from '@grafana/ui';
  5. export class AppPageCtrl {
  6. page: any;
  7. pluginId: any;
  8. appModel: any;
  9. navModel: any;
  10. /** @ngInject */
  11. constructor(private $routeParams: any, private $rootScope, private navModelSrv) {
  12. this.pluginId = $routeParams.pluginId;
  13. getPluginSettings(this.pluginId)
  14. .then(settings => {
  15. this.initPage(settings);
  16. })
  17. .catch(err => {
  18. this.$rootScope.appEvent('alert-error', ['Unknown Plugin', '']);
  19. this.navModel = this.navModelSrv.getNotFoundNav();
  20. });
  21. }
  22. initPage(app: PluginMeta) {
  23. this.appModel = app;
  24. this.page = _.find(app.includes, { slug: this.$routeParams.slug });
  25. if (!this.page) {
  26. this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
  27. this.navModel = this.navModelSrv.getNotFoundNav();
  28. return;
  29. }
  30. if (app.type !== 'app' || !app.enabled) {
  31. this.$rootScope.appEvent('alert-error', ['Applicaiton Not Enabled', '']);
  32. this.navModel = this.navModelSrv.getNotFoundNav();
  33. return;
  34. }
  35. const pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
  36. this.navModel = {
  37. main: {
  38. img: app.info.logos.large,
  39. subTitle: app.name,
  40. url: '',
  41. text: this.page.name,
  42. breadcrumbs: [{ title: app.name, url: pluginNav.main.url }],
  43. },
  44. };
  45. }
  46. }
  47. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);