plugin_page_ctrl.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. appLogoUrl: any;
  10. /** @ngInject */
  11. constructor(private backendSrv, private $routeParams: any, private $rootScope) {
  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 = _.findWhere(app.includes, {slug: this.$routeParams.slug});
  22. this.appLogoUrl = app.info.logos.small;
  23. pluginInfoCache[this.pluginId] = app;
  24. if (!this.page) {
  25. this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
  26. }
  27. }
  28. loadPluginInfo() {
  29. this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
  30. this.initPage(app);
  31. });
  32. }
  33. }
  34. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);