snapshot_ctrl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import angular from 'angular';
  2. import _ from 'lodash';
  3. export class SnapshotsCtrl {
  4. navModel: any;
  5. snapshots: any;
  6. /** @ngInject */
  7. constructor(private $rootScope, private backendSrv, navModelSrv) {
  8. this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
  9. this.backendSrv.get('/api/dashboard/snapshots').then(result => {
  10. this.snapshots = result;
  11. });
  12. }
  13. removeSnapshotConfirmed(snapshot) {
  14. _.remove(this.snapshots, { key: snapshot.key });
  15. this.backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey).then(
  16. () => {
  17. this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
  18. },
  19. () => {
  20. this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
  21. this.snapshots.push(snapshot);
  22. }
  23. );
  24. }
  25. removeSnapshot(snapshot) {
  26. this.$rootScope.appEvent('confirm-modal', {
  27. title: 'Delete',
  28. text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
  29. yesText: 'Delete',
  30. icon: 'fa-trash',
  31. onConfirm: () => {
  32. this.removeSnapshotConfirmed(snapshot);
  33. },
  34. });
  35. }
  36. }
  37. angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);