snapshot_ctrl.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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.delete('/api/snapshots/' + snapshot.key).then(
  16. () => {},
  17. () => {
  18. this.snapshots.push(snapshot);
  19. }
  20. );
  21. }
  22. removeSnapshot(snapshot) {
  23. this.$rootScope.appEvent('confirm-modal', {
  24. title: 'Delete',
  25. text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
  26. yesText: 'Delete',
  27. icon: 'fa-trash',
  28. onConfirm: () => {
  29. this.removeSnapshotConfirmed(snapshot);
  30. },
  31. });
  32. }
  33. }
  34. angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);