Make it configurable after how many chars suggestions are provided
Suggestions for reviewers, accounts, account groups and projects are provided to the user as soon as he starts typing. On systems with many accounts, account groups and projects providing suggestions may be expensive, especially for short query strings. Suggestions for very short query strings are often not very useful for the user because the list of suggestions is too big. Normally useful suggestions are only provided if the user has typed a certain number of character that is sufficient to limit the suggestions to a reasonable set. In this case it makes sense to show suggestions only if the user has typed a least a certain number of characters. Allow administrators to configure after how many typed characters suggestions should be provided. By default suggestions will always be provided. Change-Id: I66bc9eeee9e1f67063fcb21dca5e2c76b20e7187 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -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);
|
||||
}
|
Reference in New Issue
Block a user