ds_dashboards_ctrl.ts 1007 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 (this.$routeParams.id) {
  11. this.getDatasourceById(this.$routeParams.id);
  12. }
  13. }
  14. getDatasourceById(id) {
  15. this.backendSrv
  16. .get('/api/datasources/' + id)
  17. .then(ds => {
  18. this.current = ds;
  19. })
  20. .then(this.getPluginInfo.bind(this));
  21. }
  22. updateNav() {
  23. store.nav.initDatasourceEditNav(this.current, this.datasourceMeta, 'datasource-dashboards');
  24. this.navModel = toJS(store.nav);
  25. }
  26. getPluginInfo() {
  27. return this.backendSrv.get('/api/plugins/' + this.current.type + '/settings').then(pluginInfo => {
  28. this.datasourceMeta = pluginInfo;
  29. this.updateNav();
  30. });
  31. }
  32. }
  33. coreModule.controller('DataSourceDashboardsCtrl', DataSourceDashboardsCtrl);