Files
gerrit/polygerrit-ui/app/scripts/gr-display-name-utils/gr-display-name-utils.js
Dmitrii Filippov 587086bc89 Editor for accounts/groups list.
To implement some new UI feature, we need a way to specify list
of accounts and/or groups. Similar solutions already exists for 'change'
view, but it can't be reused as-is in other places.
In this commit the existing solution was reworked to use the same
editor in different places.
Editor was splitted to 2 parts - editor itself and suggestion provider.

Change-Id: I43ce060e568a69f9842fbfad6f5fd62361ab2022
2019-09-13 09:29:55 +00:00

56 lines
1.6 KiB
JavaScript

(function(window) {
'use strict';
if (window.GrDisplayNameUtils) {
return;
}
const ANONYMOUS_NAME = 'Anonymous';
class GrDisplayNameUtils {
/**
* enableEmail when true enables to fallback to using email if
* the account name is not avilable.
*/
static getUserName(config, account, enableEmail) {
if (account && account.name) {
return account.name;
} else if (account && account.username) {
return account.username;
} else if (enableEmail && account && account.email) {
return account.email;
} else if (config && config.user &&
config.user.anonymous_coward_name !== 'Anonymous Coward') {
return config.user.anonymous_coward_name;
}
return ANONYMOUS_NAME;
}
static getAccountDisplayName(config, account, enableEmail) {
const reviewerName = this._accountOrAnon(config, account, enableEmail);
const reviewerEmail = this._accountEmail(account.email);
const reviewerStatus = account.status ? '(' + account.status + ')' : '';
return [reviewerName, reviewerEmail, reviewerStatus]
.filter(p => p.length > 0).join(' ');
}
static _accountOrAnon(config, reviewer, enableEmail) {
return this.getUserName(config, reviewer, !!enableEmail);
}
static _accountEmail(email) {
if (typeof email !== 'undefined') {
return '<' + email + '>';
}
return '';
}
static getGroupDisplayName(group) {
return group.name + ' (group)';
}
}
window.GrDisplayNameUtils = GrDisplayNameUtils;
})(window);