plugin_page_ctrl.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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, private $q) {
  12. this.pluginId = $routeParams.pluginId;
  13. this.$q
  14. .when(getPluginSettings(this.pluginId))
  15. .then(settings => {
  16. this.initPage(settings);
  17. })
  18. .catch(err => {
  19. this.$rootScope.appEvent('alert-error', ['Unknown Plugin', '']);
  20. this.navModel = this.navModelSrv.getNotFoundNav();
  21. });
  22. }
  23. initPage(app: PluginMeta) {
  24. this.appModel = app;
  25. this.page = _.find(app.includes, { slug: this.$routeParams.slug });
  26. if (!this.page) {
  27. this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
  28. this.navModel = this.navModelSrv.getNotFoundNav();
  29. return;
  30. }
  31. if (app.type !== 'app' || !app.enabled) {
  32. this.$rootScope.appEvent('alert-error', ['Application Not Enabled', '']);
  33. this.navModel = this.navModelSrv.getNotFoundNav();
  34. return;
  35. }
  36. const pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
  37. this.navModel = {
  38. main: {
  39. img: app.info.logos.large,
  40. subTitle: app.name,
  41. url: '',
  42. text: this.page.name,
  43. breadcrumbs: [{ title: app.name, url: pluginNav.main.url }],
  44. },
  45. };
  46. }
  47. }
  48. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);