Merge "Make it configurable after how many chars suggestions are provided"
This commit is contained in:
@@ -2288,6 +2288,13 @@ otherwise, this value applies to both `suggest.accounts` and
|
||||
New configurations should prefer the boolean value for this field
|
||||
and an enum value for `accounts.visibility`.
|
||||
|
||||
[[suggest.from]]suggest.from::
|
||||
+
|
||||
The number of characters that a user must have typed before suggestions
|
||||
are provided. If set to 0, suggestions are always provided.
|
||||
+
|
||||
By default 0.
|
||||
|
||||
[[theme]] Section theme
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ public class GerritConfig implements Cloneable {
|
||||
protected boolean documentationAvailable;
|
||||
protected boolean testChangeMerge;
|
||||
protected String anonymousCowardName;
|
||||
protected int suggestFrom;
|
||||
|
||||
public String getRegisterUrl() {
|
||||
return registerUrl;
|
||||
@@ -238,6 +239,14 @@ public class GerritConfig implements Cloneable {
|
||||
this.anonymousCowardName = anonymousCowardName;
|
||||
}
|
||||
|
||||
public int getSuggestFrom() {
|
||||
return suggestFrom;
|
||||
}
|
||||
|
||||
public void setSuggestFrom(final int suggestFrom) {
|
||||
this.suggestFrom = suggestFrom;
|
||||
}
|
||||
|
||||
public boolean siteHasUsernames() {
|
||||
if (getAuthType() == AuthType.CUSTOM_EXTENSION
|
||||
&& getHttpPasswordUrl() != null
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle;
|
||||
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -28,14 +27,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/** Suggestion Oracle for AccountGroup entities. */
|
||||
public class AccountGroupSuggestOracle extends HighlightSuggestOracle {
|
||||
public class AccountGroupSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
||||
private Map<String, AccountGroup.UUID> priorResults =
|
||||
new HashMap<String, AccountGroup.UUID>();
|
||||
|
||||
private Project.NameKey projectName;
|
||||
|
||||
@Override
|
||||
public void onRequestSuggestions(final Request req, final Callback callback) {
|
||||
public void _onRequestSuggestions(final Request req, final Callback callback) {
|
||||
RpcStatus.hide(new Runnable() {
|
||||
public void run() {
|
||||
SuggestUtil.SVC.suggestAccountGroupForProject(
|
||||
|
||||
@@ -19,15 +19,14 @@ import com.google.gerrit.client.RpcStatus;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.common.data.AccountInfo;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle;
|
||||
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Suggestion Oracle for Account entities. */
|
||||
public class AccountSuggestOracle extends HighlightSuggestOracle {
|
||||
public class AccountSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
||||
@Override
|
||||
public void onRequestSuggestions(final Request req, final Callback callback) {
|
||||
public void _onRequestSuggestions(final Request req, final Callback callback) {
|
||||
RpcStatus.hide(new Runnable() {
|
||||
public void run() {
|
||||
SuggestUtil.SVC.suggestAccount(req.getQuery(), Boolean.TRUE,
|
||||
|
||||
@@ -17,12 +17,11 @@ package com.google.gerrit.client.ui;
|
||||
import com.google.gerrit.client.RpcStatus;
|
||||
import com.google.gerrit.client.projects.ProjectMap;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
|
||||
|
||||
/** Suggestion Oracle for Project.NameKey entities. */
|
||||
public class ProjectNameSuggestOracle extends HighlightSuggestOracle {
|
||||
public class ProjectNameSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
||||
@Override
|
||||
public void onRequestSuggestions(final Request req, final Callback callback) {
|
||||
public void _onRequestSuggestions(final Request req, final Callback callback) {
|
||||
RpcStatus.hide(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -22,18 +22,17 @@ import com.google.gerrit.common.data.AccountInfo;
|
||||
import com.google.gerrit.common.data.ReviewerInfo;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwt.user.client.ui.SuggestOracle;
|
||||
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Suggestion Oracle for reviewers. */
|
||||
public class ReviewerSuggestOracle extends HighlightSuggestOracle {
|
||||
public class ReviewerSuggestOracle extends SuggestAfterTypingNCharsOracle {
|
||||
|
||||
private Change.Id changeId;
|
||||
|
||||
@Override
|
||||
protected void onRequestSuggestions(final Request req, final Callback callback) {
|
||||
protected void _onRequestSuggestions(final Request req, final Callback callback) {
|
||||
RpcStatus.hide(new Runnable() {
|
||||
public void run() {
|
||||
SuggestUtil.SVC.suggestChangeReviewer(changeId, req.getQuery(),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.ui;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
|
||||
|
||||
/**
|
||||
* Suggest oracle that only provides suggestions if the user has typed at least
|
||||
* as many characters as configured by 'suggest.from'. If 'suggest.from' is set
|
||||
* to 0, suggestions will always be provided.
|
||||
*/
|
||||
public abstract class SuggestAfterTypingNCharsOracle extends HighlightSuggestOracle {
|
||||
|
||||
@Override
|
||||
protected void onRequestSuggestions(final Request request, final Callback done) {
|
||||
final int suggestFrom = Gerrit.getConfig().getSuggestFrom();
|
||||
if (suggestFrom == 0 || request.getQuery().length() >= suggestFrom) {
|
||||
_onRequestSuggestions(request, done);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void _onRequestSuggestions(Request request, Callback done);
|
||||
}
|
||||
@@ -121,6 +121,7 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
config.setTestChangeMerge(cfg.getBoolean("changeMerge",
|
||||
"test", false));
|
||||
config.setAnonymousCowardName(anonymousCowardName);
|
||||
config.setSuggestFrom(cfg.getInt("suggest", "from", 0));
|
||||
|
||||
config.setReportBugUrl(cfg.getString("gerrit", null, "reportBugUrl"));
|
||||
if (config.getReportBugUrl() == null) {
|
||||
|
||||
Reference in New Issue
Block a user