Show user status in autocomplete suggestions and account-label

Also adds setAccountStatus to gr-rest-api.

Feature: Issue 4394
Change-Id: I61797554145974ce21a134786aa4372ff10b8ab4
This commit is contained in:
Kasper Nilsson
2017-02-02 12:13:01 -08:00
parent 7d4ffdd708
commit 3b740452ed
3 changed files with 36 additions and 19 deletions

View File

@@ -69,28 +69,27 @@
},
_makeSuggestion: function(reviewer) {
var name;
var value;
var generateStatusStr = function(account) {
return account.status ? ' (' + account.status + ')' : '';
};
if (reviewer.account) {
// Reviewer is an account suggestion from getChangeSuggestedReviewers.
return {
name: reviewer.account.name + ' (' + reviewer.account.email + ')',
value: reviewer,
};
name = reviewer.account.name + ' <' + reviewer.account.email + '>' +
generateStatusStr(reviewer.account);
value = reviewer;
} else if (reviewer.group) {
// Reviewer is a group suggestion from getChangeSuggestedReviewers.
return {
name: reviewer.group.name + ' (group)',
value: reviewer,
};
name = reviewer.group.name + ' (group)';
value = reviewer;
} else if (reviewer._account_id) {
// Reviewer is an account suggestion from getSuggestedAccounts.
return {
name: reviewer.name + ' (' + reviewer.email + ')',
value: {
account: reviewer,
count: 1,
},
};
name = reviewer.name + ' <' + reviewer.email + '>' +
generateStatusStr(reviewer);
value = {account: reviewer, count: 1};
}
return {name: name, value: value};
},
_getReviewerSuggestions: function(input) {
@@ -104,7 +103,7 @@
if (!this.filter) { return reviewers.map(this._makeSuggestion); }
return reviewers
.filter(this.filter)
.map(this._makeSuggestion);
.map(this._makeSuggestion.bind(this));
}.bind(this));
},
});

View File

@@ -35,12 +35,13 @@ limitations under the License.
suite('gr-account-entry tests', function() {
var sandbox;
var _nextAccountId = 0;
var makeAccount = function() {
var makeAccount = function(opt_status) {
var accountId = ++_nextAccountId;
return {
_account_id: accountId,
name: 'name ' + accountId,
email: 'email ' + accountId,
status: opt_status,
};
};
@@ -97,7 +98,7 @@ limitations under the License.
var account = makeAccount();
var suggestion = element._makeSuggestion({account: account});
assert.deepEqual(suggestion, {
name: account.name + ' (' + account.email + ')',
name: account.name + ' <' + account.email + '>',
value: {account: account},
});
@@ -110,7 +111,21 @@ limitations under the License.
suggestion = element._makeSuggestion(account);
assert.deepEqual(suggestion, {
name: account.name + ' (' + account.email + ')',
name: account.name + ' <' + account.email + '>',
value: {account: account, count: 1},
});
account = makeAccount('OOO');
suggestion = element._makeSuggestion({account: account});
assert.deepEqual(suggestion, {
name: account.name + ' <' + account.email + '> (OOO)',
value: {account: account},
});
suggestion = element._makeSuggestion(account);
assert.deepEqual(suggestion, {
name: account.name + ' <' + account.email + '> (OOO)',
value: {account: account, count: 1},
});
});

View File

@@ -44,6 +44,9 @@ limitations under the License.
<span hidden$="[[!_computeShowEmail(showEmail, account)]]">
[[_computeEmailStr(account)]]
</span>
<template is="dom-if" if="[[account.status]]">
<span>([[account.status]])</span>
</template>
</span>
</span>
</template>