snapshot_ctrl.ts 1.2 KB

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