From 797d4cc7ff858b6a07f5c685d5b6990c3091bec0 Mon Sep 17 00:00:00 2001 From: Paladox none Date: Mon, 8 May 2017 21:49:24 +0000 Subject: [PATCH] PolyGerrit: If your account does not have a name use a default name When you create an account with no name it is very hard to go to settings to change the name as the dropdown will be hidden. Lets do what gwtui does and provide a fake name so that dropdown works. Change-Id: I7a6cb6fadff6e12f02611af4020781eb7191e0f6 --- .../gr-account-dropdown.html | 2 +- .../gr-account-dropdown.js | 31 +++++++++++++++---- .../gr-account-dropdown_test.html | 20 ++++++++++++ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.html b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.html index 015cfc5b43..7e358fd839 100644 --- a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.html +++ b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.html @@ -39,7 +39,7 @@ limitations under the License. items=[[links]] top-content=[[topContent]] horizontal-align="right"> - + diff --git a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js index 0e06647eb4..d1da8299d7 100644 --- a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js +++ b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown.js @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. (function() { - 'use strict'; + 'use strict' + + var ANONYMOUS_NAME = 'Anonymous'; Polymer({ is: 'gr-account-dropdown', @@ -20,6 +22,10 @@ properties: { account: Object, _hasAvatars: Boolean, + _anonymousName: { + type: String, + value: ANONYMOUS_NAME, + }, links: { type: Array, value: [ @@ -30,22 +36,35 @@ }, topContent: { type: Array, - computed: '_getTopContent(account)', + computed: '_getTopContent(account, _anonymousName)', }, }, attached: function() { this.$.restAPI.getConfig().then(function(cfg) { this._hasAvatars = !!(cfg && cfg.plugin && cfg.plugin.has_avatars); + if (cfg && cfg.user && + cfg.user.anonymous_coward_name && + cfg.user.anonymous_coward_name !== 'Anonymous Coward') { + this._anonymousName = cfg.user.anonymous_coward_name; + } }.bind(this)); }, - _getTopContent: function(account) { - // if (!account) { return []; } + _getTopContent: function(account, _anonymousName) { return [ - {text: account.name, bold: true}, - {text: account.email}, + {text: this._accountName(account, _anonymousName), bold: true}, + {text: account.email ? account.email : ''}, ]; }, + + _accountName: function(account, _anonymousName) { + if (account && account.name) { + return account.name; + } else if (account && account.email) { + return account.email; + } + return _anonymousName; + }, }); })(); diff --git a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown_test.html b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown_test.html index e833cd6b5e..d7f09b8d39 100644 --- a/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown_test.html +++ b/polygerrit-ui/app/elements/core/gr-account-dropdown/gr-account-dropdown_test.html @@ -48,5 +48,25 @@ limitations under the License. assert.deepEqual(element.topContent, [{text: 'John Doe', bold: true}, {text: 'john@doe.com'}]); }); + + test('test for account without a name', function() { + element.account = {id: '0001'}; + assert.deepEqual(element.topContent, + [{text: 'Anonymous', bold: true}, {text: ''}]); + }); + + test('test for account without a name but using config', function() { + element._anonymousName = 'WikiGerrit'; + element.account = {id: '0001'}; + assert.deepEqual(element.topContent, + [{text: 'WikiGerrit', bold: true}, {text: ''}]); + }); + + test('test for account name as an email', function() { + element._anonymousName = 'WikiGerrit'; + element.account = {email: 'john@doe.com'}; + assert.deepEqual(element.topContent, + [{text: 'john@doe.com', bold: true}, {text: 'john@doe.com'}]); + }); });