2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
2020-01-21 03:08:07 -06:00
|
|
|
import { ILocationService, IScope } from 'angular';
|
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
|
2019-07-18 01:03:04 -05:00
|
|
|
import { NavModelSrv } from 'app/core/core';
|
2019-10-14 03:27:47 -05:00
|
|
|
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
|
|
|
import { CoreEvents } from 'app/types';
|
2020-01-21 03:08:07 -06:00
|
|
|
import { promiseToDigest } from '../../core/utils/promiseToDigest';
|
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(
|
2019-10-14 03:27:47 -05:00
|
|
|
private $rootScope: GrafanaRootScope,
|
2019-07-18 01:03:04 -05:00
|
|
|
navModelSrv: NavModelSrv,
|
2020-01-21 03:08:07 -06:00
|
|
|
private $location: ILocationService,
|
|
|
|
private $scope: IScope
|
2019-07-18 01:03:04 -05:00
|
|
|
) {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'snapshots', 0);
|
2020-01-21 03:08:07 -06:00
|
|
|
promiseToDigest(this.$scope)(
|
|
|
|
getBackendSrv()
|
|
|
|
.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
|
|
|
}
|
|
|
|
|
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 });
|
2020-01-21 03:08:07 -06:00
|
|
|
promiseToDigest(this.$scope)(
|
|
|
|
getBackendSrv()
|
|
|
|
.delete('/api/snapshots/' + snapshot.key)
|
|
|
|
.then(
|
|
|
|
() => {},
|
|
|
|
() => {
|
|
|
|
this.snapshots.push(snapshot);
|
|
|
|
}
|
|
|
|
)
|
2017-12-19 09:06:54 -06:00
|
|
|
);
|
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) {
|
2019-10-14 03:27:47 -05:00
|
|
|
this.$rootScope.appEvent(CoreEvents.showConfirmModal, {
|
2017-12-20 05:33:33 -06:00
|
|
|
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
|
|
|
}
|