Allow setting the filter for project/group list screen by URL parameter
This allows to bookmark a filtered screen and share links to filtered results. E.g. to send somebody a list of all Gerrit plugins the following link could be used: https://gerrit-review.googlesource.com/#/admin/projects/?filter=plugins Change-Id: I7417356a48f7cd8ece7e3d38c41114c571d51955 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -679,14 +679,36 @@ public class Dispatcher {
|
||||
Gerrit.display(token, new GroupListScreen());
|
||||
|
||||
} else if (matchPrefix("/admin/groups/", token)) {
|
||||
group();
|
||||
String rest = skip(token);
|
||||
if (rest.startsWith("?")) {
|
||||
Gerrit.display(token, new GroupListScreen(rest.substring(1)));
|
||||
} else {
|
||||
group();
|
||||
}
|
||||
|
||||
} else if (matchPrefix("/admin/groups", token)) {
|
||||
String rest = skip(token);
|
||||
if (rest.startsWith("?")) {
|
||||
Gerrit.display(token, new GroupListScreen(rest.substring(1)));
|
||||
}
|
||||
|
||||
} else if (matchExact(ADMIN_PROJECTS, token)
|
||||
|| matchExact("/admin/projects", token)) {
|
||||
Gerrit.display(token, new ProjectListScreen());
|
||||
|
||||
} else if (matchPrefix("/admin/projects/", token)) {
|
||||
Gerrit.display(token, selectProject());
|
||||
String rest = skip(token);
|
||||
if (rest.startsWith("?")) {
|
||||
Gerrit.display(token, new ProjectListScreen(rest.substring(1)));
|
||||
} else {
|
||||
Gerrit.display(token, selectProject());
|
||||
}
|
||||
|
||||
} else if (matchPrefix("/admin/projects", token)) {
|
||||
String rest = skip(token);
|
||||
if (rest.startsWith("?")) {
|
||||
Gerrit.display(token, new ProjectListScreen(rest.substring(1)));
|
||||
}
|
||||
|
||||
} else if (matchPrefix(ADMIN_PLUGINS, token)
|
||||
|| matchExact("/admin/plugins", token)) {
|
||||
|
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.client.admin;
|
||||
|
||||
import static com.google.gerrit.common.PageLinks.ADMIN_GROUPS;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.groups.GroupMap;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
@@ -23,6 +25,7 @@ import com.google.gerrit.client.ui.IgnoreOutdatedFilterResultsCallbackWrapper;
|
||||
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.http.client.URL;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
@@ -32,6 +35,22 @@ public class GroupListScreen extends AccountScreen implements FilteredUserInterf
|
||||
private NpTextBox filterTxt;
|
||||
private String subname;
|
||||
|
||||
public GroupListScreen() {
|
||||
}
|
||||
|
||||
public GroupListScreen(String params) {
|
||||
for (String kvPair : params.split("[,;&]")) {
|
||||
String[] kv = kvPair.split("=", 2);
|
||||
if (kv.length != 2 || kv[0].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("filter".equals(kv[0])) {
|
||||
subname = URL.decodeQueryString(kv[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad() {
|
||||
super.onLoad();
|
||||
@@ -39,6 +58,8 @@ public class GroupListScreen extends AccountScreen implements FilteredUserInterf
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
setToken(subname == null || "".equals(subname) ? ADMIN_GROUPS
|
||||
: ADMIN_GROUPS + "?filter=" + URL.encodeQueryString(subname));
|
||||
GroupMap.match(subname,
|
||||
new IgnoreOutdatedFilterResultsCallbackWrapper<GroupMap>(this,
|
||||
new ScreenLoadCallback<GroupMap>(this) {
|
||||
@@ -87,6 +108,9 @@ public class GroupListScreen extends AccountScreen implements FilteredUserInterf
|
||||
@Override
|
||||
public void onShowView() {
|
||||
super.onShowView();
|
||||
if (subname != null) {
|
||||
filterTxt.setCursorPos(subname.length());
|
||||
}
|
||||
filterTxt.setFocus(true);
|
||||
}
|
||||
|
||||
|
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.client.admin;
|
||||
|
||||
import static com.google.gerrit.common.PageLinks.ADMIN_PROJECTS;
|
||||
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.GitwebLink;
|
||||
@@ -29,6 +31,7 @@ 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.http.client.URL;
|
||||
import com.google.gwt.user.client.History;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
@@ -41,6 +44,22 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
|
||||
private NpTextBox filterTxt;
|
||||
private String subname;
|
||||
|
||||
public ProjectListScreen() {
|
||||
}
|
||||
|
||||
public ProjectListScreen(String params) {
|
||||
for (String kvPair : params.split("[,;&]")) {
|
||||
String[] kv = kvPair.split("=", 2);
|
||||
if (kv.length != 2 || kv[0].isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ("filter".equals(kv[0])) {
|
||||
subname = URL.decodeQueryString(kv[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLoad() {
|
||||
super.onLoad();
|
||||
@@ -48,6 +67,8 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
setToken(subname == null || "".equals(subname) ? ADMIN_PROJECTS
|
||||
: ADMIN_PROJECTS + "?filter=" + URL.encodeQueryString(subname));
|
||||
ProjectMap.match(subname,
|
||||
new IgnoreOutdatedFilterResultsCallbackWrapper<ProjectMap>(this,
|
||||
new ScreenLoadCallback<ProjectMap>(this) {
|
||||
@@ -141,6 +162,9 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
|
||||
@Override
|
||||
public void onShowView() {
|
||||
super.onShowView();
|
||||
if (subname != null) {
|
||||
filterTxt.setCursorPos(subname.length());
|
||||
}
|
||||
filterTxt.setFocus(true);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user