list_ctrl.ts 1.5 KB

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