瀏覽代碼

UI and backend working

utkarshcmu 10 年之前
父節點
當前提交
281ec60085

+ 0 - 1
pkg/api/dashboard_snapshot.go

@@ -36,7 +36,6 @@ func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapsho
 		cmd.DeleteKey = util.GetRandomString(32)
 		cmd.OrgId = c.OrgId
 		cmd.UserId = c.UserId
-		cmd.Name = c.Name
 		metrics.M_Api_Dashboard_Snapshot_Create.Inc(1)
 	}
 

+ 3 - 3
public/app/features/snapshot/partials/snapshots.html

@@ -1,7 +1,7 @@
 <navbar icon="fa fa-fw fa-camera-retro" title="Dashboard snapshots"></navbar>
 
 <div class="page-container">
-  <div class="page-wide" ng-init="ctrl.init()">
+  <div class="page-wide">
 
     <h2>Available snapshots</h2>
 
@@ -14,7 +14,7 @@
      
      </thead>
       
-      <tr ng-repeat="snapshot in ctrl.snapshots">
+      <tr ng-repeat="snapshot in snapshots">
         <td>
 					<a href="dashboard/snapshot/{{snapshot.Key}}">{{snapshot.Name}}</a>
         </td>
@@ -28,7 +28,7 @@
           </a>
         </td>
         <td  class="text-right">
-          <a ng-click="ctrl.removeSnapshot(snapshot)" class="btn btn-danger btn-mini">
+          <a ng-click="removeSnapshot(snapshot)" class="btn btn-danger btn-mini">
             <i class="fa fa-remove"></i>
           </a>
         </td>

+ 30 - 7
public/app/features/snapshot/snapshot_ctrl.ts

@@ -4,16 +4,39 @@ import angular from 'angular';
 import _ from 'lodash';
 
 export class SnapshotsCtrl {
-  snapshots: any[];
 
   /** @ngInject */
-  constructor(private backendSrv: any) {}
+  constructor(backendSrv, $scope) {
+    $scope.init = function() {
+      backendSrv.get('/api/dashboard/snapshots').then(function(result) {
+        $scope.snapshots = result;
+      });
+    };
 
-  init() {
-    this.backendSrv.get('/api/dashboard/snapshots').then(snapshots => {
-      this.snapshots = snapshots;
-    });
-    console.log(this.snapshots);
+    $scope.removeSnapshot = function(snapshot) {
+      $scope.appEvent('confirm-modal', {
+        title: 'Confirm delete snapshot',
+        text: 'Are you sure you want to delete snapshot ' + snapshot.Name + '?',
+        yesText: "Delete",
+        icon: "fa-warning",
+        onConfirm: function() {
+          $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();
   }
 }