Bläddra i källkod

AMBARI-8537. Alerts UI: Add ability to create global alert-notification.(xiwang)

Xi Wang 10 år sedan
förälder
incheckning
ae24c7331f

+ 1 - 0
ambari-web/app/controllers/main/alerts/manage_alert_groups_controller.js

@@ -95,6 +95,7 @@ App.ManageAlertGroupsController = Em.Controller.extend({
             name: target.AlertTarget.name,
             type: target.AlertTarget.notification_type,
             description: target.AlertTarget.description,
+            global: target.AlertTarget.global,
             id: target.AlertTarget.id
           }));
         }

+ 11 - 0
ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js

@@ -51,6 +51,12 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       value: '',
       defaultValue: ''
     },
+    global: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.global'),
+      value: false,
+      defaultValue: false,
+      disabled: false
+    },
     method: {
       label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.method'),
       value: '',
@@ -146,6 +152,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
    */
   addAlertNotification: function () {
     var inputFields = this.get('inputFields');
+    inputFields.set('global.disabled', false);
     Em.keys(inputFields).forEach(function (key) {
       inputFields.set(key + '.value', inputFields.get(key + '.defaultValue'));
     });
@@ -178,6 +185,9 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       selectedAlertNotification.get('alertStates').contains('CRITICAL'),
       selectedAlertNotification.get('alertStates').contains('UNKNOWN')
     ]);
+    inputFields.set('global.value', selectedAlertNotification.get('global'));
+    // not allow to edit global field
+    inputFields.set('global.disabled', true);
     inputFields.set('description.value', selectedAlertNotification.get('description'));
     inputFields.set('method.value', selectedAlertNotification.get('type'));
     inputFields.get('customProperties').clear();
@@ -256,6 +266,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       AlertTarget: {
         name: inputFields.get('name.value'),
         description: inputFields.get('description.value'),
+        global: inputFields.get('global.value'),
         notification_type: inputFields.get('method.value'),
         alert_states: alertStates,
         properties: properties

+ 2 - 1
ambari-web/app/mappers/alert_notification_mapper.js

@@ -23,7 +23,8 @@ App.alertNotificationMapper = App.QuickDataMapper.create({
     id: 'AlertTarget.id',
     name: 'AlertTarget.name',
     type: 'AlertTarget.notification_type',
-    description: 'AlertTarget.description'
+    description: 'AlertTarget.description',
+    global: 'AlertTarget.global'
   },
 
   map: function (json) {

+ 1 - 0
ambari-web/app/messages.js

@@ -1861,6 +1861,7 @@ Em.I18n.translations = {
   'alerts.actions.manage_alert_notifications_popup.duplicateButton':'Duplicate Alert Notification',
   'alerts.actions.manage_alert_notifications_popup.method':'Method',
   'alerts.actions.manage_alert_notifications_popup.email':'Email',
+  'alerts.actions.manage_alert_notifications_popup.global':'Global',
   'alerts.actions.manage_alert_notifications_popup.severityFilter':'Severity Filter',
 
   'hosts.host.add':'Add New Hosts',

+ 1 - 1
ambari-web/app/models/alert_config.js

@@ -209,7 +209,7 @@ App.AlertConfigProperties = {
     name: 'interval',
     label: 'Interval',
     displayType: 'textField',
-    unit: 'Second',
+    unit: 'Minute',
     classNames: 'alert-interval-input',
     apiProperty: 'interval'
   }),

+ 1 - 0
ambari-web/app/models/alert_notification.js

@@ -24,6 +24,7 @@ App.AlertNotification = DS.Model.extend({
   type: DS.attr('string'),
   description: DS.attr('string'),
   groups: DS.hasMany('App.AlertGroup'),
+  global: DS.attr('boolean'),
 
   properties: {},
   alertStates: []

+ 6 - 1
ambari-web/app/styles/alerts.less

@@ -337,6 +337,12 @@
   }
 }
 
+#manage-alert-notification-content {
+  .notification-info .global-info .global-checkbox {
+    margin: 0px;
+  }
+}
+
 #manage-alert-notifications-error {
   margin-bottom: 20px
 }
@@ -357,7 +363,6 @@
   .icon-minus-sign {
     color: #FF4B4B;
   }
-
 }
 
 /*****start styles for manage alerts popup*****/

+ 1 - 1
ambari-web/app/styles/common.less

@@ -60,7 +60,7 @@
   position: relative;
 }
 
