Files
grafana/public/app/features/snapshot/snapshot_ctrl.ts
Dan Cech 417db13efb Fix dashboard snapshot deletion (#12025)
* fix issue deleting dashboard snapshots by deleteKey, add dedicated endopoint for authenticated requests, update frontend, tests & docs.
2018-05-24 08:55:16 +02:00

40 lines
1.0 KiB
TypeScript

import angular from 'angular';
import _ from 'lodash';
export class SnapshotsCtrl {
navModel: any;
snapshots: any;
/** @ngInject */
constructor(private $rootScope, private backendSrv, navModelSrv) {
this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
this.backendSrv.get('/api/dashboard/snapshots').then(result => {
this.snapshots = result;
});
}
removeSnapshotConfirmed(snapshot) {
_.remove(this.snapshots, { key: snapshot.key });
this.backendSrv.delete('/api/snapshots/' + snapshot.key).then(
() => {},
() => {
this.snapshots.push(snapshot);
}
);
}
removeSnapshot(snapshot) {
this.$rootScope.appEvent('confirm-modal', {
title: 'Delete',
text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
yesText: 'Delete',
icon: 'fa-trash',
onConfirm: () => {
this.removeSnapshotConfirmed(snapshot);
},
});
}
}
angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);