grafana/public/app/features/manage-dashboards/SnapshotListCtrl.ts

41 lines
1.1 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import _ from 'lodash';
2016-01-19 23:04:53 -06:00
export class SnapshotListCtrl {
navModel: any;
2016-01-20 04:35:24 -06:00
snapshots: any;
2016-01-19 23:04:53 -06:00
/** @ngInject */
constructor(private $rootScope, private backendSrv, navModelSrv, private $location) {
2017-12-20 05:33:33 -06:00
this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
this.backendSrv.get('/api/dashboard/snapshots').then(result => {
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 04:35:24 -06:00
});
}
removeSnapshotConfirmed(snapshot) {
_.remove(this.snapshots, { key: snapshot.key });
this.backendSrv.delete('/api/snapshots/' + snapshot.key).then(
() => {},
() => {
this.snapshots.push(snapshot);
}
);
2016-01-19 23:04:53 -06:00
}
2016-01-20 04:35:24 -06:00
removeSnapshot(snapshot) {
2017-12-20 05:33:33 -06: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 04:35:24 -06:00
onConfirm: () => {
this.removeSnapshotConfirmed(snapshot);
2017-12-20 05:33:33 -06:00
},
2016-01-20 04:35:24 -06:00
});
}
2016-01-19 23:04:53 -06:00
}