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