Merge "Allow filtering of projects on the ProjectListScreen"
This commit is contained in:
@@ -224,4 +224,6 @@ public interface GerritCss extends CssResource {
|
||||
String watchedProjectFilter();
|
||||
String selectPatchSetOldVersion();
|
||||
String patchCellReverseDiff();
|
||||
String projectFilterPanel();
|
||||
String projectFilterLabel();
|
||||
}
|
||||
|
||||
@@ -101,6 +101,7 @@ public interface AdminConstants extends Constants {
|
||||
String groupTabGeneral();
|
||||
String groupTabMembers();
|
||||
String projectListTitle();
|
||||
String projectFilter();
|
||||
String createProjectTitle();
|
||||
String projectListQueryLink();
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ createGroupTitle = Create Group
|
||||
groupTabGeneral = General
|
||||
groupTabMembers = Members
|
||||
projectListTitle = Projects
|
||||
projectFilter = Filter
|
||||
createProjectTitle = Create Project
|
||||
projectListQueryLink = Search for changes on this project
|
||||
|
||||
|
||||
@@ -25,29 +25,64 @@ import com.google.gerrit.client.ui.ProjectSearchLink;
|
||||
import com.google.gerrit.client.ui.ProjectsTable;
|
||||
import com.google.gerrit.client.ui.Screen;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gwt.event.dom.client.KeyUpEvent;
|
||||
import com.google.gwt.event.dom.client.KeyUpHandler;
|
||||
import com.google.gwt.user.client.History;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
|
||||
public class ProjectListScreen extends Screen {
|
||||
private ProjectsTable projects;
|
||||
private NpTextBox filterTxt;
|
||||
private String subname;
|
||||
|
||||
@Override
|
||||
protected void onLoad() {
|
||||
super.onLoad();
|
||||
ProjectMap.all(new ScreenLoadCallback<ProjectMap>(this) {
|
||||
@Override
|
||||
protected void preDisplay(final ProjectMap result) {
|
||||
projects.display(result);
|
||||
projects.finishDisplay();
|
||||
}
|
||||
});
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
if (subname == null || "".equals(subname)) {
|
||||
ProjectMap.all(new ScreenLoadCallback<ProjectMap>(this) {
|
||||
@Override
|
||||
protected void preDisplay(final ProjectMap result) {
|
||||
if (subname == null || "".equals(subname)) {
|
||||
display(result);
|
||||
}
|
||||
// Else ignore the result, due to the same reason as below.
|
||||
}
|
||||
});
|
||||
} else {
|
||||
final String mySubname = subname;
|
||||
ProjectMap.match(subname, new ScreenLoadCallback<ProjectMap>(this) {
|
||||
@Override
|
||||
protected void preDisplay(final ProjectMap result) {
|
||||
if (mySubname.equals(subname)) {
|
||||
display(result);
|
||||
}
|
||||
// Else ignore the result, the user has already changed subname and
|
||||
// the result is not relevant anymore. If multiple RPC's are fired
|
||||
// the results may come back out-of-order and a non-relevant result
|
||||
// could overwrite the correct result if not ignored.
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void display(final ProjectMap result) {
|
||||
projects.display(result);
|
||||
projects.finishDisplay();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInitUI() {
|
||||
super.onInitUI();
|
||||
setPageTitle(Util.C.projectListTitle());
|
||||
initPageHeader();
|
||||
|
||||
projects = new ProjectsTable() {
|
||||
@Override
|
||||
@@ -99,6 +134,31 @@ public class ProjectListScreen extends Screen {
|
||||
add(projects);
|
||||
}
|
||||
|
||||
private void initPageHeader() {
|
||||
final HorizontalPanel hp = new HorizontalPanel();
|
||||
hp.setStyleName(Gerrit.RESOURCES.css().projectFilterPanel());
|
||||
final Label filterLabel = new Label(Util.C.projectFilter());
|
||||
filterLabel.setStyleName(Gerrit.RESOURCES.css().projectFilterLabel());
|
||||
hp.add(filterLabel);
|
||||
filterTxt = new NpTextBox();
|
||||
filterTxt.setValue(subname);
|
||||
filterTxt.addKeyUpHandler(new KeyUpHandler() {
|
||||
@Override
|
||||
public void onKeyUp(KeyUpEvent event) {
|
||||
subname = filterTxt.getValue();
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
hp.add(filterTxt);
|
||||
add(hp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShowView() {
|
||||
super.onShowView();
|
||||
filterTxt.setFocus(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerKeys() {
|
||||
super.registerKeys();
|
||||
|
||||
@@ -1471,3 +1471,14 @@ a:hover.downloadLink {
|
||||
/** PluginListScreen **/
|
||||
.pluginsTable {
|
||||
}
|
||||
|
||||
/** ProjectListScreen **/
|
||||
.projectFilterPanel {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.projectFilterPanel input {
|
||||
width: 200px;
|
||||
}
|
||||
.projectFilterLabel {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
@@ -53,6 +53,14 @@ public class ProjectMap extends NativeMap<ProjectInfo> {
|
||||
.get(NativeMap.copyKeysIntoChildren(cb));
|
||||
}
|
||||
|
||||
public static void match(String match, AsyncCallback<ProjectMap> cb) {
|
||||
new RestApi("/projects/")
|
||||
.addParameter("m", match)
|
||||
.addParameterRaw("type", "ALL")
|
||||
.addParameterTrue("d") // description
|
||||
.get(NativeMap.copyKeysIntoChildren(cb));
|
||||
}
|
||||
|
||||
protected ProjectMap() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
package com.google.gerrit.server.project;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
import com.google.gerrit.common.errors.NoSuchGroupException;
|
||||
@@ -26,7 +28,6 @@ import com.google.gerrit.extensions.restapi.RestReadView;
|
||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.Project.NameKey;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.gerrit.server.StringUtil;
|
||||
@@ -57,6 +58,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
@@ -134,6 +136,9 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
@Option(name = "-p", metaVar = "PERFIX", usage = "match project prefix")
|
||||
private String matchPrefix;
|
||||
|
||||
@Option(name = "-m", metaVar = "MATCH", usage = "match project substring")
|
||||
private String matchSubstring;
|
||||
|
||||
@Option(name = "--has-acl-for", metaVar = "GROUP", usage =
|
||||
"displays only projects on which access rights for this group are directly assigned")
|
||||
private AccountGroup.UUID groupUuid;
|
||||
@@ -378,9 +383,17 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
||||
}
|
||||
}
|
||||
|
||||
private Iterable<NameKey> scan() {
|
||||
private Iterable<Project.NameKey> scan() {
|
||||
if (matchPrefix != null) {
|
||||
return projectCache.byName(matchPrefix);
|
||||
} else if (matchSubstring != null) {
|
||||
return Iterables.filter(projectCache.all(),
|
||||
new Predicate<Project.NameKey>() {
|
||||
public boolean apply(Project.NameKey in) {
|
||||
return in.get().toLowerCase(Locale.US)
|
||||
.contains(matchSubstring.toLowerCase(Locale.US));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return projectCache.all();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user