ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xiw...@apache.org
Subject [1/2] ambari git commit: AMBARI-9017. Alerts UI: saving notification with same name fails w/o informing user.(xiwang)
Date Wed, 07 Jan 2015 21:05:45 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 915f0e789 -> 0e1cc1de4


AMBARI-9017. Alerts UI: saving notification with same name fails w/o informing user.(xiwang)


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

Branch: refs/heads/trunk
Commit: 0e1cc1de436c396476f43794d070c2759fd26d95
Parents: f90ac9e
Author: Xi Wang <xiwang@apache.org>
Authored: Wed Jan 7 11:58:20 2015 -0800
Committer: Xi Wang <xiwang@apache.org>
Committed: Wed Jan 7 12:57:39 2015 -0800

----------------------------------------------------------------------
 .../manage_alert_notifications_controller.js    | 57 ++++++++++++++++----
 ambari-web/app/messages.js                      |  2 +
 .../main/alerts/create_alert_notification.hbs   |  6 ++-
 ...anage_alert_notifications_controller_test.js | 31 +++++++++++
 4 files changed, 84 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0e1cc1de/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 2dd442e..2d84994 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
@@ -350,16 +350,45 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         }.property('controller.inputFields.method.value'),
 
         nameValidation: function () {
-          this.set('parentView.hasErrors', !this.get('controller.inputFields.name.value').trim());
+          var newName = this.get('controller.inputFields.name.value').trim();
+          var errorMessage = '';
+          // on editing, save current notification name
+          if (newName && !this.get('currentName')) {
+            this.set('currentName', newName);
+          }
+          if (isEdit) {
+            // edit current alert notification
+            if (!newName) {
+              this.set('nameError', true);
+              errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty');
+            } else if (newName && newName != this.get('currentName') && self.get('alertNotifications').mapProperty('name').contains(newName))
{
+              this.set('nameError', true);
+              errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.existed');
+            } else {
+              this.set('nameError', false);
+            }
+          } else {
+            // add new alert notification
+            if (!newName) {
+              this.set('nameError', true);
+              errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty');
+            } else if (newName && self.get('alertNotifications').mapProperty('name').contains(newName))
{
+              this.set('nameError', true);
+              errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.existed');
+            } else {
+              this.set('nameError', false);
+            }
+          }
+          this.set('controller.inputFields.name.errorMsg', errorMessage);
         }.observes('controller.inputFields.name.value'),
 
         emailToValidation: function () {
           var emailTo = this.get('controller.inputFields.email.value');
           if (emailTo && !validator.isValidEmail(emailTo)) {
-            this.set('parentView.hasErrors', true);
+            this.set('emailToError', true);
             this.set('controller.inputFields.email.errorMsg', Em.I18n.t('alerts.notifications.error.email'));
           } else {
-            this.set('parentView.hasErrors', false);
+            this.set('emailToError', false);
             this.set('controller.inputFields.email.errorMsg', null);
           }
         }.observes('controller.inputFields.email.value'),
@@ -367,10 +396,10 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         emailFromValidation: function () {
           var emailFrom = this.get('controller.inputFields.emailFrom.value');
           if (emailFrom && !validator.isValidEmail(emailFrom)) {
-            this.set('parentView.hasErrors', true);
+            this.set('emailFromError', true);
             this.set('controller.inputFields.emailFrom.errorMsg', Em.I18n.t('alerts.notifications.error.email'));
           } else {
-            this.set('parentView.hasErrors', false);
+            this.set('emailFromError', false);
             this.set('controller.inputFields.emailFrom.errorMsg', null);
           }
         }.observes('controller.inputFields.emailFrom.value'),
@@ -378,10 +407,10 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         smtpPortValidation: function () {
           var value = this.get('controller.inputFields.SMTPPort.value');
           if (value && (!validator.isValidInt(value) || value < 0)) {
-            this.set('parentView.hasErrors', true);
+            this.set('smtpPortError', true);
             this.set('controller.inputFields.SMTPPort.errorMsg', Em.I18n.t('alerts.notifications.error.integer'));
           } else {
-            this.set('parentView.hasErrors', false);
+            this.set('smtpPortError', false);
             this.set('controller.inputFields.SMTPPort.errorMsg', null);
           }
         }.observes('controller.inputFields.SMTPPort.value'),
@@ -389,10 +418,10 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         portValidation: function () {
           var value = this.get('controller.inputFields.port.value');
           if (value && (!validator.isValidInt(value) || value < 0)) {
-            this.set('parentView.hasErrors', true);
+            this.set('portError', true);
             this.set('controller.inputFields.port.errorMsg', Em.I18n.t('alerts.notifications.error.integer'));
           } else {
-            this.set('parentView.hasErrors', false);
+            this.set('portError', false);
             this.set('controller.inputFields.port.errorMsg', null);
           }
         }.observes('controller.inputFields.port.value'),
