plugin_page_ctrl.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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(private backendSrv, private $routeParams: any, private $rootScope, private navModelSrv) {
  11. this.pluginId = $routeParams.pluginId;
  12. if (pluginInfoCache[this.pluginId]) {
  13. this.initPage(pluginInfoCache[this.pluginId]);
  14. } else {
  15. this.loadPluginInfo();
  16. }
  17. }
  18. initPage(app) {
  19. this.appModel = app;
  20. this.page = _.find(app.includes, { slug: this.$routeParams.slug });
  21. pluginInfoCache[this.pluginId] = app;
  22. if (!this.page) {
  23. this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
  24. this.navModel = this.navModelSrv.getNotFoundNav();
  25. return;
  26. }
  27. const pluginNav = this.navModelSrv.getNav('plugin-page-' + app.id);
  28. this.navModel = {
  29. main: {
  30. img: app.info.logos.large,
  31. subTitle: app.name,
  32. url: '',
  33. text: this.page.name,
  34. breadcrumbs: [{ title: app.name, url: pluginNav.main.url }],
  35. },
  36. };
  37. }
  38. loadPluginInfo() {
  39. this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
  40. this.initPage(app);
  41. });
  42. }
  43. }
  44. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);