2017-12-20 12:33:33 +01:00
|
|
|
import angular from 'angular';
|
|
|
|
|
import _ from 'lodash';
|
2016-01-19 21:04:53 -08:00
|
|
|
|
|
|
|
|
export class SnapshotsCtrl {
|
2017-06-02 14:00:42 +02:00
|
|
|
navModel: any;
|
2016-01-20 02:35:24 -08:00
|
|
|
snapshots: any;
|
|
|
|
|
|
2016-01-19 21:04:53 -08:00
|
|
|
/** @ngInject */
|
2017-08-16 11:28:52 +02:00
|
|
|
constructor(private $rootScope, private backendSrv, navModelSrv) {
|
2017-12-20 12:33:33 +01:00
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
|
|
|
|
|
this.backendSrv.get('/api/dashboard/snapshots').then(result => {
|
2016-01-20 02:35:24 -08:00
|
|
|
this.snapshots = result;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeSnapshotConfirmed(snapshot) {
|
2017-12-19 16:06:54 +01:00
|
|
|
_.remove(this.snapshots, { key: snapshot.key });
|
2017-12-20 12:33:33 +01:00
|
|
|
this.backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey).then(
|
2017-12-19 16:06:54 +01:00
|
|
|
() => {
|
2017-12-20 12:33:33 +01:00
|
|
|
this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
|
2017-12-19 16:06:54 +01:00
|
|
|
},
|
|
|
|
|
() => {
|
2017-12-21 08:39:31 +01:00
|
|
|
this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
|
2017-12-19 16:06:54 +01:00
|
|
|
this.snapshots.push(snapshot);
|
|
|
|
|
}
|
|
|
|
|
);
|
2016-01-19 21:04:53 -08:00
|
|
|
}
|
2016-01-20 02:35:24 -08:00
|
|
|
|
|
|
|
|
removeSnapshot(snapshot) {
|
2017-12-20 12:33:33 +01:00
|
|
|
this.$rootScope.appEvent('confirm-modal', {
|
|
|
|
|
title: 'Delete',
|
|
|
|
|
text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
|
|
|
|
|
yesText: 'Delete',
|
|
|
|
|
icon: 'fa-trash',
|
2016-01-20 02:35:24 -08:00
|
|
|
onConfirm: () => {
|
|
|
|
|
this.removeSnapshotConfirmed(snapshot);
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
2016-01-20 02:35:24 -08:00
|
|
|
});
|
|
|
|
|
}
|
2016-01-19 21:04:53 -08:00
|
|
|
}
|
2016-01-20 02:35:24 -08:00
|
|
|
|
2017-12-21 08:39:31 +01:00
|
|
|
angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);
|