2017-12-20 12:33:33 +01:00
|
|
|
import _ from 'lodash';
|
2016-01-19 21:04:53 -08:00
|
|
|
|
2018-09-10 13:59:31 +02:00
|
|
|
export class SnapshotListCtrl {
|
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 */
|
2018-12-10 16:40:26 -05:00
|
|
|
constructor(private $rootScope, private backendSrv, navModelSrv, private $location) {
|
2017-12-20 12:33:33 +01:00
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
|
|
|
|
|
this.backendSrv.get('/api/dashboard/snapshots').then(result => {
|
2018-12-10 16:40:26 -05:00
|
|
|
const baseUrl = this.$location.absUrl().replace($location.url(), '');
|
|
|
|
|
this.snapshots = result.map(snapshot => ({
|
|
|
|
|
...snapshot,
|
|
|
|
|
url: snapshot.externalUrl || `${baseUrl}/dashboard/snapshot/${snapshot.key}`,
|
|
|
|
|
}));
|
2016-01-20 02:35:24 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
removeSnapshotConfirmed(snapshot) {
|
2017-12-19 16:06:54 +01:00
|
|
|
_.remove(this.snapshots, { key: snapshot.key });
|
2018-05-24 02:55:16 -04:00
|
|
|
this.backendSrv.delete('/api/snapshots/' + snapshot.key).then(
|
|
|
|
|
() => {},
|
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
|
|
|
}
|