Repository: ambari
Updated Branches:
  refs/heads/trunk 28cb0cf50 -> a133aee9a


AMBARI-19779 Normalize upgrade status label in Upgrade History. (atkach)


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

Branch: refs/heads/trunk
Commit: a133aee9ab408a41493855fa701437d37a41ed32
Parents: 28cb0cf
Author: Andrii Tkach <[email protected]>
Authored: Mon Jan 30 16:36:24 2017 +0200
Committer: Andrii Tkach <[email protected]>
Committed: Tue Jan 31 13:39:38 2017 +0200

----------------------------------------------------------------------
 ambari-web/app/models/host_stack_version.js     |  4 ++-
 .../stack_version/stack_upgrade_history.js      |  7 ++++-
 .../admin/stack_upgrade/upgrade_history.hbs     |  2 +-
 ambari-web/app/utils/string_utils.js            | 14 +++++++++
 ambari-web/test/utils/string_utils_test.js      | 30 ++++++++++++++++++++
 5 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a133aee9/ambari-web/app/models/host_stack_version.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/host_stack_version.js 
b/ambari-web/app/models/host_stack_version.js
index b0c000e..7e6d0a0 100644
--- a/ambari-web/app/models/host_stack_version.js
+++ b/ambari-web/app/models/host_stack_version.js
@@ -18,6 +18,8 @@
 
 var App = require('app');
 
+var stringUtils = require('utils/string_utils');
+
 App.HostStackVersion = DS.Model.extend({
   stack: DS.attr('string'),
   version: DS.attr('string'),
@@ -86,5 +88,5 @@ App.HostStackVersion.statusDefinition = [
 App.HostStackVersion.formatStatus = function (status) {
   return App.HostStackVersion.statusDefinition.contains(status) ?
     Em.I18n.t('hosts.host.stackVersions.status.' + status.toLowerCase()) :
-    status.toCapital();
+    stringUtils.upperUnderscoreToText(status);
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/a133aee9/ambari-web/app/models/stack_version/stack_upgrade_history.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/stack_version/stack_upgrade_history.js 
b/ambari-web/app/models/stack_version/stack_upgrade_history.js
index 9e0439c..7276c5c 100644
--- a/ambari-web/app/models/stack_version/stack_upgrade_history.js
+++ b/ambari-web/app/models/stack_version/stack_upgrade_history.js
@@ -18,6 +18,8 @@
 
 var App = require('app');
 
+var stringUtils = require('utils/string_utils');
+
 App.StackUpgradeHistory = DS.Model.extend({
   requestId: DS.attr('number'),
   clusterName: DS.attr('string'),
@@ -31,7 +33,10 @@ App.StackUpgradeHistory = DS.Model.extend({
   skipServiceCheckFailures: DS.attr('boolean'),
   endTime: DS.attr('number'),
   startTime: DS.attr('number'),
-  createTime: DS.attr('number')
+  createTime: DS.attr('number'),
+  displayStatus: function() {
+    return stringUtils.upperUnderscoreToText(this.get('requestStatus'));
+  }.property('requestStatus')
 });
 
 App.StackUpgradeHistory.FIXTURES = [];

http://git-wip-us.apache.org/repos/asf/ambari/blob/a133aee9/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
----------------------------------------------------------------------
diff --git 
a/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs 
b/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
index e023fbb..44168ca 100644
--- a/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
+++ b/ambari-web/app/templates/main/admin/stack_upgrade/upgrade_history.hbs
@@ -87,7 +87,7 @@
                 <span>{{item.endTimeLabel}}</span>
               </td>
               <td>
-                <span>{{item.requestStatus}}</span>
+                <span>{{item.displayStatus}}</span>
               </td>
             </tr>
           {{/each}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a133aee9/ambari-web/app/utils/string_utils.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/string_utils.js 
b/ambari-web/app/utils/string_utils.js
index f4e3674..13be1ec 100644
--- a/ambari-web/app/utils/string_utils.js
+++ b/ambari-web/app/utils/string_utils.js
@@ -241,5 +241,19 @@ module.exports = {
       text += allowed.charAt(Math.floor(Math.random() * allowed.length));
     }
     return text;
+  },
+
+  /**
+   * @param {string} string
+   * @returns {string}
+   * @method upperUnderscoreToText
+   */
+  upperUnderscoreToText: function(string) {
+    if (typeof(string) !== 'string') {
+      return '';
+    }
+    return string.split('_').map(function(word) {
+      return word.toLowerCase().capitalize();
+    }).join(' ');
   }
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/a133aee9/ambari-web/test/utils/string_utils_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/string_utils_test.js 
b/ambari-web/test/utils/string_utils_test.js
index 3c7b077..6750906 100644
--- a/ambari-web/test/utils/string_utils_test.js
+++ b/ambari-web/test/utils/string_utils_test.js
@@ -255,4 +255,34 @@ describe('stringUtils', function () {
       });
     });
   });
+
+  describe('#upperUnderscoreToText', function() {
+    var testCases = [
+      {
+        input: null,
+        expected: ''
+      },
+      {
+        input: '',
+        expected: ''
+      },
+      {
+        input: 'foo',
+        expected: 'Foo'
+      },
+      {
+        input: 'FOO',
+        expected: 'Foo'
+      },
+      {
+        input: 'FOO_BAR',
+        expected: 'Foo Bar'
+      }
+    ];
+    testCases.forEach(function(test) {
+      it('should return ' + test.expected + ' when string is ' + test.input, 
function() {
+        
expect(stringUtils.upperUnderscoreToText(test.input)).to.be.equal(test.expected);
+      });
+    });
+  });
 });

Reply via email to