ds_dashboards_ctrl.ts 1.1 KB

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