plugin_page_ctrl.ts 1.7 KB

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