ds_list_ctrl.ts 1.7 KB

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