ds_list_ctrl.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import coreModule from '../../core/core_module';
  2. import _ from 'lodash';
  3. export class DataSourcesCtrl {
  4. datasources: any;
  5. unfiltered: any;
  6. navModel: any;
  7. searchQuery: string;
  8. /** @ngInject */
  9. constructor(
  10. private $scope,
  11. private backendSrv,
  12. private datasourceSrv,
  13. private navModelSrv) {
  14. this.navModel = this.navModelSrv.getNav('cfg', 'datasources', 0);
  15. backendSrv.get('/api/datasources').then(result => {
  16. this.datasources = result;
  17. this.unfiltered = result;
  18. });
  19. }
  20. onQueryUpdated() {
  21. let regex = new RegExp(this.searchQuery, 'ig');
  22. this.datasources = _.filter(this.unfiltered, item => {
  23. return regex.test(item.name) || regex.test(item.type);
  24. });
  25. }
  26. removeDataSourceConfirmed(ds) {
  27. this.backendSrv.delete('/api/datasources/' + ds.id)
  28. .then(() => {
  29. this.$scope.appEvent('alert-success', ['Datasource deleted', '']);
  30. }, () => {
  31. this.$scope.appEvent('alert-error', ['Unable to delete datasource', '']);
  32. }).then(() => {
  33. this.backendSrv.get('/api/datasources')
  34. .then((result) => {
  35. this.datasources = result;
  36. });
  37. this.backendSrv.get('/api/frontend/settings')
  38. .then((settings) => {
  39. this.datasourceSrv.init(settings.datasources);
  40. });
  41. });
  42. }
  43. removeDataSource(ds) {
  44. this.$scope.appEvent('confirm-modal', {
  45. title: 'Delete',
  46. text: 'Are you sure you want to delete datasource ' + ds.name + '?',
  47. yesText: "Delete",
  48. icon: "fa-trash",
  49. onConfirm: () => {
  50. this.removeDataSourceConfirmed(ds);
  51. }
  52. });
  53. }
  54. }
  55. coreModule.controller('DataSourcesCtrl', DataSourcesCtrl);