-.editable-list-container.edit-mode .items-box ul.items-list li.item{
+.editable-list-container.edit-mode .items-box ul.items-list li.item.deletable{
   padding-right: 25px;
 }
 

+ 1 - 1
ambari-web/app/templates/common/alerts_popup.hbs

@@ -35,7 +35,7 @@
                   <div class="status-icon">{{{alertInstance.status}}}</div>
                   <div class="name-text"><a href="#" {{action "gotoAlertDetails" alertInstance target="view"}}>{{alertInstance.label}}</a></div>
                   <div class="service-text"><a href="#" {{action "gotoService" alertInstance.service target="view"}}>{{alertInstance.service.displayName}}</a>
-                    {{#if alertInstance.host}}
+                    {{#if alertInstance.host.hostName}}
                       {{#if alertInstance.service.displayName}}
                         &nbsp;/&nbsp;
                       {{/if}}

+ 6 - 4
ambari-web/app/templates/common/editable_list.hbs

@@ -20,12 +20,14 @@
   <div class="items-box" {{action enableEditMode target="view"}}>
     <ul class="items-list">
       {{#each item in view.items}}
-        <li class="item">
+        <li {{bindAttr class=":item item.global::deletable"}}>
           <span>
             <a href>{{item.name}}</a>
-            <button {{action removeFromItems item target="view"}} type="button" class="close">
-              <span>&times;x</span>
-            </button>
+            {{#unless item.global}}
+              <button {{action removeFromItems item target="view"}} type="button" class="close">
+                <span>&times;</span>
+              </button>
+            {{/unless}}
           </span>
         </li>
       {{/each}}

+ 9 - 1
ambari-web/app/templates/main/alerts/create_alert_notification.hbs

@@ -32,7 +32,15 @@
       <label class="control-label" for="inputGroups">{{controller.inputFields.groups.label}}</label>
 
       <div class="controls">
-        {{view Em.TextField valueBinding="controller.inputFields.groups.value" id="inputGroups" class="input-xlarge"}}
+        {{view Em.TextField valueBinding="controller.inputFields.groups.value" id="inputGroups" class="input-xlarge" disabledBinding="controller.inputFields.global.value"}}
+      </div>
+    </div>
+
+    <div class="control-group">
+      <label class="control-label" for="inputGlobal">{{controller.inputFields.global.label}}</label>
+
+      <div class="controls">
+        {{view Em.Checkbox checkedBinding="controller.inputFields.global.value" disabledBinding="controller.inputFields.global.disabled" id="inputGlobal" class="input-xlarge"}}
       </div>
     </div>
 

+ 1 - 1
ambari-web/app/templates/main/alerts/definition_details.hbs

@@ -175,7 +175,7 @@
               <td class="first">{{{instance.status}}}</td>
               <td>
                 <a {{action goToService instance.service target="controller"}} href="#">{{instance.service.displayName}}</a>
-                {{#if instance.host}}
+                {{#if instance.host.hostName}}
                   {{#if instance.service.displayName}}
                     &nbsp;/&nbsp;
                   {{/if}}

+ 7 - 3
ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs

@@ -17,10 +17,10 @@
 }}
 <div class="alert alert-info margin-bottom-5">{{t alerts.actions.manageNotifications.info}}</div>
 {{#if controller.isLoaded}}
-  <div class="row-fluid  manage-configuration-group-content">
+  <div class="row-fluid  manage-configuration-group-content" id="manage-alert-notification-content">
     <div class="span12">
       <div class="row-fluid">
-        <div class="span4">
+        <div class="span4 notification-list">
           <span>&nbsp;</span>
           {{view Em.Select
           contentBinding="alertNotifications"
@@ -56,7 +56,7 @@
             </div>
           </div>
         </div>
-        <div class="span8">
+        <div class="span8 notification-info">
           <span>&nbsp;</span>
 
           <div class="row-fluid">
@@ -70,6 +70,10 @@
                 <div class="span3">{{t common.groups}}</div>
                 <div class="span9">{{view.selectedAlertNotificationGroups}}</div>
               </div>
+              <div class="row-fluid global-info">
+                <div class="span3">{{t alerts.actions.manage_alert_notifications_popup.global}}</div>
+                <div class="span9">{{view Em.Checkbox checkedBinding="selectedAlertNotification.global" disabled="disabled" class="global-checkbox"}}</div>
+              </div>
               <div class="row-fluid">
                 <div class="span3">{{t alerts.actions.manage_alert_notifications_popup.method}}</div>
                 <div class="span9">{{selectedAlertNotification.type}}</div>

+ 1 - 7
ambari-web/app/views/common/editable_list.js

@@ -105,7 +105,6 @@ App.EditableList = Ember.View.extend({
           self.addItem(item);
         });
         self.clearInput();
-        self.focusOnInput();
       } else {
         // Load typeahed items based on current input
         var items = self.get('availableItemsToAdd');
@@ -115,12 +114,7 @@ App.EditableList = Ember.View.extend({
     } else {
       self.set('typeahead', []);
       self.set('selectedTypeahed', 0);
-      this.focusOnInput();
     }
 
-  }.observes('input'),
-
-  focusOnInput: function() {
-  }
-
+  }.observes('input')
 });

+ 1 - 1
ambari-web/app/views/main/alerts/manage_alert_notifications_view.js

@@ -28,7 +28,7 @@ App.ManageAlertNotificationsView = Em.View.extend({
   selectedAlertNotification: null,
 
   selectedAlertNotificationGroups: function () {
-    return this.get('controller.selectedAlertNotification.groups').toArray().mapProperty('name').join(', ');
+    return this.get('controller.selectedAlertNotification.groups').toArray().mapProperty('displayName').join(', ');
   }.property('controller.selectedAlertNotification'),
 
   isEditButtonDisabled: true,

+ 11 - 0
ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js

@@ -168,6 +168,7 @@ describe('App.ManageAlertNotificationsController', function () {
 
       controller.set('selectedAlertNotification', Em.Object.create({
         name: 'test_name',
+        global: true,
         description: 'test_description',
         type: 'EMAIL',
         alertStates: ['OK', 'UNKNOWN'],
@@ -187,6 +188,9 @@ describe('App.ManageAlertNotificationsController', function () {
         groups: {
           value: ''
         },
+        global: {
+          value: false
+        },
         method: {
           value: ''
         },
@@ -214,6 +218,9 @@ describe('App.ManageAlertNotificationsController', function () {
         groups: {
           value: ''
         },
+        global: {
+          value: true
+        },
         method: {
           value: 'EMAIL'
         },
@@ -270,6 +277,9 @@ describe('App.ManageAlertNotificationsController', function () {
         groups: {
           value: ''
         },
+        global: {
+          value: false
+        },
         method: {
           value: 'EMAIL'
         },
@@ -293,6 +303,7 @@ describe('App.ManageAlertNotificationsController', function () {
       expect(result).to.eql({
         AlertTarget: {
           name: 'test_name',
+          global: false,
           description: 'test_description',
           notification_type: 'EMAIL',
           alert_states: ['OK', 'CRITICAL'],