snapshot_ctrl.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. export class SnapshotsCtrl {
  5. snapshots: any;
  6. /** @ngInject */
  7. constructor(private $rootScope, private backendSrv) {
  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.get('/api/snapshots-delete/' + snapshot.deleteKey)
  15. .then(() => {
  16. this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
  17. }, () => {
  18. this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
  19. this.snapshots.push(snapshot);
  20. });
  21. }
  22. removeSnapshot(snapshot) {
  23. this.$rootScope.appEvent('confirm-modal', {
  24. title: 'Confirm delete snapshot',
  25. text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
  26. yesText: "Delete",
  27. icon: "fa-warning",
  28. onConfirm: () => {
  29. this.removeSnapshotConfirmed(snapshot);
  30. }
  31. });
  32. }
  33. }
  34. angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);