ds_list_ctrl.ts 1.5 KB

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