Merge "Support filtering of groups in GroupListScreen"
This commit is contained in:
@@ -97,6 +97,7 @@ public interface AdminConstants extends Constants {
|
||||
String groupItemHelp();
|
||||
|
||||
String groupListTitle();
|
||||
String groupFilter();
|
||||
String createGroupTitle();
|
||||
String groupTabGeneral();
|
||||
String groupTabMembers();
|
||||
|
||||
@@ -77,6 +77,7 @@ because they have open changes:
|
||||
groupItemHelp = group
|
||||
|
||||
groupListTitle = Groups
|
||||
groupFilter = Filter
|
||||
createGroupTitle = Create Group
|
||||
groupTabGeneral = General
|
||||
groupTabMembers = Members
|
||||
|
||||
@@ -14,34 +14,85 @@
|
||||
|
||||
package com.google.gerrit.client.admin;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.groups.GroupMap;
|
||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||
import com.google.gerrit.client.ui.AccountScreen;
|
||||
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.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||
|
||||
public class GroupListScreen extends AccountScreen {
|
||||
private GroupTable groups;
|
||||
private NpTextBox filterTxt;
|
||||
private String subname;
|
||||
|
||||
@Override
|
||||
protected void onLoad() {
|
||||
super.onLoad();
|
||||
GroupMap.all(new ScreenLoadCallback<GroupMap>(this) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
final String mySubname = subname;
|
||||
GroupMap.match(subname, new ScreenLoadCallback<GroupMap>(this) {
|
||||
@Override
|
||||
protected void preDisplay(final GroupMap result) {
|
||||
groups.display(result);
|
||||
if ((mySubname == null && subname == null)
|
||||
|| (mySubname != null && 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 GroupMap result) {
|
||||
groups.display(result, subname);
|
||||
groups.finishDisplay();
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onInitUI() {
|
||||
super.onInitUI();
|
||||
setPageTitle(Util.C.groupListTitle());
|
||||
initPageHeader();
|
||||
|
||||
groups = new GroupTable(true /* hyperlink to admin */, PageLinks.ADMIN_GROUPS);
|
||||
add(groups);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.groups.GroupInfo;
|
||||
import com.google.gerrit.client.groups.GroupMap;
|
||||
import com.google.gerrit.client.ui.Hyperlink;
|
||||
import com.google.gerrit.client.ui.HighlightingInlineHyperlink;
|
||||
import com.google.gerrit.client.ui.NavigationTable;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
@@ -77,6 +77,10 @@ public class GroupTable extends NavigationTable<GroupInfo> {
|
||||
}
|
||||
|
||||
public void display(final GroupMap groups) {
|
||||
display(groups, null);
|
||||
}
|
||||
|
||||
public void display(final GroupMap groups, final String toHighlight) {
|
||||
while (1 < table.getRowCount())
|
||||
table.removeRow(table.getRowCount() - 1);
|
||||
|
||||
@@ -91,14 +95,14 @@ public class GroupTable extends NavigationTable<GroupInfo> {
|
||||
final int row = table.getRowCount();
|
||||
table.insertRow(row);
|
||||
applyDataRowStyle(row);
|
||||
populate(row, group);
|
||||
populate(row, group, toHighlight);
|
||||
}
|
||||
}
|
||||
|
||||
void populate(final int row, final GroupInfo k) {
|
||||
void populate(final int row, final GroupInfo k, final String toHighlight) {
|
||||
if (enableLink) {
|
||||
table.setWidget(row, 1, new Hyperlink(k.name(),
|
||||
Dispatcher.toGroup(k.getGroupId())));
|
||||
table.setWidget(row, 1, new HighlightingInlineHyperlink(k.name(),
|
||||
Dispatcher.toGroup(k.getGroupId()), toHighlight));
|
||||
} else {
|
||||
table.setText(row, 1, k.name());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,16 @@ public class GroupMap extends NativeMap<GroupInfo> {
|
||||
.get(NativeMap.copyKeysIntoChildren(callback));
|
||||
}
|
||||
|
||||
public static void match(String match, AsyncCallback<GroupMap> cb) {
|
||||
if (match == null || "".equals(match)) {
|
||||
all(cb);
|
||||
} else {
|
||||
new RestApi("/groups/")
|
||||
.addParameter("m", match)
|
||||
.get(NativeMap.copyKeysIntoChildren(cb));
|
||||
}
|
||||
}
|
||||
|
||||
protected GroupMap() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.server.account;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gerrit.common.data.GroupReference;
|
||||
@@ -27,6 +28,7 @@ import com.google.inject.Provider;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -42,6 +44,7 @@ public class VisibleGroups {
|
||||
|
||||
private boolean onlyVisibleToAll;
|
||||
private AccountGroup.Type groupType;
|
||||
private String match;
|
||||
|
||||
@Inject
|
||||
VisibleGroups(final Provider<IdentifiedUser> currentUser,
|
||||
@@ -60,6 +63,10 @@ public class VisibleGroups {
|
||||
this.groupType = groupType;
|
||||
}
|
||||
|
||||
public void setMatch(final String match) {
|
||||
this.match = match;
|
||||
}
|
||||
|
||||
public List<AccountGroup> get() {
|
||||
return filterGroups(groupCache.all());
|
||||
}
|
||||
@@ -109,6 +116,12 @@ public class VisibleGroups {
|
||||
final boolean isAdmin =
|
||||
identifiedUser.get().getCapabilities().canAdministrateServer();
|
||||
for (final AccountGroup group : groups) {
|
||||
if (!Strings.isNullOrEmpty(match)) {
|
||||
if (!group.getName().toLowerCase(Locale.US)
|
||||
.contains(match.toLowerCase(Locale.US))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!isAdmin) {
|
||||
final GroupControl c = groupControlFactory.controlFor(group);
|
||||
if (!c.isVisible()) {
|
||||
|
||||
@@ -73,6 +73,9 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
"owner group UUID, and whether the group is visible to all")
|
||||
private boolean verboseOutput;
|
||||
|
||||
@Option(name = "-m", metaVar = "MATCH", usage = "match group substring")
|
||||
private String matchSubstring;
|
||||
|
||||
@Inject
|
||||
protected ListGroups(final GroupCache groupCache,
|
||||
final VisibleGroups.Factory visibleGroupsFactory,
|
||||
@@ -112,6 +115,7 @@ public class ListGroups implements RestReadView<TopLevelResource> {
|
||||
final VisibleGroups visibleGroups = visibleGroupsFactory.create();
|
||||
visibleGroups.setOnlyVisibleToAll(visibleToAll);
|
||||
visibleGroups.setGroupType(groupType);
|
||||
visibleGroups.setMatch(matchSubstring);
|
||||
final List<AccountGroup> groupList;
|
||||
if (!projects.isEmpty()) {
|
||||
groupList = visibleGroups.get(projects);
|
||||
|
||||
Reference in New Issue
Block a user