2016-01-19 21:04:53 -08:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'snapshots');
|
2016-01-20 02:35:24 -08:00
|
|
|
this.backendSrv.get('/api/dashboard/snapshots').then(result => {
|
|
|
|
|
this.snapshots = result;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeSnapshotConfirmed(snapshot) {
|
|
|
|
|
_.remove(this.snapshots, {key: snapshot.key});
|
|
|
|
|
this.backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey)
|
|
|
|
|
.then(() => {
|
|
|
|
|
this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
|
|
|
|
|
}, () => {
|
|
|
|
|
this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
|
|
|
|
|
this.snapshots.push(snapshot);
|
|
|
|
|
});
|
2016-01-19 21:04:53 -08:00
|
|
|
}
|
2016-01-20 02:35:24 -08:00
|
|
|
|
|
|
|
|
removeSnapshot(snapshot) {
|
|
|
|
|
this.$rootScope.appEvent('confirm-modal', {
|
2016-03-04 20:56:53 +01:00
|
|
|
title: 'Delete',
|
2016-01-20 02:35:24 -08:00
|
|
|
text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
|
|
|
|
|
yesText: "Delete",
|
2016-03-04 20:56:53 +01:00
|
|
|
icon: "fa-trash",
|
2016-01-20 02:35:24 -08:00
|
|
|
onConfirm: () => {
|
|
|
|
|
this.removeSnapshotConfirmed(snapshot);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-19 21:04:53 -08:00
|
|
|
}
|
2016-01-20 02:35:24 -08:00
|
|
|
|
2016-01-19 21:04:53 -08:00
|
|
|
angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);
|