AMBARI-7055. Slider View: Metric names and quick-links should be human readable. (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ff27e56f Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ff27e56f Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ff27e56f Branch: refs/heads/branch-alerts-dev Commit: ff27e56fe8a983c76c40951472575197117b5914 Parents: 0fb6e63 Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Thu Aug 28 16:34:13 2014 +0300 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Thu Aug 28 16:34:13 2014 +0300 ---------------------------------------------------------------------- .../src/main/resources/ui/app/helpers/helper.js | 32 ++++++++++++++++++++ .../ui/app/mappers/slider_apps_mapper.js | 2 +- .../resources/ui/app/templates/slider_app.hbs | 2 +- .../ui/app/templates/slider_app/summary.hbs | 2 +- 4 files changed, 35 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/ff27e56f/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js b/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js index 664328c..88dfcb7 100644 --- a/contrib/views/slider/src/main/resources/ui/app/helpers/helper.js +++ b/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') })); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/ff27e56f/contrib/views/slider/src/main/resources/ui/app/mappers/slider_apps_mapper.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/mappers/slider_apps_mapper.js b/contrib/views/slider/src/main/resources/ui/app/mappers/slider_apps_mapper.js index dbe62bf..e5bcb49 100644 --- a/contrib/views/slider/src/main/resources/ui/app/mappers/slider_apps_mapper.js +++ b/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({ http://git-wip-us.apache.org/repos/asf/ambari/blob/ff27e56f/contrib/views/slider/src/main/resources/ui/app/templates/slider_app.hbs ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/templates/slider_app.hbs b/contrib/views/slider/src/main/resources/ui/app/templates/slider_app.hbs index b8ab969..f435bdf 100644 --- a/contrib/views/slider/src/main/resources/ui/app/templates/slider_app.hbs +++ b/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> http://git-wip-us.apache.org/repos/asf/ambari/blob/ff27e56f/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/summary.hbs ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/summary.hbs b/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/summary.hbs index 010bb9b..68ea262 100644 --- a/contrib/views/slider/src/main/resources/ui/app/templates/slider_app/summary.hbs +++ b/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}}