snapshot_ctrl.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define([
  2. 'angular',
  3. 'lodash'
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('grafana.controllers');
  8. module.controller('SnapshotsCtrl', function($scope, $location, backendSrv) {
  9. backendSrv.get('/api/dashboard/snapshots')
  10. .then(function(result) {
  11. $scope.snapshots = result;
  12. });
  13. $scope.removeSnapshotConfirmed = function(snapshot) {
  14. _.remove($scope.snapshots, {Key: snapshot.Key});
  15. backendSrv.get('/api/snapshots-delete/' + snapshot.DeleteKey)
  16. .then(function() {
  17. $scope.appEvent('alert-success', ['Snapshot deleted', '']);
  18. }, function() {
  19. $scope.appEvent('alert-error', ['Unable to delete snapshot', '']);
  20. $scope.snapshots.push(snapshot);
  21. });
  22. };
  23. $scope.removeSnapshot = function(snapshot) {
  24. $scope.appEvent('confirm-modal', {
  25. title: 'Confirm delete snapshot',
  26. text: 'Are you sure you want to delete snapshot ' + snapshot.Name + '?',
  27. yesText: "Delete",
  28. icon: "fa-warning",
  29. onConfirm: function() {
  30. $scope.removeSnapshotConfirmed(snapshot);
  31. }
  32. });
  33. };
  34. });
  35. });