2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
2019-07-18 01:03:04 -05:00
|
|
|
import { NavModelSrv } from 'app/core/core';
|
|
|
|
import { ILocationService } from 'angular';
|
|
|
|
import { BackendSrv } from '@grafana/runtime';
|
2016-01-19 23:04:53 -06:00
|
|
|
|
2018-09-10 06:59:31 -05:00
|
|
|
export class SnapshotListCtrl {
|
2017-06-02 07:00:42 -05:00
|
|
|
navModel: any;
|
2016-01-20 04:35:24 -06:00
|
|
|
snapshots: any;
|
|
|
|
|
2016-01-19 23:04:53 -06:00
|
|
|
/** @ngInject */
|
2019-07-18 01:03:04 -05:00
|
|
|
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);
|
2019-07-18 01:03:04 -05:00
|
|
|
this.backendSrv.get('/api/dashboard/snapshots').then((result: any) => {
|
2018-12-10 15:40:26 -06:00
|
|
|
const baseUrl = this.$location.absUrl().replace($location.url(), '');
|
2019-07-18 01:03:04 -05:00
|
|
|
this.snapshots = result.map((snapshot: any) => ({
|
2018-12-10 15:40:26 -06:00
|
|
|
...snapshot,
|
|
|
|
url: snapshot.externalUrl || `${baseUrl}/dashboard/snapshot/${snapshot.key}`,
|
|
|
|
}));
|
2016-01-20 04:35:24 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-18 01:03:04 -05:00
|
|
|
removeSnapshotConfirmed(snapshot: any) {
|
2017-12-19 09:06:54 -06:00
|
|
|
_.remove(this.snapshots, { key: snapshot.key });
|
2018-05-24 01:55:16 -05:00
|
|
|
this.backendSrv.delete('/api/snapshots/' + snapshot.key).then(
|
|
|
|
() => {},
|
2017-12-19 09:06:54 -06:00
|
|
|
() => {
|
|
|
|
this.snapshots.push(snapshot);
|
|
|
|
}
|
|
|
|
);
|
2016-01-19 23:04:53 -06:00
|
|
|
}
|
2016-01-20 04:35:24 -06:00
|
|
|
|
2019-07-18 01:03:04 -05: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
|
|
|
}
|