plugin_page_ctrl.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. var pluginInfoCache = {};
  4. export class AppPageCtrl {
  5. page: any;
  6. pluginId: any;
  7. appModel: any;
  8. navModel: any;
  9. /** @ngInject */
  10. constructor(
  11. private backendSrv,
  12. private $routeParams: any,
  13. private $rootScope,
  14. private navModelSrv
  15. ) {
  16. this.pluginId = $routeParams.pluginId;
  17. if (pluginInfoCache[this.pluginId]) {
  18. this.initPage(pluginInfoCache[this.pluginId]);
  19. } else {
  20. this.loadPluginInfo();
  21. }
  22. }
  23. initPage(app) {
  24. this.appModel = app;
  25. this.page = _.find(app.includes, { slug: this.$routeParams.slug });
  26. pluginInfoCache[this.pluginId] = app;
  27. if (!this.page) {
  28. this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
  29. this.navModel = this.navModelSrv.getNotFoundNav();
  30. return;
  31. }
  32. let pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
  33. this.navModel = {
  34. main: {
  35. img: app.info.logos.large,
  36. subTitle: app.name,
  37. url: '',
  38. text: '',
  39. breadcrumbs: [
  40. { title: app.name, url: pluginNav.main.url },
  41. { title: this.page.name },
  42. ],
  43. },
  44. };
  45. }
  46. loadPluginInfo() {
  47. this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
  48. this.initPage(app);
  49. });
  50. }
  51. }
  52. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);