@@ -401,14 +430,20 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
           var passwordValue = this.get('controller.inputFields.SMTPPassword.value');
           var retypePasswordValue = this.get('controller.inputFields.retypeSMTPPassword.value');
           if (passwordValue !== retypePasswordValue) {
-            this.set('parentView.hasErrors', true);
+            this.set('passwordError', true);
             this.set('controller.inputFields.retypeSMTPPassword.errorMsg', Em.I18n.t('alerts.notifications.error.retypePassword'));
           } else {
-            this.set('parentView.hasErrors', false);
+            this.set('passwordError', false);
             this.set('controller.inputFields.retypeSMTPPassword.errorMsg', null);
           }
         }.observes('controller.inputFields.retypeSMTPPassword.value', 'controller.inputFields.SMTPPassword.value'),
 
+        setParentErrors: function () {
+          var hasErrors = this.get('nameError') || this.get('emailToError') || this.get('emailFromError')
||
+            this.get('smtpPortError') || this.get('portError') || this.get('passwordError');
+          this.set('parentView.hasErrors', hasErrors);
+        }.observes('nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'portError',
'passwordError'),
+
 
         groupsSelectView: Em.Select.extend({
           attributeBindings: ['disabled'],

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e1cc1de/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 30b7edb..096662e 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -1903,6 +1903,8 @@ Em.I18n.translations = {
   'alerts.actions.manage_alert_notifications_popup.selectAll':'Select All',
   'alerts.actions.manage_alert_notifications_popup.confirmDeleteHeader':'Confirm Delete',
   'alerts.actions.manage_alert_notifications_popup.confirmDeleteBody':'Are you sure you want
to delete {0} notification?',
+  'alerts.actions.manage_alert_notifications_popup.error.name.empty': 'Notification name
is required',
+  'alerts.actions.manage_alert_notifications_popup.error.name.existed': 'Notification name
already exists',
 
   'hosts.host.add':'Add New Hosts',
   'hosts.table.noHosts':'No hosts to display',

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e1cc1de/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs b/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
index 451e3e1..00ba20e 100644
--- a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
+++ b/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
@@ -22,12 +22,16 @@
 
 
     {{! alert-notification name }}
-    <div class="control-group">
+    <div {{bindAttr class=":control-group controller.inputFields.name.errorMsg:error"}}>
       <label class="control-label" for="inputName">{{controller.inputFields.name.label}}</label>
 
       <div class="controls">
         {{view Em.TextField valueBinding="controller.inputFields.name.value" id="inputName"
class="input-xlarge"}}
       </div>
+
+      <div class="controls error-msg">
+        {{controller.inputFields.name.errorMsg}}
+      </div>
     </div>
     {{! alert-notification name end }}
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e1cc1de/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
index 831009c..9f3c498 100644
--- a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
+++ b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
@@ -352,6 +352,7 @@ describe('App.ManageAlertNotificationsController', function () {
         view = controller.showCreateEditPopup().get('bodyClass').create({
           controller: Em.Object.create({
             inputFields: {
+              name: {},
               global: {},
               allGroups: {},
               SMTPPassword: {},
@@ -404,6 +405,36 @@ describe('App.ManageAlertNotificationsController', function () {
 
       });
 
+      describe('#nameValidation', function () {
+
+        it('should check inputFields.name.value', function () {
+          view.set('controller.inputFields.name.value', '');
+          expect(view.get('controller.inputFields.name.errorMsg')).to.equal(Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty'));
+          expect(view.get('parentView.hasErrors')).to.be.true;
+        });
+
+        it('should check inputFields.name.value', function () {
+          view.set('controller.inputFields.name.errorMsg', 'error');
+          view.set('controller.inputFields.name.value', 'test');
+          expect(view.get('controller.inputFields.name.errorMsg')).to.equal('');
+        });
+
+        it('should check inputFields.name.value', function () {
+          view.set('isEdit', true);
+          view.set('controller.inputFields.name.value', '');
+          expect(view.get('controller.inputFields.name.errorMsg')).to.equal(Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty'));
+          expect(view.get('parentView.hasErrors')).to.be.true;
+        });
+
+        it('should check inputFields.name.value', function () {
+          view.set('isEdit', true);
+          view.set('controller.inputFields.name.errorMsg', 'error');
+          view.set('controller.inputFields.name.value', 'test');
+          expect(view.get('controller.inputFields.name.errorMsg')).to.equal('');
+        });
+
+      });
+
       describe('#retypePasswordValidation', function () {
 
         it('should check inputFields.retypeSMTPPassword.value', function () {


Mime
View raw message