Files
grafana/public/app/features/snapshot/snapshot_ctrl.ts

44 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-01-19 21:04:53 -08:00
///<reference path="../../headers/common.d.ts" />
import angular from 'angular';
import _ from 'lodash';
export class SnapshotsCtrl {
navModel: any;
2016-01-20 02:35:24 -08:00
snapshots: any;
2016-01-19 21:04:53 -08:00
/** @ngInject */
2017-08-16 11:28:52 +02:00
constructor(private $rootScope, private backendSrv, navModelSrv) {
this.navModel = navModelSrv.getNav('dashboards', 'snapshots');
2016-01-20 02:35:24 -08:00
this.backendSrv.get('/api/dashboard/snapshots').then(result => {
this.snapshots = result;
});
}
removeSnapshotConfirmed(snapshot) {
_.remove(this.snapshots, {key: snapshot.key});
this.backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey)
.then(() => {
this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
}, () => {
this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
this.snapshots.push(snapshot);
});
2016-01-19 21:04:53 -08:00
}
2016-01-20 02:35:24 -08:00
removeSnapshot(snapshot) {
this.$rootScope.appEvent('confirm-modal', {
title: 'Delete',
2016-01-20 02:35:24 -08:00
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);
}
});
}
2016-01-19 21:04:53 -08:00
}
2016-01-20 02:35:24 -08:00
2016-01-19 21:04:53 -08:00
angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);