Repository: ambari
Updated Branches:
  refs/heads/trunk 2b2accd9c -> d0b8bed79


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


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d0b8bed7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d0b8bed7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d0b8bed7

Branch: refs/heads/trunk
Commit: d0b8bed79096bbbb0c9f9d1fac1e3ed90a3dd2d1
Parents: 2b2accd
Author: Srimanth Gunturi <sgunt...@hortonworks.com>
Authored: Fri Nov 21 09:32:23 2014 -0800
Committer: Srimanth Gunturi <sgunt...@hortonworks.com>
Committed: Fri Nov 21 10:04:00 2014 -0800

----------------------------------------------------------------------
 .../alerts/definition_details_controller.js     | 28 ++++++++++++++++++--
 ambari-web/app/utils/ajax/ajax.js               | 10 ++++++-
 .../definitions_details_controller_test.js      | 13 +++++++++
 3 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d0b8bed7/ambari-web/app/controllers/main/alerts/definition_details_controller.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/app/controllers/main/alerts/definition_details_controller.js 
b/ambari-web/app/controllers/main/alerts/definition_details_controller.js
index 05d2ad0..dda193c 100644
--- a/ambari-web/app/controllers/main/alerts/definition_details_controller.js
+++ b/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);
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0b8bed7/ambari-web/app/utils/ajax/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax/ajax.js 
b/ambari-web/app/utils/ajax/ajax.js
index d4a8402..773746e 100644
--- a/ambari-web/app/utils/ajax/ajax.js
+++ b/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',

http://git-wip-us.apache.org/repos/asf/ambari/blob/d0b8bed7/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js
----------------------------------------------------------------------
diff --git 
a/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js
 
b/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js
index 5e53b89..52b3bfa 100644
--- 
a/ambari-web/test/controllers/main/alerts/definitions_details_controller_test.js
+++ 
b/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;
+    });
+  });
 
 });

Reply via email to