ソースを参照

AMBARI-7055. Slider View: Metric names and quick-links should be human readable. (onechiporenko)

Oleg Nechiporenko 10 年 前
コミット
ff27e56fe8

+ 32 - 0
contrib/views/slider/src/main/resources/ui/app/helpers/helper.js

@@ -68,4 +68,36 @@ App.registerBoundHelper('formatWordBreak', Em.View.extend({
     var r = new RegExp('\\'+d,"g");
     return this.get('content') && this.get('content').replace(r, d+'<wbr />');
   }.property('content')
+}));
+
+/**
+ * Return formatted string with inserted spaces before upper case and replaced '_' to spaces
+ * Also capitalize first letter
+ *
+ * @param {String} content
+ *
+ * Examples:
+ *
+ * returns 'apple'
+ * {{humanize 'Apple'}}
+ *
+ * returns 'apple_banana'
+ * {{humanize 'Apple banana'}}
+ *
+ * returns 'apple_bananaUranium'
+ * {{humanize 'Apple banana Uranium'}}
+ */
+App.registerBoundHelper('humanize', Em.View.extend({
+
+  tagName: 'span',
+
+  template: Ember.Handlebars.compile('{{{view.result}}}'),
+
+  /**
+   * @type {string}
+   */
+  result: function() {
+    var content = this.get('content');
+    return content && (content[0].toUpperCase() + content.slice(1)).replace(/([A-Z])/g, ' $1').replace(/_/g, ' ');
+  }.property('content')
 }));

+ 1 - 1
contrib/views/slider/src/main/resources/ui/app/mappers/slider_apps_mapper.js

@@ -141,7 +141,7 @@ App.SliderAppsMapper = App.Mapper.createWithMixins(App.RunPeriodically, {
         masterActiveTime.value = new Date(Date.now() - masterActiveTime.value).getHours() + "h:" + new Date(Date.now() - masterActiveTime.value).getMinutes() + "m";
       }
       if(masterStartTime){
-        masterStartTime.value = (new Date(masterStartTime.value).toUTCString());
+        masterStartTime.value = (new Date(parseInt(masterStartTime.value)).toUTCString());
       }
       apps.push(
         Ember.Object.create({

+ 1 - 1
contrib/views/slider/src/main/resources/ui/app/templates/slider_app.hbs

@@ -33,7 +33,7 @@
       <ul class="dropdown-menu">
         {{#each option in controller.availableActions}}
           <li>
-            <a {{action 'openModal' option target='controller'}}>{{option.title}}</a>
+            <a {{action 'openModal' option target='controller'}}>{{humanize option.title}}</a>
           </li>
         {{/each}}
       </ul>

+ 1 - 1
contrib/views/slider/src/main/resources/ui/app/templates/slider_app/summary.hbs

@@ -44,7 +44,7 @@
             </tr>
             {{#each controller.model.jmx}}
               <tr>
-                <td>{{key}}</td>
+                <td>{{humanize key}}</td>
                 <td>{{formatWordBreak value}}</td>
               </tr>
             {{/each}}