ds_list_ctrl.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. this.navModel = this.navModelSrv.getNav('cfg', 'datasources');
  13. backendSrv.get('/api/datasources').then(result => {
  14. this.datasources = result;
  15. });
  16. }
  17. removeDataSourceConfirmed(ds) {
  18. this.backendSrv.delete('/api/datasources/' + ds.id)
  19. .then(() => {
  20. this.$scope.appEvent('alert-success', ['Datasource deleted', '']);
  21. }, () => {
  22. this.$scope.appEvent('alert-error', ['Unable to delete datasource', '']);
  23. }).then(() => {
  24. this.backendSrv.get('/api/datasources')
  25. .then((result) => {
  26. this.datasources = result;
  27. });
  28. this.backendSrv.get('/api/frontend/settings')
  29. .then((settings) => {
  30. this.datasourceSrv.init(settings.datasources);
  31. });
  32. });
  33. }
  34. removeDataSource(ds) {
  35. this.$scope.appEvent('confirm-modal', {
  36. title: 'Delete',
  37. text: 'Are you sure you want to delete datasource ' + ds.name + '?',
  38. yesText: "Delete",
  39. icon: "fa-trash",
  40. onConfirm: () => {
  41. this.removeDataSourceConfirmed(ds);
  42. }
  43. });
  44. }
  45. }
  46. coreModule.controller('DataSourcesCtrl', DataSourcesCtrl);