Account suggestion: Show suggestion with email that was matched
If an account is suggested because the query string matched on a secondary email address, then the displayed suggestion should show that secondary email in the suggestion (and not the preferred email). This way the user can see why the account was suggested. Change-Id: I86a9e5c099d4619e064aa52c68ed5b98c6faff13 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
parent
2eadde4d9f
commit
7e6343dd8a
@ -17,6 +17,7 @@ package com.google.gerrit.client.info;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
import com.google.gwt.core.client.JsArrayString;
|
||||
import com.google.gwtjsonrpc.client.impl.ser.JavaSqlTimestamp_JsonSerializer;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
@ -29,6 +30,8 @@ public class AccountInfo extends JavaScriptObject {
|
||||
public final native int _accountId() /*-{ return this._account_id || 0; }-*/;
|
||||
public final native String name() /*-{ return this.name; }-*/;
|
||||
public final native String email() /*-{ return this.email; }-*/;
|
||||
public final native JsArrayString secondaryEmails()
|
||||
/*-{ return this.secondary_emails; }-*/;
|
||||
public final native String username() /*-{ return this.username; }-*/;
|
||||
|
||||
public final Timestamp registeredOn() {
|
||||
|
@ -35,7 +35,7 @@ public class AccountSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
||||
public void onSuccess(JsArray<AccountInfo> in) {
|
||||
List<AccountSuggestion> r = new ArrayList<>(in.length());
|
||||
for (AccountInfo p : Natives.asList(in)) {
|
||||
r.add(new AccountSuggestion(p));
|
||||
r.add(new AccountSuggestion(p, req.getQuery()));
|
||||
}
|
||||
cb.onSuggestionsReady(req, new Response(r));
|
||||
}
|
||||
@ -43,20 +43,34 @@ public class AccountSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
||||
}
|
||||
|
||||
private static class AccountSuggestion implements SuggestOracle.Suggestion {
|
||||
private final AccountInfo info;
|
||||
private final String suggestion;
|
||||
|
||||
AccountSuggestion(final AccountInfo k) {
|
||||
info = k;
|
||||
AccountSuggestion(AccountInfo info, String query) {
|
||||
String s = FormatUtil.nameEmail(info);
|
||||
if (!s.toLowerCase().contains(query.toLowerCase())
|
||||
&& info.secondaryEmails() != null) {
|
||||
for (String email : Natives.asList(info.secondaryEmails())) {
|
||||
AccountInfo info2 = AccountInfo.create(info._accountId(), info.name(),
|
||||
email, info.username());
|
||||
String s2 = FormatUtil.nameEmail(info2);
|
||||
if (s2.toLowerCase().contains(query.toLowerCase())) {
|
||||
s = s2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.suggestion = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayString() {
|
||||
return FormatUtil.nameEmail(info);
|
||||
return suggestion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReplacementString() {
|
||||
return FormatUtil.nameEmail(info);
|
||||
return suggestion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user