SnapshotListCtrl.ts 935 B

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