ds_list_ctrl.ts 1.5 KB

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