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

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import _ from 'lodash';
import { NavModelSrv } from 'app/core/core';
import { ILocationService } from 'angular';
import { BackendSrv } from '@grafana/runtime';
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: any,
private backendSrv: BackendSrv,
navModelSrv: NavModelSrv,
private $location: ILocationService
) {
2017-12-20 05:33:33 -06:00
this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
this.backendSrv.get('/api/dashboard/snapshots').then((result: any) => {
const baseUrl = this.$location.absUrl().replace($location.url(), '');
this.snapshots = result.map((snapshot: any) => ({
...snapshot,
url: snapshot.externalUrl || `${baseUrl}/dashboard/snapshot/${snapshot.key}`,
}));
2016-01-20 04:35:24 -06:00
});
}
removeSnapshotConfirmed(snapshot: any) {
_.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: any) {
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
}