ds_dashboards_ctrl.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { toJS } from 'mobx';
  2. import { coreModule } from 'app/core/core';
  3. import { store } from 'app/stores/store';
  4. export class DataSourceDashboardsCtrl {
  5. datasourceMeta: any;
  6. navModel: any;
  7. current: any;
  8. /** @ngInject */
  9. constructor(private backendSrv, private $routeParams) {
  10. if (store.nav.main === null) {
  11. store.nav.load('cfg', 'datasources');
  12. }
  13. this.navModel = toJS(store.nav);
  14. if (this.$routeParams.id) {
  15. this.getDatasourceById(this.$routeParams.id);
  16. }
  17. }
  18. getDatasourceById(id) {
  19. this.backendSrv
  20. .get('/api/datasources/' + id)
  21. .then(ds => {
  22. this.current = ds;
  23. })
  24. .then(this.getPluginInfo.bind(this));
  25. }
  26. updateNav() {
  27. store.nav.initDatasourceEditNav(this.current, this.datasourceMeta, 'datasource-dashboards');
  28. this.navModel = toJS(store.nav);
  29. }
  30. getPluginInfo() {
  31. return this.backendSrv.get('/api/plugins/' + this.current.type + '/settings').then(pluginInfo => {
  32. this.datasourceMeta = pluginInfo;
  33. this.updateNav();
  34. });
  35. }
  36. }
  37. coreModule.controller('DataSourceDashboardsCtrl', DataSourceDashboardsCtrl);