Show the list of groups the user owns and can manage
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -16,6 +16,7 @@ package com.google.gerrit.client;
|
|||||||
|
|
||||||
import com.google.gerrit.client.account.AccountSettings;
|
import com.google.gerrit.client.account.AccountSettings;
|
||||||
import com.google.gerrit.client.admin.AccountGroupScreen;
|
import com.google.gerrit.client.admin.AccountGroupScreen;
|
||||||
|
import com.google.gerrit.client.admin.GroupListScreen;
|
||||||
import com.google.gerrit.client.changes.AccountDashboardScreen;
|
import com.google.gerrit.client.changes.AccountDashboardScreen;
|
||||||
import com.google.gerrit.client.changes.ChangeScreen;
|
import com.google.gerrit.client.changes.ChangeScreen;
|
||||||
import com.google.gerrit.client.changes.MineStarredScreen;
|
import com.google.gerrit.client.changes.MineStarredScreen;
|
||||||
@@ -75,6 +76,10 @@ public class Link implements HistoryListener {
|
|||||||
return "patch," + type + "," + id.toString();
|
return "patch," + type + "," + id.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String toAccountGroup(final AccountGroup.Id id) {
|
||||||
|
return "admin,group," + id.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public void onHistoryChanged(final String token) {
|
public void onHistoryChanged(final String token) {
|
||||||
Screen s;
|
Screen s;
|
||||||
try {
|
try {
|
||||||
@@ -110,13 +115,15 @@ public class Link implements HistoryListener {
|
|||||||
return new MineStarredScreen();
|
return new MineStarredScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
p = "patch,sidebyside,";
|
if (token.startsWith("patch,")) {
|
||||||
if (token.startsWith(p))
|
p = "patch,sidebyside,";
|
||||||
return new PatchSideBySideScreen(Patch.Key.parse(skip(p, token)));
|
if (token.startsWith(p))
|
||||||
|
return new PatchSideBySideScreen(Patch.Key.parse(skip(p, token)));
|
||||||
|
|
||||||
p = "patch,unified,";
|
p = "patch,unified,";
|
||||||
if (token.startsWith(p))
|
if (token.startsWith(p))
|
||||||
return new PatchUnifiedScreen(Patch.Key.parse(skip(p, token)));
|
return new PatchUnifiedScreen(Patch.Key.parse(skip(p, token)));
|
||||||
|
}
|
||||||
|
|
||||||
p = "change,";
|
p = "change,";
|
||||||
if (token.startsWith(p))
|
if (token.startsWith(p))
|
||||||
@@ -126,9 +133,15 @@ public class Link implements HistoryListener {
|
|||||||
if (token.startsWith(p))
|
if (token.startsWith(p))
|
||||||
return new AccountDashboardScreen(Account.Id.parse(skip(p, token)));
|
return new AccountDashboardScreen(Account.Id.parse(skip(p, token)));
|
||||||
|
|
||||||
p = "admin,group,";
|
if (token.startsWith("admin,")) {
|
||||||
if (token.startsWith(p))
|
p = "admin,group,";
|
||||||
return new AccountGroupScreen(AccountGroup.Id.parse(skip(p, token)));
|
if (token.startsWith(p))
|
||||||
|
return new AccountGroupScreen(AccountGroup.Id.parse(skip(p, token)));
|
||||||
|
|
||||||
|
if (ADMIN_GROUPS.equals(token)) {
|
||||||
|
return new GroupListScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,4 +30,8 @@ public interface AdminConstants extends Constants {
|
|||||||
String columnMember();
|
String columnMember();
|
||||||
String columnEmailAddress();
|
String columnEmailAddress();
|
||||||
String columnOwner();
|
String columnOwner();
|
||||||
|
String columnGroupName();
|
||||||
|
String columnGroupDescription();
|
||||||
|
|
||||||
|
String groupListTitle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,3 +11,7 @@ headingMembers = Members
|
|||||||
columnMember = Member
|
columnMember = Member
|
||||||
columnEmailAddress = Email Address
|
columnEmailAddress = Email Address
|
||||||
columnOwner = Owner
|
columnOwner = Owner
|
||||||
|
columnGroupName = Name
|
||||||
|
columnGroupDescription = Description
|
||||||
|
|
||||||
|
groupListTitle = Groups
|
||||||
|
|||||||
@@ -21,9 +21,13 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
|||||||
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
||||||
import com.google.gwtjsonrpc.client.VoidResult;
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public interface GroupAdminService extends RemoteJsonService {
|
public interface GroupAdminService extends RemoteJsonService {
|
||||||
|
@SignInRequired
|
||||||
|
void ownedGroups(AsyncCallback<List<AccountGroup>> callback);
|
||||||
|
|
||||||
@SignInRequired
|
@SignInRequired
|
||||||
void groupDetail(AccountGroup.Id groupId,
|
void groupDetail(AccountGroup.Id groupId,
|
||||||
AsyncCallback<AccountGroupDetail> callback);
|
AsyncCallback<AccountGroupDetail> callback);
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ import com.google.gwtjsonrpc.client.VoidResult;
|
|||||||
import com.google.gwtorm.client.OrmException;
|
import com.google.gwtorm.client.OrmException;
|
||||||
import com.google.gwtorm.client.SchemaFactory;
|
import com.google.gwtorm.client.SchemaFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class GroupAdminServiceImpl extends BaseServiceImplementation implements
|
public class GroupAdminServiceImpl extends BaseServiceImplementation implements
|
||||||
@@ -38,6 +41,27 @@ public class GroupAdminServiceImpl extends BaseServiceImplementation implements
|
|||||||
super(rdf);
|
super(rdf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ownedGroups(final AsyncCallback<List<AccountGroup>> callback) {
|
||||||
|
run(callback, new Action<List<AccountGroup>>() {
|
||||||
|
public List<AccountGroup> run(ReviewDb db) throws OrmException {
|
||||||
|
final List<AccountGroup> result;
|
||||||
|
if (amAdmin(db)) {
|
||||||
|
result = db.accountGroups().all().toList();
|
||||||
|
} else {
|
||||||
|
final Set<AccountGroup.Id> mine = myOwnedGroups(db);
|
||||||
|
result =
|
||||||
|
new ArrayList<AccountGroup>(db.accountGroups().get(mine).toList());
|
||||||
|
Collections.sort(result, new Comparator<AccountGroup>() {
|
||||||
|
public int compare(final AccountGroup a, final AccountGroup b) {
|
||||||
|
return a.getName().compareTo(b.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void groupDetail(final AccountGroup.Id groupId,
|
public void groupDetail(final AccountGroup.Id groupId,
|
||||||
final AsyncCallback<AccountGroupDetail> callback) {
|
final AsyncCallback<AccountGroupDetail> callback) {
|
||||||
run(callback, new Action<AccountGroupDetail>() {
|
run(callback, new Action<AccountGroupDetail>() {
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
// Copyright 2008 Google Inc.
|
||||||
|
//
|
||||||
|
// 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.admin;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.Link;
|
||||||
|
import com.google.gerrit.client.reviewdb.AccountGroup;
|
||||||
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
|
import com.google.gerrit.client.ui.AccountScreen;
|
||||||
|
import com.google.gerrit.client.ui.FancyFlexTable;
|
||||||
|
import com.google.gwt.user.client.History;
|
||||||
|
import com.google.gwt.user.client.ui.Hyperlink;
|
||||||
|
import com.google.gwt.user.client.ui.SourcesTableEvents;
|
||||||
|
import com.google.gwt.user.client.ui.TableListener;
|
||||||
|
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GroupListScreen extends AccountScreen {
|
||||||
|
private GroupTable groups;
|
||||||
|
|
||||||
|
public GroupListScreen() {
|
||||||
|
super(Util.C.groupListTitle());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getScreenCacheToken() {
|
||||||
|
return getClass();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoad() {
|
||||||
|
if (groups == null) {
|
||||||
|
initUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.GROUP_SVC.ownedGroups(new GerritCallback<List<AccountGroup>>() {
|
||||||
|
public void onSuccess(final List<AccountGroup> result) {
|
||||||
|
if (isAttached()) {
|
||||||
|
groups.display(result);
|
||||||
|
groups.finishDisplay(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initUI() {
|
||||||
|
groups = new GroupTable();
|
||||||
|
groups.setSavePointerId(Link.ADMIN_GROUPS);
|
||||||
|
add(groups);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GroupTable extends FancyFlexTable<AccountGroup> {
|
||||||
|
GroupTable() {
|
||||||
|
table.setText(0, 1, Util.C.columnGroupName());
|
||||||
|
table.setText(0, 2, Util.C.columnGroupDescription());
|
||||||
|
table.addTableListener(new TableListener() {
|
||||||
|
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
|
||||||
|
if (cell != 1 && getRowItem(row) != null) {
|
||||||
|
movePointerTo(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final FlexCellFormatter fmt = table.getFlexCellFormatter();
|
||||||
|
fmt.addStyleName(0, 1, S_DATA_HEADER);
|
||||||
|
fmt.addStyleName(0, 2, S_DATA_HEADER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object getRowItemKey(final AccountGroup item) {
|
||||||
|
return item.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onOpenItem(final AccountGroup item) {
|
||||||
|
History.newItem(Link.toAccountGroup(item.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void display(final List<AccountGroup> result) {
|
||||||
|
while (1 < table.getRowCount())
|
||||||
|
table.removeRow(table.getRowCount() - 1);
|
||||||
|
|
||||||
|
for (final AccountGroup k : result) {
|
||||||
|
final int row = table.getRowCount();
|
||||||
|
table.insertRow(row);
|
||||||
|
populate(row, k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void populate(final int row, final AccountGroup k) {
|
||||||
|
table.setWidget(row, 1, new Hyperlink(k.getName(), Link.toAccountGroup(k
|
||||||
|
.getId())));
|
||||||
|
table.setText(row, 2, k.getDescription());
|
||||||
|
|
||||||
|
final FlexCellFormatter fmt = table.getFlexCellFormatter();
|
||||||
|
fmt.addStyleName(row, 1, S_DATA_CELL);
|
||||||
|
fmt.addStyleName(row, 2, S_DATA_CELL);
|
||||||
|
|
||||||
|
setRowItem(row, k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,8 @@ package com.google.gerrit.client.reviewdb;
|
|||||||
import com.google.gwtorm.client.Access;
|
import com.google.gwtorm.client.Access;
|
||||||
import com.google.gwtorm.client.OrmException;
|
import com.google.gwtorm.client.OrmException;
|
||||||
import com.google.gwtorm.client.PrimaryKey;
|
import com.google.gwtorm.client.PrimaryKey;
|
||||||
|
import com.google.gwtorm.client.Query;
|
||||||
|
import com.google.gwtorm.client.ResultSet;
|
||||||
import com.google.gwtorm.client.SecondaryKey;
|
import com.google.gwtorm.client.SecondaryKey;
|
||||||
|
|
||||||
public interface AccountGroupAccess extends
|
public interface AccountGroupAccess extends
|
||||||
@@ -26,4 +28,7 @@ public interface AccountGroupAccess extends
|
|||||||
|
|
||||||
@SecondaryKey("name")
|
@SecondaryKey("name")
|
||||||
AccountGroup get(AccountGroup.NameKey name) throws OrmException;
|
AccountGroup get(AccountGroup.NameKey name) throws OrmException;
|
||||||
|
|
||||||
|
@Query("ORDER BY name")
|
||||||
|
ResultSet<AccountGroup> all() throws OrmException;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user