You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by zh...@apache.org on 2016/09/01 00:32:36 UTC

ambari git commit: Ambari-18281 Expose Disabling of Alert Targets in Web Client (Vivek Ratnavel Subramanian via zhewang)

Repository: ambari
Updated Branches:
  refs/heads/trunk 352a4a83e -> 4f84718b6


Ambari-18281 Expose Disabling of Alert Targets in Web Client (Vivek Ratnavel Subramanian via zhewang)


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

Branch: refs/heads/trunk
Commit: 4f84718b691641a1293f677f3b1abc873f1dc07b
Parents: 352a4a8
Author: Zhe (Joe) Wang <zh...@apache.org>
Authored: Wed Aug 31 17:31:29 2016 -0700
Committer: Zhe (Joe) Wang <zh...@apache.org>
Committed: Wed Aug 31 17:31:29 2016 -0700

----------------------------------------------------------------------
 .../manage_alert_notifications_controller.js    | 44 ++++++++++++++++++++
 .../app/mappers/alert_notification_mapper.js    |  5 ++-
 ambari-web/app/messages.js                      |  4 ++
 .../app/models/alerts/alert_notification.js     |  4 ++
 ambari-web/app/styles/modal_popups.less         |  7 ++++
 .../alerts/manage_alert_notifications_popup.hbs | 35 +++++++++++-----
 .../alerts/manage_alert_notifications_view.js   | 35 ++++++++++++++--
 .../manage_alert_notifications_view_test.js     |  8 ++--
 8 files changed, 122 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
