snapshot_ctrl.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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) {
  9. this.navModel = {
  10. section: {
  11. title: 'Snapshots',
  12. icon: 'icon-gf icon-gf-snapshot',
  13. url: 'dashboard/snapshots',
  14. },
  15. menu: [],
  16. };
  17. this.backendSrv.get('/api/dashboard/snapshots').then(result => {
  18. this.snapshots = result;
  19. });
  20. }
  21. removeSnapshotConfirmed(snapshot) {
  22. _.remove(this.snapshots, {key: snapshot.key});
  23. this.backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey)
  24. .then(() => {
  25. this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
  26. }, () => {
  27. this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
  28. this.snapshots.push(snapshot);
  29. });
  30. }
  31. removeSnapshot(snapshot) {
  32. this.$rootScope.appEvent('confirm-modal', {
  33. title: 'Delete',
  34. text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
  35. yesText: "Delete",
  36. icon: "fa-trash",
  37. onConfirm: () => {
  38. this.removeSnapshotConfirmed(snapshot);
  39. }
  40. });
  41. }
  42. }
  43. angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);