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
This commit is contained in:
parent
9d00f8e216
commit
797d4cc7ff
@ -39,7 +39,7 @@ limitations under the License.
|
||||
items=[[links]]
|
||||
top-content=[[topContent]]
|
||||
horizontal-align="right">
|
||||
<span hidden$="[[_hasAvatars]]" hidden>[[account.name]]</span>
|
||||
<span hidden$="[[_hasAvatars]]" hidden>[[_accountName(account, _anonymousName)]]</span>
|
||||
<gr-avatar account="[[account]]" hidden$="[[!_hasAvatars]]" hidden
|
||||
image-size="56" aria-label="Account avatar"></gr-avatar>
|
||||
</gr-dropdown>
|
||||
|
@ -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;
|
||||
},
|
||||
});
|
||||
})();
|
||||
|
@ -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'}]);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user