snapshot_ctrl.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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", [
  22. "Unable to delete snapshot",
  23. ""
  24. ]);
  25. this.snapshots.push(snapshot);
  26. }
  27. );
  28. }
  29. removeSnapshot(snapshot) {
  30. this.$rootScope.appEvent("confirm-modal", {
  31. title: "Delete",
  32. text: "Are you sure you want to delete snapshot " + snapshot.name + "?",
  33. yesText: "Delete",
  34. icon: "fa-trash",
  35. onConfirm: () => {
  36. this.removeSnapshotConfirmed(snapshot);
  37. }
  38. });
  39. }
  40. }
  41. angular
  42. .module("grafana.controllers")
  43. .controller("SnapshotsCtrl", SnapshotsCtrl);