ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jai...@apache.org
Subject ambari git commit: AMBARI-11974. Display label for the custom action. (Di Li via jaimin)
Date Thu, 12 Nov 2015 19:33:29 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 9108b522e -> 8429a6a1d


AMBARI-11974. Display label for the custom action. (Di Li via jaimin)


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

Branch: refs/heads/trunk
Commit: 8429a6a1d2f079f112929a0e21b34aac28c0c628
Parents: 9108b52
Author: Jaimin Jetly <jaimin@hortonworks.com>
Authored: Thu Nov 12 11:33:02 2015 -0800
Committer: Jaimin Jetly <jaimin@hortonworks.com>
Committed: Thu Nov 12 11:33:28 2015 -0800

----------------------------------------------------------------------
 ambari-web/app/utils/helper.js                  | 28 ++++++++++++++++++++
 .../main/host/details/host_component_view.js    |  2 +-
 ambari-web/app/views/main/service/item.js       |  4 +--
 ambari-web/test/utils/helper_test.js            | 22 +++++++++++++++
 .../host/details/host_component_view_test.js    |  8 +++---
 5 files changed, 57 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/8429a6a1/ambari-web/app/utils/helper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/helper.js b/ambari-web/app/utils/helper.js
index 0f4a5c3..cb71356 100644
--- a/ambari-web/app/utils/helper.js
+++ b/ambari-web/app/utils/helper.js
@@ -543,6 +543,34 @@ App.format = {
   /**
    * Try to format non predefined names to readable format.
    *
+   * @method normalizeNameBySeparator
+   * @param name {String} - name to format
+   * @param separator {String} - token use to split the string
+   * @return {String}
+   */
+  normalizeNameBySeparators: function(name, separators) {
+    if (!name || typeof name != 'string') return '';
+    name = name.toLowerCase();
+    if (!separators || separators.length == 0) {
+      console.debug("No separators specified. Use default separator '_' instead");
+      separators = ["_"];
+    }
+
+    for (var i = 0; i < separators.length; i++){
+      var separator = separators[i];
+      if (new RegExp(separator, 'g').test(name)) {
+        name = name.split(separator).map(function(singleName) {
+          return this.normalizeName(singleName.toUpperCase());
+        }, this).join(' ');
+      }
+    }
+    return name.capitalize();
+  },
+
+
+  /**
+   * Try to format non predefined names to readable format.
+   *
    * @method normalizeName
    * @param name {String} - name to format
    * @return {String}

http://git-wip-us.apache.org/repos/asf/ambari/blob/8429a6a1/ambari-web/app/views/main/host/details/host_component_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/details/host_component_view.js b/ambari-web/app/views/main/host/details/host_component_view.js
index 0335234..eba1691 100644
--- a/ambari-web/app/views/main/host/details/host_component_view.js
+++ b/ambari-web/app/views/main/host/details/host_component_view.js
@@ -351,7 +351,7 @@ App.HostComponentView = Em.View.extend({
    */
   getCustomCommandLabel: function (command, isSlave) {
     if (isSlave || !(command in App.HostComponentActionMap.getMap(this)) || !App.HostComponentActionMap.getMap(this)[command].label)
{
-      return Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(command)
+      return Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command,
["_", "-", " "]))
     }
     return App.HostComponentActionMap.getMap(this)[command].label;
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/8429a6a1/ambari-web/app/views/main/service/item.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/item.js b/ambari-web/app/views/main/service/item.js
index bfa98ca..d87e16b 100644
--- a/ambari-web/app/views/main/service/item.js
+++ b/ambari-web/app/views/main/service/item.js
@@ -213,9 +213,9 @@ App.MainServiceItemView = Em.View.extend({
           }
 
           options.push(self.createOption(actionMap.MASTER_CUSTOM_COMMAND, {
-            label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(command),
+            label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command,
["_", "-", " "])),
             context: {
-              label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(command),
+              label: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format(App.format.normalizeNameBySeparators(command,
["_", "-", " "])),
               service: component.get('serviceName'),
               component: component.get('componentName'),
               command: command

http://git-wip-us.apache.org/repos/asf/ambari/blob/8429a6a1/ambari-web/test/utils/helper_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/helper_test.js b/ambari-web/test/utils/helper_test.js
index 62acf58..0b4ac90 100644
--- a/ambari-web/test/utils/helper_test.js
+++ b/ambari-web/test/utils/helper_test.js
@@ -294,6 +294,28 @@ describe('utils/helper', function() {
           });
         });
       });
+
+      describe('#normalizeNameBySeparators()', function() {
+        var testMessage = '`{0}` should be converted to `{1}`';
+        var tests = {
+          'APP_TIMELINE_SERVER': 'App Timeline Server',
+          'app_timeline_server': 'App Timeline Server',
+          'APP-TIMELINE-SERVER': 'App Timeline Server',
+          'app-timeline-server': 'App Timeline Server',
+          'APP TIMELINE SERVER': 'App Timeline Server',
+          'app timeline server': 'App Timeline Server',
+          'FALCON': 'Falcon',
+          'falcon': 'Falcon'
+        };
+        for (var inputName in tests) {
+          (function(name) {
+            it(testMessage.format(name, tests[name]), function() {
+              expect(App.format.normalizeNameBySeparators(name, ["-", "_", " "])).to.eql(tests[name]);
+            });
+          })(inputName)
+        }
+      });
+
       describe('#normalizeName()', function() {
         var testMessage = '`{0}` should be converted to `{1}`';
         var tests = {

http://git-wip-us.apache.org/repos/asf/ambari/blob/8429a6a1/ambari-web/test/views/main/host/details/host_component_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/host/details/host_component_view_test.js b/ambari-web/test/views/main/host/details/host_component_view_test.js
index 75cf476..c1ad6aa 100644
--- a/ambari-web/test/views/main/host/details/host_component_view_test.js
+++ b/ambari-web/test/views/main/host/details/host_component_view_test.js
@@ -469,13 +469,13 @@ describe('App.HostComponentView', function() {
         msg: 'Non-slave component not present in `App.HostComponentActionMap.getMap()` should
have a default valid label',
         isSlave: false,
         command: 'CUSTOM',
-        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('CUSTOM')
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('Custom')
       },
       {
         msg: 'Non-slave component present in `App.HostComponentActionMap.getMap()` with no
label should have a default valid label',
         isSlave: false,
         command: 'MASTER_CUSTOM_COMMAND',
-        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('MASTER_CUSTOM_COMMAND')
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('Master
Custom Command')
       },
       {
         msg: 'Non-slave component present in `App.HostComponentActionMap.getMap()` with label
should have a custom valid label',
@@ -487,13 +487,13 @@ describe('App.HostComponentView', function() {
         msg: 'Slave component not present in `App.HostComponentActionMap.getMap()` should
have a default valid label',
         isSlave: true,
         command: 'CUSTOM',
-        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('CUSTOM')
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('Custom')
       },
       {
         msg: 'Slave component present in `App.HostComponentActionMap.getMap()` should have
a default valid label',
         isSlave: true,
         command: 'REFRESHQUEUES',
-        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('REFRESHQUEUES')
+        e: Em.I18n.t('services.service.actions.run.executeCustomCommand.menu').format('Refreshqueues')
       }
     ]);
 


Mime
View raw message