瀏覽代碼

AMBARI-8416. Alerts UI: Delete alert-definition action should remove using API (srimanth)

Srimanth Gunturi 10 年之前
父節點
當前提交
d0b8bed790

+ 26 - 2
ambari-web/app/controllers/main/alerts/definition_details_controller.js

@@ -120,8 +120,32 @@ App.MainAlertDefinitionDetailsController = Em.Controller.extend({
    * "Delete" button handler
    * @param event
    */
-  deleteAlertDefinition: function (event) {
-    // todo: provide deleting of alert definition
+  deleteAlertDefinition : function(event) {
+    var alertDefinition = this.get('content');
+    var self = this;
+    App.showConfirmationPopup(function() {
+      App.ajax.send({
+        name : 'alerts.delete_alert_definition',
+        sender : self,
+        success : 'deleteAlertDefinitionSuccess',
+        error : 'deleteAlertDefinitionError',
+        data : {
+          id : alertDefinition.get('id')
+        }
+      });
+    }, null, function() {
+    });
+  },
+
+  deleteAlertDefinitionSuccess : function() {
+    App.router.transitionTo('main.alerts.index');
+  },
+
+  deleteAlertDefinitionError : function(xhr, textStatus, errorThrown, opt) {
+    console.log(textStatus);
+    console.log(errorThrown);
+    xhr.responseText = "{\"message\": \"" + xhr.statusText + "\"}";
+    App.ajax.defaultErrorHandler(xhr, opt.url, 'DELETE', xhr.status);
   },
 
   /**

+ 9 - 1
ambari-web/app/utils/ajax/ajax.js

@@ -385,7 +385,15 @@ var urls = {
         data: JSON.stringify(data.data)
       }
     }
-
+  },
+  'alerts.delete_alert_definition': {
+    'real': '/clusters/{clusterName}/alert_definitions/{id}',
+    'mock': '',
+    'format': function (data) {
+      return {
+        type: 'DELETE'
+      }
+    }
   },
   'background_operations.get_most_recent': {
     'real': '/clusters/{clusterName}/requests?to=end&page_size={operationsCount}&fields=Requests',

+ 13 - 0
ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js

@@ -114,5 +114,18 @@ describe('App.MainAlertDefinitionDetailsController', function () {
       expect(App.get('router').transitionTo.calledOnce).to.be.true;
     });
   });
+  
+  describe("#deleteAlertDefinition()", function() {
+    beforeEach(function() {
+      sinon.stub(App.get('router'), 'transitionTo', Em.K);
+    });
+    afterEach(function() {
+     App.get('router').transitionTo.restore();
+    });
+    it("deleteAlertDefinitionSuccess", function() {
+      controller.deleteAlertDefinitionSuccess();
+      expect(App.get('router').transitionTo.calledWith('main.alerts.index')).to.be.true;
+    });
+  });
 
 });