plugin_page_ctrl.ts 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.appModel = pluginInfoCache[this.pluginId];
  15. } else {
  16. this.loadPluginInfo();
  17. }
  18. }
  19. loadPluginInfo() {
  20. this.backendSrv.get(`/api/plugins/${this.pluginId}/settings`).then(app => {
  21. this.appModel = app;
  22. this.page = _.findWhere(app.includes, {slug: this.$routeParams.slug});
  23. this.appLogoUrl = app.info.logos.small;
  24. pluginInfoCache[this.pluginId] = app;
  25. if (!this.page) {
  26. this.$rootScope.appEvent('alert-error', ['App Page Not Found', '']);
  27. }
  28. });
  29. }
  30. }
  31. angular.module('grafana.controllers').controller('AppPageCtrl', AppPageCtrl);