AMBARI-20602. Comparison for configs with list of hostNames doesn't show all hosts correctly (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d14dba6f Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d14dba6f Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d14dba6f Branch: refs/heads/branch-dev-logsearch Commit: d14dba6fabd948290403a7857f75da174d0ef1d9 Parents: c77f4ce Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Tue Mar 28 11:49:06 2017 +0300 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Tue Mar 28 14:43:44 2017 +0300 ---------------------------------------------------------------------- .../app/templates/wizard/component_hosts.hbs | 2 +- ambari-web/app/views/common/controls_view.js | 17 ++++++----------- .../test/views/common/controls_view_test.js | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/d14dba6f/ambari-web/app/templates/wizard/component_hosts.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/wizard/component_hosts.hbs b/ambari-web/app/templates/wizard/component_hosts.hbs index 802b970..e23b742 100644 --- a/ambari-web/app/templates/wizard/component_hosts.hbs +++ b/ambari-web/app/templates/wizard/component_hosts.hbs @@ -20,7 +20,7 @@ {{t installer.noHostsAssigned}} {{else}} {{#if view.hasMultipleHosts}} - <a href="#" {{action showHosts target="view"}}>{{value.firstObject}} {{t and}} {{view.otherLength}}</a> + <a href="#" {{action showHosts target="view"}}>{{view.firstHost}} {{t and}} {{view.otherLength}}</a> {{else}} {{view.value.[0]}} {{/if}} http://git-wip-us.apache.org/repos/asf/ambari/blob/d14dba6f/ambari-web/app/views/common/controls_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/controls_view.js b/ambari-web/app/views/common/controls_view.js index 120ca9a..da886ed 100644 --- a/ambari-web/app/views/common/controls_view.js +++ b/ambari-web/app/views/common/controls_view.js @@ -914,28 +914,21 @@ App.ServiceConfigMultipleHostsDisplay = Ember.Mixin.create(App.ServiceConfigHost if (!this.get('value')) { return true; } - return this.get('value').length === 0; + return !this.get('value.length'); }.property('value'), - formatValue: function() { - if (Em.isArray(this.get('value')) && this.get('value').length === 1) { - return this.get('value.firstObject'); - } else { - return this.get('value'); - } - }.property('value'), + formatValue: Em.computed.ifThenElseByKeys('hasOneHost', 'value.firstObject', 'value'), hasOneHost: Em.computed.equal('value.length', 1), hasMultipleHosts: Em.computed.gt('value.length', 1), otherLength: function () { - var len = this.get('value').length; + var len = this.get('value.length'); if (len > 2) { return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.others').format(len - 1); - } else { - return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.other'); } + return Em.I18n.t('installer.controls.serviceConfigMultipleHosts.other'); }.property('value') }); @@ -954,6 +947,8 @@ App.ServiceConfigComponentHostsView = Ember.View.extend(App.ServiceConfigMultipl templateName: require('templates/wizard/component_hosts'), + firstHost: Em.computed.firstNotBlank('value.firstObject', 'serviceConfig.value.firstObject'), + /** * Onclick handler for link */ http://git-wip-us.apache.org/repos/asf/ambari/blob/d14dba6f/ambari-web/test/views/common/controls_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/controls_view_test.js b/ambari-web/test/views/common/controls_view_test.js index 3ff5253..17dd6e1 100644 --- a/ambari-web/test/views/common/controls_view_test.js +++ b/ambari-web/test/views/common/controls_view_test.js @@ -979,3 +979,22 @@ describe('App.BaseUrlTextField', function () { }); }); }); + +describe('App.ServiceConfigComponentHostsView', function () { + + function getView (value, serviceConfig) { + return App.ServiceConfigComponentHostsView.create({ + value: value, + serviceConfig: serviceConfig + }); + } + + App.TestAliases.testAsComputedFirstNotBlank(getView(), 'firstHost', ['value.firstObject', 'serviceConfig.value.firstObject']); + + App.TestAliases.testAsComputedIfThenElseByKeys(getView(), 'formatValue', 'hasOneHost', 'value.firstObject', 'value'); + + App.TestAliases.testAsComputedEqual(getView(), 'hasOneHost', 'value.length', 1); + + App.TestAliases.testAsComputedGt(getView(), 'hasMultipleHosts', 'value.length', 1); + +}) \ No newline at end of file