Commit a854f0c4 by utkarshcmu

Switched snapshot ctrl to angularjs2

parent aa1d2883
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</thead> </thead>
<tr ng-repeat="snapshot in snapshots"> <tr ng-repeat="snapshot in ctrl.snapshots">
<td> <td>
<a href="dashboard/snapshot/{{snapshot.key}}">{{snapshot.name}}</a> <a href="dashboard/snapshot/{{snapshot.key}}">{{snapshot.name}}</a>
</td> </td>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</a> </a>
</td> </td>
<td class="text-right"> <td class="text-right">
<a ng-click="removeSnapshot(snapshot)" class="btn btn-danger btn-mini"> <a ng-click="ctrl.removeSnapshot(snapshot)" class="btn btn-danger btn-mini">
<i class="fa fa-remove"></i> <i class="fa fa-remove"></i>
</a> </a>
</td> </td>
......
...@@ -5,39 +5,38 @@ import _ from 'lodash'; ...@@ -5,39 +5,38 @@ import _ from 'lodash';
export class SnapshotsCtrl { export class SnapshotsCtrl {
snapshots: any;
/** @ngInject */ /** @ngInject */
constructor(backendSrv, $scope) { constructor(private $rootScope, private backendSrv) {
$scope.init = function() { this.backendSrv.get('/api/dashboard/snapshots').then(result => {
backendSrv.get('/api/dashboard/snapshots').then(function(result) { this.snapshots = result;
$scope.snapshots = result; });
}); }
};
removeSnapshotConfirmed(snapshot) {
$scope.removeSnapshot = function(snapshot) { _.remove(this.snapshots, {key: snapshot.key});
$scope.appEvent('confirm-modal', { this.backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey)
title: 'Confirm delete snapshot', .then(() => {
text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?', this.$rootScope.appEvent('alert-success', ['Snapshot deleted', '']);
yesText: "Delete", }, () => {
icon: "fa-warning", this.$rootScope.appEvent('alert-error', ['Unable to delete snapshot', '']);
onConfirm: function() { this.snapshots.push(snapshot);
$scope.removeSnapshotConfirmed(snapshot); });
}
});
};
$scope.removeSnapshotConfirmed = function(snapshot) {
_.remove($scope.snapshots, {key: snapshot.key});
backendSrv.get('/api/snapshots-delete/' + snapshot.deleteKey)
.then(function() {
$scope.appEvent('alert-success', ['Snapshot deleted', '']);
}, function() {
$scope.appEvent('alert-error', ['Unable to delete snapshot', '']);
$scope.snapshots.push(snapshot);
});
};
$scope.init();
} }
removeSnapshot(snapshot) {
this.$rootScope.appEvent('confirm-modal', {
title: 'Confirm delete snapshot',
text: 'Are you sure you want to delete snapshot ' + snapshot.name + '?',
yesText: "Delete",
icon: "fa-warning",
onConfirm: () => {
this.removeSnapshotConfirmed(snapshot);
}
});
}
} }
angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl); angular.module('grafana.controllers').controller('SnapshotsCtrl', SnapshotsCtrl);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment