snapshot_ctrl.ts 1.2 KB

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