plugin_page_ctrl.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. var pluginInfoCache = {};
  5. export class AppPageCtrl {
  6. page: any;
  7. pluginId: any;
  8. appModel: any;
  9. navModel: any;
  10. /** @ngInject */
  11. constructor(private backendSrv, private $routeParams: any, private $rootScope, private navModelSrv) {
  12. this.pluginId = $routeParams.pluginId;
  13. if (pluginInfoCache[this.pluginId]) {
  14. this.initPage(pluginInfoCache[this.pluginId]);
  15. } else {
  16. this.loadPluginInfo();
  17. }
  18. }
  19. initPage(app) {
  20. this.appModel = app;
  21. this.page = _.find(app.includes, {slug: this.$routeParams.slug});
  22. pluginInfoCache[this.pluginId] = app;
  23. if (!this.page) {
  24. this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
  25. this.navModel = this.navModelSrv.getNotFoundNav();
  26. return;
  27. }
  28. this.navModel = this.navModelSrv.getNav('plugin-page-' + app.id);
  29. this.navModel.breadcrumbs.push({text: this.page.name});
  30. }
  31. loadPluginInfo() {
  32. this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
  33. this.initPage(app);
  34. });
  35. }
  36. }
  37. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);