ds_list_ctrl.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ///<reference path="../../headers/common.d.ts" />
  2. import coreModule from '../../core/core_module';
  3. export class DataSourcesCtrl {
  4. datasources: any;
  5. navModel: any;
  6. /** @ngInject */
  7. constructor(
  8. private $scope,
  9. private backendSrv,
  10. private datasourceSrv,
  11. private navModelSrv
  12. ) {
  13. this.navModel = this.navModelSrv.getDatasourceNav(0);
  14. backendSrv.get('/api/datasources').then(result => {
  15. this.datasources = result;
  16. });
  17. }
  18. removeDataSourceConfirmed(ds) {
  19. this.backendSrv.delete('/api/datasources/' + ds.id)
  20. .then(() => {
  21. this.$scope.appEvent('alert-success', ['Datasource deleted', '']);
  22. }, () => {
  23. this.$scope.appEvent('alert-error', ['Unable to delete datasource', '']);
  24. }).then(() => {
  25. this.backendSrv.get('/api/datasources')
  26. .then((result) => {
  27. this.datasources = result;
  28. });
  29. this.backendSrv.get('/api/frontend/settings')
  30. .then((settings) => {
  31. this.datasourceSrv.init(settings.datasources);
  32. });
  33. });
  34. }
  35. removeDataSource(ds) {
  36. this.$scope.appEvent('confirm-modal', {
  37. title: 'Delete',
  38. text: 'Are you sure you want to delete datasource ' + ds.name + '?',
  39. yesText: "Delete",
  40. icon: "fa-trash",
  41. onConfirm: () => {
  42. this.removeDataSourceConfirmed(ds);
  43. }
  44. });
  45. }
  46. }
  47. coreModule.controller('DataSourcesCtrl', DataSourcesCtrl);