Selaa lähdekoodia

AMBARI-3932 Config Group names can be named without any restriction. (ababiichuk)

aBabiichuk 11 vuotta sitten
vanhempi
commit
95ba3b4522

+ 4 - 4
ambari-web/app/controllers/main/service/manage_config_groups_controller.js

@@ -363,19 +363,19 @@ App.ManageConfigGroupsController = Em.Controller.extend({
       warningMessage: '',
       validate: function () {
         var warningMessage = '';
-        if (self.get('usedConfigGroupNames').concat(self.get('configGroups').mapProperty('name')).contains(this.get('configGroupName'))) {
+        if (self.get('usedConfigGroupNames').concat(self.get('configGroups').mapProperty('name')).contains(this.get('configGroupName').trim())) {
           warningMessage = Em.I18n.t("config.group.selection.dialog.err.name.exists");
         }
         this.set('warningMessage', warningMessage);
       }.observes('configGroupName'),
       enablePrimary: function () {
-        return this.get('configGroupName').length > 0 && !this.get('warningMessage');
+        return this.get('configGroupName').trim().length > 0 && !this.get('warningMessage');
       }.property('warningMessage', 'configGroupName'),
       onPrimary: function () {
         if (!this.get('enablePrimary')) {
           return false;
         }
-        this.get('content').set('configGroupName', this.get('configGroupName'));
+        this.get('content').set('configGroupName', this.get('configGroupName').trim());
         this.get('content').set('configGroupDesc', this.get('configGroupDesc'));
         var desiredConfig = [];
          if (isDuplicated) {
@@ -391,7 +391,7 @@ App.ManageConfigGroupsController = Em.Controller.extend({
             })
           }, this);
         }
-        self.createNewConfigurationGroup(this.get('configGroupName'),this.get('content.serviceName'),this.get('configGroupDesc'), desiredConfig, this.get('content'));
+        self.createNewConfigurationGroup(this.get('configGroupName').trim(),this.get('content.serviceName'),this.get('configGroupDesc'), desiredConfig, this.get('content'));
       },
       onSecondary: function () {
         this.hide();

+ 15 - 2
ambari-web/app/models/config_group.js

@@ -76,9 +76,22 @@ App.ConfigGroup = Ember.Object.extend({
    */
   hosts: [],
 
+  /**
+   * Provides a display friendly name. This includes trimming
+   * names to a certain length.
+   */
   displayName: function () {
-    return this.get('name') + ' (' + this.get('hosts.length') + ')';
-  }.property('name', 'hosts.length'),
+    var name = this.get('name');
+    if (name && name.length>App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
+      var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
+      name = name.substring(0, middle) + "..." + name.substring(name.length-middle);
+    }
+    return name;
+  }.property('name'),
+
+  displayNameHosts: function () {
+    return this.get('displayName') + ' (' + this.get('hosts.length') + ')';
+  }.property('displayName', 'hosts.length'),
 
   apiResponse: null,
 

+ 1 - 1
ambari-web/app/templates/common/configs/overriddenProperty.hbs

@@ -21,7 +21,7 @@
     <div {{bindAttr class="overriddenSCP.errorMessage:error: :control-group :overrideField"}}>
       {{view overriddenSCP.viewClass serviceConfigBinding="overriddenSCP" categoryConfigsBinding="view.categoryConfigs"}}
       {{#if overriddenSCP.group}}
-        <a class="action" {{action selectConfigGroup overriddenSCP.group target="controller"}}>{{overriddenSCP.group.name}}</a>
+        <a class="action" {{action selectConfigGroup overriddenSCP.group target="controller"}}>{{overriddenSCP.group.displayName}}</a>
       {{/if}}
       {{#if overriddenSCP.isEditable}}
 	      {{#if isNotDefaultValue}}

+ 2 - 2
ambari-web/app/templates/common/configs/service_config.hbs

@@ -49,7 +49,7 @@
 	<div class="alert alert-info">
 	  {{t common.group}}&nbsp; 
 	  <span class="btn-group">
-		  <button {{bindAttr disabled="controller.isHostsConfigsPage"}} class="btn">{{selectedConfigGroup.name}}</button>
+		  <button {{bindAttr disabled="controller.isHostsConfigsPage"}} class="btn">{{selectedConfigGroup.displayNameHosts}}</button>
 		  <button {{bindAttr disabled="controller.isHostsConfigsPage"}} class="btn dropdown-toggle" data-toggle="dropdown">
 		    <span class="caret"></span>
 		  </button>
@@ -58,7 +58,7 @@
 		    {{#each configGroup in configGroups}}
            <li>
              <a href="#" {{action "selectConfigGroup" configGroup target="controller"}}>
-               {{configGroup.name}} ({{configGroup.hosts.length}})
+               {{configGroup.displayNameHosts}}
              </a>
            </li>
         {{/each}}

+ 1 - 1
ambari-web/app/templates/main/service/manage_configuration_groups_popup.hbs

@@ -23,7 +23,7 @@
       <div class="span5">
         {{view Em.Select
           contentBinding="configGroups"
-          optionLabelPath="content.displayName"
+          optionLabelPath="content.displayNameHosts"
           selectionBinding="view.selectedConfigGroup"
           multiple="multiple"
           class="group-select"

+ 2 - 0
ambari-web/app/utils/config.js

@@ -43,6 +43,8 @@ App.config = Em.Object.create({
     "&apos;": "'"
   },
   
+  CONFIG_GROUP_NAME_MAX_LENGTH: 40,
+
   /**
    * Since values end up in XML files (core-sit.xml, etc.), certain
    * XML sensitive characters should be escaped. If not we will have