index 1de15a6..10a7918 100644
--- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
+++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
@@ -153,6 +153,16 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
   }),
 
   /**
+   * List of available options for Enable or Disable
+   * used in settings of SelectedAlertNotification
+   * @type {Object}
+   */
+  enableOrDisable: {
+    enable: "enable",
+    disable: "disable"
+  },
+
+  /**
    * List of available Notification types
    * used in Type combobox
    * @type {Array}
@@ -880,6 +890,40 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
   },
 
   /**
+   * Enable or Disable Notification button handler
+   * @method enableOrDisableAlertNotification
+   */
+  enableOrDisableAlertNotification: function (e) {
+    var enabled = (e.context === "disable")?false:true;
+    return App.ajax.send({
+      name: 'alerts.update_alert_notification',
+      sender: this,
+      data: {
+        data: {
+          "AlertTarget": {
+            "enabled": enabled
+          }
+        },
+        id: this.get('selectedAlertNotification.id')
+      },
+      success: 'enableOrDisableAlertNotificationSuccessCallback',
+      error: 'saveErrorCallback'
+    });
+  },
+
+  /**
+   * Success callback for <code>enableOrDisableAlertNotification</code>
+   * @method enableOrDisableAlertNotificationSuccessCallback
+   */
+  enableOrDisableAlertNotificationSuccessCallback: function () {
+    this.loadAlertNotifications();
+    var createEditPopup = this.get('createEditPopup');
+    if (createEditPopup) {
+      createEditPopup.hide();
+    }
+  },
+
+  /**
    * Show popup with form for new custom property
    * @method addCustomPropertyHandler
    * @return {App.ModalPopup}

http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/app/mappers/alert_notification_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/alert_notification_mapper.js b/ambari-web/app/mappers/alert_notification_mapper.js
index 95e2362..9567c77 100644
--- a/ambari-web/app/mappers/alert_notification_mapper.js
+++ b/ambari-web/app/mappers/alert_notification_mapper.js
@@ -26,7 +26,8 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
     name: 'AlertTarget.name',
     type: 'AlertTarget.notification_type',
     description: 'AlertTarget.description',
-    global: 'AlertTarget.global'
+    global: 'AlertTarget.global',
+    enabled: 'AlertTarget.enabled'
   },
 
   map: function (json) {
@@ -50,7 +51,7 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
         }
 
         var previousNotification = App.cache['previousAlertNotificationsFullMap'][notification.id] ? App.cache['previousAlertNotificationsFullMap'][notification.id] : {};
-        var changedFields = self.getDiscrepancies(notification, previousNotification, ['name', 'type', 'description', 'global', 'groups']);
+        var changedFields = self.getDiscrepancies(notification, previousNotification, ['name', 'type', 'description', 'global', 'enabled', 'groups']);
         if (Object.keys(changedFields).length) {
           result.push(notification);
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index b216918..2c819e5 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -198,6 +198,8 @@ Em.I18n.translations = {
   'common.edit': 'Edit',
   'common.delete': 'Delete',
   'common.duplicate': 'Duplicate',
+  'common.disable': 'Disable',
+  'common.enable': 'Enable',
   'common.empty': 'Empty',
   'common.override':'Override',
   'common.undo':'Undo',
@@ -2375,6 +2377,8 @@ Em.I18n.translations = {
   'alerts.actions.manage_alert_notifications_popup.editButton':'Edit Alert Notification',
   'alerts.actions.manage_alert_notifications_popup.editHeader':'Edit Notification',
   'alerts.actions.manage_alert_notifications_popup.duplicateButton':'Duplicate Alert Notification',
+  'alerts.actions.manage_alert_notifications_popup.disableButton':'Disable Alert Notification',
+  'alerts.actions.manage_alert_notifications_popup.enableButton':'Enable Alert Notification',
   'alerts.actions.manage_alert_notifications_popup.method':'Method',
   'alerts.actions.manage_alert_notifications_popup.email':'Email To',
   'alerts.actions.manage_alert_notifications_popup.SMTPServer':'SMTP Server',

http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/app/models/alerts/alert_notification.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alerts/alert_notification.js b/ambari-web/app/models/alerts/alert_notification.js
index c2d7570..e503c6b 100644
--- a/ambari-web/app/models/alerts/alert_notification.js
+++ b/ambari-web/app/models/alerts/alert_notification.js
@@ -25,6 +25,10 @@ App.AlertNotification = DS.Model.extend({
   description: DS.attr('string'),
   groups: DS.hasMany('App.AlertGroup'),
   global: DS.attr('boolean'),
+  enabled: DS.attr('boolean'),
+  displayName: Ember.computed('enabled', function() {
+    return (this.get('enabled') === true)?this.get('name'): this.get('name') + ' (Disabled)';
+  }),
 
   properties: {},
   alertStates: []

http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/app/styles/modal_popups.less
----------------------------------------------------------------------
diff --git a/ambari-web/app/styles/modal_popups.less b/ambari-web/app/styles/modal_popups.less
index 762ea46..a5c764d 100644
--- a/ambari-web/app/styles/modal_popups.less
+++ b/ambari-web/app/styles/modal_popups.less
@@ -256,6 +256,13 @@
   .modal-body {
 
     max-height: 403px;
+    overflow: visible;
+
+    li.disabled {
+      a {
+        cursor: not-allowed;
+      }
+    }
 
     .form-horizontal{
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs
index 19f9ca3..49724bd 100644
--- a/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs
+++ b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs
@@ -24,7 +24,7 @@
           <span>&nbsp;</span>
           {{view Em.Select
             contentBinding="alertNotifications"
-            optionLabelPath="content.name"
+            optionLabelPath="content.displayName"
             multiple="multiple"
             class="group-select"
             selectionBinding="view.selectedAlertNotification"
@@ -43,16 +43,29 @@
                 <i class="icon-cog"></i>&nbsp;<span class="caret"></span>
               </button>
               <ul class="dropdown-menu">
-                <li {{bindAttr class="view.isEditButtonDisabled:disabled"}}>
-                  <a href="" rel="button-info-dropdown"
-                    {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.editButton"}}
-                    {{action editAlertNotification target="controller"}}>{{t common.edit}}</a>
-                </li>
-                <li {{bindAttr class="view.isDuplicateButtonDisabled:disabled"}}>
-                  <a href="" rel="button-info-dropdown"
-                    {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.duplicateButton"}}
-                    {{action duplicateAlertNotification target="controller"}}>{{t common.duplicate}}</a>
-                </li>
+                  <li {{bindAttr class="view.isEditButtonDisabled:disabled"}}>
+                    <a href="" rel="button-info-dropdown"
+                      {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.editButton"}}
+                      {{action editAlertNotification target="view"}}>{{t common.edit}}</a>
+                  </li>
+                  <li {{bindAttr class="view.isDuplicateButtonDisabled:disabled"}}>
+                    <a href="" rel="button-info-dropdown"
+                      {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.duplicateButton"}}
+                      {{action duplicateAlertNotification target="view"}}>{{t common.duplicate}}</a>
+                  </li>
+                {{#if selectedAlertNotification.enabled}}
+                  <li {{bindAttr class="view.isEnableOrDisableButtonDisabled:disabled"}}>
+                    <a href="" rel="button-info-dropdown"
+                      {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.disableButton"}}
+                      {{action enableOrDisableAlertNotification enableOrDisable.disable target="view"}}>{{t common.disable}}</a>
+                  </li>
+                {{else}}
+                  <li {{bindAttr class="view.isEnableOrDisableButtonDisabled:disabled"}}>
+                    <a href="" rel="button-info-dropdown"
+                      {{translateAttr data-original-title="alerts.actions.manage_alert_notifications_popup.enableButton"}}
+                      {{action enableOrDisableAlertNotification enableOrDisable.enable target="view"}}>{{t common.enable}}</a>
+                  </li>
+                {{/if}}
               </ul>
             </div>
           </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js
index 5b476a3..abb1694 100644
--- a/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js
+++ b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js
@@ -41,7 +41,7 @@ App.ManageAlertNotificationsView = Em.View.extend({
   /**
    * @type {boolean}
    */
