list_ctrl.ts 1.4 KB

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