ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject [1/2] ambari git commit: AMBARI-16737. Add validation for alert name edit (alexantonenko)
Date Fri, 20 May 2016 11:11:00 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 848f40766 -> 40ccef06b


AMBARI-16737. Add validation for alert name edit (alexantonenko)


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

Branch: refs/heads/trunk
Commit: 40ccef06b851c45346de4098f4793034b4f65b15
Parents: 2bd3d32
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Fri May 20 14:10:12 2016 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Fri May 20 14:10:54 2016 +0300

----------------------------------------------------------------------
 ambari-web/app/messages.js                      |  1 +
 ambari-web/app/styles/alerts.less               |  6 +++-
 .../main/alerts/definition_details.hbs          |  4 +--
 ambari-web/app/utils/validator.js               | 11 +++++++
 .../main/alerts/definition_details_view.js      | 19 ++++++++++-
 .../main/alerts/definition_details_view_test.js | 33 ++++++++++++++++++++
 6 files changed, 70 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/40ccef06/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index bcb7ca3..fe5a301 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -1080,6 +1080,7 @@ Em.I18n.translations = {
   'alerts.definition.name': 'Alert Definition Name',
   'alerts.saveChanges': 'You have unsaved changes',
 
+  'alert.definition.name.invalid': 'Invalid input. Only alphanumerics, underscores, hyphens,
percentage and spaces are allowed.',
   'alerts.definition.details.enable': 'Enable',
   'alerts.definition.details.disable': 'Disable',
   'alerts.definition.details.enableDisable': 'Enable / Disable',

http://git-wip-us.apache.org/repos/asf/ambari/blob/40ccef06/ambari-web/app/styles/alerts.less
----------------------------------------------------------------------
diff --git a/ambari-web/app/styles/alerts.less b/ambari-web/app/styles/alerts.less
index 50246e6..65f0355 100644
--- a/ambari-web/app/styles/alerts.less
+++ b/ambari-web/app/styles/alerts.less
@@ -267,7 +267,11 @@
       margin-top: -4px;
       float: left;
       margin-left: 7px;
-    }
+    }    
+  }
+
+  .error-msg {
+      color: #b94a48;
   }
 
   .edit-buttons {

http://git-wip-us.apache.org/repos/asf/ambari/blob/40ccef06/ambari-web/app/templates/main/alerts/definition_details.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/definition_details.hbs b/ambari-web/app/templates/main/alerts/definition_details.hbs
index cda1193..bfaad44 100644
--- a/ambari-web/app/templates/main/alerts/definition_details.hbs
+++ b/ambari-web/app/templates/main/alerts/definition_details.hbs
@@ -26,7 +26,7 @@
       <div class="definition-name row-fluid">
         {{#if controller.editing.label.isEditing}}
           <div {{bindAttr class="controller.editing.label.isError:error :span5 :name-text-field
:control-group"}}>
-            {{view Em.TextField valueBinding="controller.editing.label.value"}}
+            {{view Em.TextField valueBinding="controller.editing.label.value" maxlength="255"}}
           </div>
           <div class="edit-buttons">
             <button {{action cancelEdit controller.editing.label target="controller"}}
@@ -48,7 +48,7 @@
         {{/unless}}
       </div>
       {{! Alert Definition Name end }}
-
+      <div class="error-msg"> {{controller.errorMessage}} </div>
       <div><a href="javascript:void(null)" data-toggle="modal" {{action back}}><i
           class="icon-arrow-left"></i>&nbsp;{{t common.back}}</a>
       </div>

http://git-wip-us.apache.org/repos/asf/ambari/blob/40ccef06/ambari-web/app/utils/validator.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/validator.js b/ambari-web/app/utils/validator.js
index 2906749..d29a6bb 100644
--- a/ambari-web/app/utils/validator.js
+++ b/ambari-web/app/utils/validator.js
@@ -312,5 +312,16 @@ module.exports = {
   isValidWidgetDescription: function(value) {
     var widgetDescriptionRegex = /^[\s0-9a-z_\-%]+$/i;
     return widgetDescriptionRegex.test(value);
+  },
+
+  /**
+   * Validate alert name
+   * @param {string} value
+   * @returns {boolean}
+   */
+  isValidAlertName: function(value) {
+    var alertNameRegex = /^[\s0-9a-z_\-%]+$/i;
+    return alertNameRegex.test(value);
   }
+
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/40ccef06/ambari-web/app/views/main/alerts/definition_details_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/alerts/definition_details_view.js b/ambari-web/app/views/main/alerts/definition_details_view.js
index 656021c..4b09a2f 100644
--- a/ambari-web/app/views/main/alerts/definition_details_view.js
+++ b/ambari-web/app/views/main/alerts/definition_details_view.js
@@ -17,6 +17,7 @@
  */
 
 var App = require('app');
+var validator = require('utils/validator');
 var filters = require('views/common/filter_view');
 var sort = require('views/common/sort_view');
 
@@ -43,6 +44,11 @@ App.MainAlertDefinitionDetailsView = App.TableView.extend({
   colPropAssoc: ['serviceName', 'hostName', 'state'],
 
   /**
+   * @type {string}
+   */
+  errorMessage: '',
+
+  /**
    * return filtered number of all content number information displayed on the page footer
bar
    * @returns {String}
    */
@@ -81,6 +87,17 @@ App.MainAlertDefinitionDetailsView = App.TableView.extend({
     });
   },
 
+  nameValidation: function () {
+     var alertName = this.get('controller.editing.label.value').trim();
+     var errorMessage = '';
+     this.set('controller.editing.label.isError',false);
+     if(alertName && !validator.isValidAlertName(alertName)){
+      errorMessage = Em.I18n.t("alert.definition.name.invalid");
+      this.set('controller.editing.label.isError',true);
+    }
+    this.set('controller.errorMessage',errorMessage);            
+  }.observes('controller.editing.label.value'),
+
   didInsertElement: function () {
     this.filter();
     this.tooltipsUpdater();
@@ -334,4 +351,4 @@ App.AlertInstanceStateView = Em.View.extend({
     this.$("[rel='tooltip']").remove();
   }
 
-});
\ No newline at end of file
+});

http://git-wip-us.apache.org/repos/asf/ambari/blob/40ccef06/ambari-web/test/views/main/alerts/definition_details_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/alerts/definition_details_view_test.js b/ambari-web/test/views/main/alerts/definition_details_view_test.js
index a98b66b..e468968 100644
--- a/ambari-web/test/views/main/alerts/definition_details_view_test.js
+++ b/ambari-web/test/views/main/alerts/definition_details_view_test.js
@@ -117,6 +117,39 @@ describe('App.MainAlertDefinitionDetailsView', function () {
     });
   });
 
+  describe("#nameValidation", function() {
+
+    view = getView();
+    
+    var tests = [
+     {
+       it: "Should display no error if user inputs valid characters in alert name",
+       errorMessage: "", 
+       alert: Ember.Object.create ({
+          label: Ember.Object.create ({
+            value: 'validAlertName'
+          })
+       })
+     },    
+     {
+       it: "Should display an error if user inputs invalid characters in alert name",
+       errorMessage: Em.I18n.t("alert.definition.name.invalid"), 
+       alert: Ember.Object.create ({
+          label: Ember.Object.create ({
+            value: 'invalidAlertName\\?<'
+          })
+       })
+     }
+    ];
+
+    tests.forEach(function(test) {
+      it(test.it, function() {
+        view.set('controller.editing',test.alert);
+        expect(view.get('controller.errorMessage')).to.equal(test.errorMessage);
+      })
+    });
+  });
+
   describe("#didInsertElement()", function() {
 
     beforeEach(function() {


Mime
View raw message