-  isEditButtonDisabled: Em.computed.or('!someAlertNotificationIsSelected', 'App.isOperator'),
+  isEditButtonDisabled: Em.computed.or('!someAlertNotificationIsSelected', 'App.isOperator', '!controller.selectedAlertNotification.enabled'),
 
   /**
    * @type {boolean}
@@ -51,7 +51,12 @@ App.ManageAlertNotificationsView = Em.View.extend({
   /**
    * @type {boolean}
    */
-  isDuplicateButtonDisabled: Em.computed.or('!someAlertNotificationIsSelected', 'App.isOperator'),
+  isDuplicateButtonDisabled: Em.computed.or('!someAlertNotificationIsSelected', 'App.isOperator', '!controller.selectedAlertNotification.enabled'),
+
+  /**
+   * @type {boolean}
+   */
+  isEnableOrDisableButtonDisabled: Em.computed.or('!someAlertNotificationIsSelected', 'App.isOperator'),
 
   /**
    * Show EMAIL information if selected alert notification has type EMAIL
@@ -76,6 +81,25 @@ App.ManageAlertNotificationsView = Em.View.extend({
     return this.get('controller.selectedAlertNotification.alertStates').join(', ');
   }.property('controller.selectedAlertNotification.alertStates'),
 
+  editAlertNotification: function () {
+    if(!this.get('isEditButtonDisabled')) {
+      this.get('controller').editAlertNotification();
+    }
+  },
+
+  duplicateAlertNotification: function () {
+    if(!this.get('isDuplicateButtonDisabled')) {
+      this.get('controller').duplicateAlertNotification();
+    }
+  },
+
+  enableOrDisableAlertNotification: function (e) {
+    if(!this.get('isEnableOrDisableButtonDisabled')) {
+      this.$("[rel='button-info-dropdown']").tooltip('destroy');
+      this.get('controller').enableOrDisableAlertNotification(e);
+    }
+  },
+
   /**
    * Prevent user select more than 1 alert notification
    * @method onAlertNotificationSelect
@@ -88,6 +112,12 @@ App.ManageAlertNotificationsView = Em.View.extend({
     if (selectedAlertNotification && selectedAlertNotification.length > 1) {
       this.set('selectedAlertNotification', selectedAlertNotification[selectedAlertNotification.length - 1]);
     }
+    if(this.$("[rel='button-info-dropdown']")) {
+      this.$("[rel='button-info-dropdown']").tooltip('destroy');
+    }
+    Em.run.later(this, function () {
+      App.tooltip(self.$("[rel='button-info-dropdown']").parent().not(".disabled").children(), {placement: 'left'});
+    }, 50);
   }.observes('selectedAlertNotification'),
 
   /**
@@ -106,7 +136,6 @@ App.ManageAlertNotificationsView = Em.View.extend({
       }
       Em.run.later(this, function () {
         App.tooltip(self.$("[rel='button-info']"));
-        App.tooltip(self.$("[rel='button-info-dropdown']"), {placement: 'left'});
       }, 50);
     }
   }.observes('controller.isLoaded'),

http://git-wip-us.apache.org/repos/asf/ambari/blob/4f84718b/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js b/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
index cebee96..39570dd 100644
--- a/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
+++ b/ambari-web/test/views/main/alerts/manage_alert_notifications_view_test.js
@@ -217,7 +217,7 @@ describe('App.ManageAlertNotificationsView', function () {
       it("App.tooltip should be called twice", function () {
         view.onLoad();
         this.clock.tick(50);
-        expect(App.tooltip.calledTwice).to.be.true;
+        expect(App.tooltip.calledOnce).to.be.true;
       });
 
       it("selectedAlertNotification should be null", function () {
@@ -247,14 +247,14 @@ describe('App.ManageAlertNotificationsView', function () {
         view.set('controller.alertNotifications', [{}]);
       });
 
-      it("Em.run.later should be called", function () {
+      it("Em.run.later should be called twice", function () {
         view.onLoad();
-        expect(Em.run.later.calledOnce).to.be.true;
+        expect(Em.run.later.calledTwice).to.be.true;
       });
 
       it("App.tooltip should be called twice", function () {
         view.onLoad();
-        this.clock.tick(50);
+        this.clock.tick(100);
         expect(App.tooltip.calledTwice).to.be.true;
       });