plugin_page_ctrl.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. let 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: '',
  34. breadcrumbs: [
  35. { title: app.name, url: pluginNav.main.url },
  36. { title: this.page.name },
  37. ],
  38. }
  39. };
  40. }
  41. loadPluginInfo() {
  42. this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
  43. this.initPage(app);
  44. });
  45. }
  46. }
  47. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);