SnapshotListCtrl.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import _ from 'lodash';
  2. export class SnapshotListCtrl {
  3. navModel: any;
  4. snapshots: any;
  5. /** @ngInject */
  6. constructor(private $rootScope, private backendSrv, navModelSrv, private $location) {
  7. this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
  8. this.backendSrv.get('/api/dashboard/snapshots').then(result => {
  9. const baseUrl = this.$location.absUrl().replace($location.url(), '');
  10. this.snapshots = result.map(snapshot => ({
  11. ...snapshot,
  12. url: snapshot.externalUrl || `${baseUrl}/dashboard/snapshot/${snapshot.key}`,
  13. }));
  14. });
  15. }
  16. removeSnapshotConfirmed(snapshot) {
  17. _.remove(this.snapshots, { key: snapshot.key });
  18. this.backendSrv.delete('/api/snapshots/' + snapshot.key).then(
  19. () => {},
  20. () => {
  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. }