You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2018/10/25 15:46:12 UTC
[ambari] 01/02: AMBARI-24824.Make cluster name inputs validation in
Ambari UI consistent
This is an automated email from the ASF dual-hosted git repository.
akovalenko pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
commit 1e5a6cad60fc127fcc3808d71d52a94b29a659f4
Author: Aleksandr Kovalenko <ak...@apache.org>
AuthorDate: Thu Oct 25 14:28:05 2018 +0300
AMBARI-24824.Make cluster name inputs validation in Ambari UI consistent
---
.../ui/admin-web/app/scripts/i18n.config.js | 3 +-
.../admin-web/app/styles/cluster-information.css | 6 ++--
.../app/views/clusters/clusterInformation.html | 33 +++++++++++++---------
.../app/controllers/wizard/step0_controller.js | 4 +--
ambari-web/test/controllers/wizard/step0_test.js | 16 ++++++++++-
5 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
index 42da1dd..a81189a 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/scripts/i18n.config.js
@@ -67,7 +67,7 @@ angular.module('ambariAdminConsole')
'common.yes': 'Yes',
'common.no': 'No',
'common.renameCluster': 'Rename Cluster',
- 'common.renameClusterTip': 'Only alpha-numeric characters, up to 80 characters',
+ 'common.renameClusterTip': 'Only alpha-numeric characters, up to 100 characters',
'common.clusterCreationInProgress': 'Cluster creation in progress...',
'common.all': 'All',
'common.group': 'Group',
@@ -143,6 +143,7 @@ angular.module('ambariAdminConsole')
'common.alerts.fieldRequired': 'Field required!',
'common.alerts.fieldIsRequired': 'This field is required.',
'common.alerts.noSpecialChars': 'Must not contain special characters!',
+ 'common.alerts.noSpecialCharsAndNoEmpty': 'Must not contain special characters and not be empty!',
'common.alerts.nothingToDisplay': 'No {{term}} to display.',
'common.alerts.noRemoteClusterDisplay': 'No Remote Clusters to display.',
'common.alerts.noPrivileges': 'No {{term}} privileges',
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/styles/cluster-information.css b/ambari-admin/src/main/resources/ui/admin-web/app/styles/cluster-information.css
index 519eeae..1eb50b7 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/styles/cluster-information.css
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/styles/cluster-information.css
@@ -27,13 +27,13 @@
#cluster-information .dev-blueprint span {
vertical-align: text-top;
}
-
-#cluster-information .cluster-name input {
+#cluster-information .cluster-name .cluster-input-block{
+ float: left;
width: 75%;
}
#cluster-information .cluster-name button {
- margin-top: -34px;
+ float: right;
}
#cluster-information .cluster-name input.edited {
diff --git a/ambari-admin/src/main/resources/ui/admin-web/app/views/clusters/clusterInformation.html b/ambari-admin/src/main/resources/ui/admin-web/app/views/clusters/clusterInformation.html
index deb2879..f3af369 100644
--- a/ambari-admin/src/main/resources/ui/admin-web/app/views/clusters/clusterInformation.html
+++ b/ambari-admin/src/main/resources/ui/admin-web/app/views/clusters/clusterInformation.html
@@ -43,19 +43,26 @@
<div class="form-group col-xs-4 cluster-name"
ng-class="{'has-error': editClusterNameForm.clusterName.$invalid}">
<label for="clusterName">{{'views.clusterName' | translate}}*</label>
- <input type="text"
- class="form-control"
- id="clusterName"
- name="clusterName"
- ng-change="toggleSaveButton()"
- ng-model="edit.clusterName"
- required
- autofocus
- ng-maxlength="100"
- tooltip="{{'common.renameClusterTip' | translate}}"
- tooltip-trigger="focus"
- tooltip-placement="bottom"
- ng-class="{edited: isClusterNameEdited}">
+ <div class="cluster-input-block">
+ <input type="text"
+ class="form-control"
+ id="clusterName"
+ name="clusterName"
+ ng-change="toggleSaveButton()"
+ ng-model="edit.clusterName"
+ required
+ autofocus
+ ng-maxlength="100"
+ tooltip="{{'common.renameClusterTip' | translate}}"
+ tooltip-trigger="focus"
+ tooltip-placement="bottom"
+ ng-pattern="/^([a-zA-Z0-9_-\s]+)$/"
+ ng-class="{edited: isClusterNameEdited}">
+ <span class="help-block validation-block"
+ ng-show='editClusterNameForm.clusterName.$invalid'>
+ {{'common.alerts.noSpecialCharsAndNoEmpty' | translate}}
+ </span>
+ </div>
<button
type="submit"
ng-class="{'disabled': editClusterNameForm.clusterName.$invalid}"
diff --git a/ambari-web/app/controllers/wizard/step0_controller.js b/ambari-web/app/controllers/wizard/step0_controller.js
index 02712d2..223bd2a 100644
--- a/ambari-web/app/controllers/wizard/step0_controller.js
+++ b/ambari-web/app/controllers/wizard/step0_controller.js
@@ -33,7 +33,7 @@ App.WizardStep0Controller = Em.Controller.extend({
* set <code>clusterNameError</code> if validation fails
*/
invalidClusterName: function () {
- var MAX_CLUSTER_NAME_LENGTH = 80;
+ var MAX_CLUSTER_NAME_LENGTH = 100;
var clusterName = this.get('content.cluster.name');
if (clusterName == '' && this.get('hasSubmitted')) {
this.set('clusterNameError', Em.I18n.t('installer.step0.clusterName.error.required'));
@@ -46,7 +46,7 @@ App.WizardStep0Controller = Em.Controller.extend({
} else if (/\s/.test(clusterName)) {
this.set('clusterNameError', Em.I18n.t('installer.step0.clusterName.error.whitespace'));
return true;
- } else if (/[^\w\s]/gi.test(clusterName)) {
+ } else if (/[^\w\-]/gi.test(clusterName)) {
this.set('clusterNameError', Em.I18n.t('installer.step0.clusterName.error.specialChar'));
return true;
} else {
diff --git a/ambari-web/test/controllers/wizard/step0_test.js b/ambari-web/test/controllers/wizard/step0_test.js
index 53fea69..d3f4d88 100644
--- a/ambari-web/test/controllers/wizard/step0_test.js
+++ b/ambari-web/test/controllers/wizard/step0_test.js
@@ -51,7 +51,21 @@ describe('App.WizardStep0Controller', function () {
wizardStep0Controller.set('hasSubmitted', true);
wizardStep0Controller.set('content', {'cluster':{'name':'$cluster'}});
expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
- })
+ wizardStep0Controller.set('content', {'cluster':{'name':']^cluster\\'}});
+ expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
+ wizardStep0Controller.set('content', {'cluster':{'name':'[cluster]'}});
+ expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
+ });
+ it('should return true if cluster name contains more than 100 symbols', function () {
+ wizardStep0Controller.set('hasSubmitted', true);
+ wizardStep0Controller.set('content', {'cluster':{'name':'0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0000-0'}});
+ expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
+ });
+ it('should return true if cluster name contains special chars', function () {
+ wizardStep0Controller.set('hasSubmitted', true);
+ wizardStep0Controller.set('content', {'cluster':{'name':'$cluster'}});
+ expect(wizardStep0Controller.get('invalidClusterName')).to.equal(true);
+ });
});
describe('#loadStep', function() {