REST API /projects/
Instead of using the JSON-RPC interface, use the new standard REST interface for loading the list of projects. This shares the backend implementation with the SSH `gerrit ls-projects` command, and will be the long-term supported interface to talk to Gerrit. Change-Id: If538bbc87410a36ed030721ef6ccda23409d287e
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.client.account;
|
package com.google.gerrit.client.account;
|
||||||
|
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.projects.ProjectMap;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||||
import com.google.gerrit.client.ui.HintTextBox;
|
import com.google.gerrit.client.ui.HintTextBox;
|
||||||
@@ -22,7 +23,6 @@ import com.google.gerrit.client.ui.ProjectNameSuggestOracle;
|
|||||||
import com.google.gerrit.client.ui.ProjectsTable;
|
import com.google.gerrit.client.ui.ProjectsTable;
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.common.data.AccountProjectWatchInfo;
|
import com.google.gerrit.common.data.AccountProjectWatchInfo;
|
||||||
import com.google.gerrit.common.data.ProjectList;
|
|
||||||
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;
|
||||||
import com.google.gwt.event.dom.client.KeyCodes;
|
import com.google.gwt.event.dom.client.KeyCodes;
|
||||||
@@ -226,14 +226,14 @@ public class MyWatchedProjectsScreen extends SettingsScreen implements
|
|||||||
|
|
||||||
// prevent user input from being overwritten by simply poping up
|
// prevent user input from being overwritten by simply poping up
|
||||||
if (! popingUp || "".equals(nameBox.getText()) ) {
|
if (! popingUp || "".equals(nameBox.getText()) ) {
|
||||||
nameBox.setText(getRowItem(row).getName());
|
nameBox.setText(getRowItem(row).name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onOpenRow(final int row) {
|
protected void onOpenRow(final int row) {
|
||||||
super.onOpenRow(row);
|
super.onOpenRow(row);
|
||||||
nameBox.setText(getRowItem(row).getName());
|
nameBox.setText(getRowItem(row).name());
|
||||||
doAddNew();
|
doAddNew();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -361,11 +361,10 @@ public class MyWatchedProjectsScreen extends SettingsScreen implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void populateProjects() {
|
protected void populateProjects() {
|
||||||
Util.PROJECT_SVC.visibleProjects(
|
ProjectMap.all(new GerritCallback<ProjectMap>() {
|
||||||
new GerritCallback<ProjectList>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final ProjectList result) {
|
public void onSuccess(final ProjectMap result) {
|
||||||
projectsTab.display(result.getProjects());
|
projectsTab.display(result);
|
||||||
if (firstPopupLoad) { // Display was delayed until table was loaded
|
if (firstPopupLoad) { // Display was delayed until table was loaded
|
||||||
firstPopupLoad = false;
|
firstPopupLoad = false;
|
||||||
displayPopup();
|
displayPopup();
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ package com.google.gerrit.client.admin;
|
|||||||
import com.google.gerrit.client.Dispatcher;
|
import com.google.gerrit.client.Dispatcher;
|
||||||
import com.google.gerrit.client.ErrorDialog;
|
import com.google.gerrit.client.ErrorDialog;
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.projects.ProjectInfo;
|
||||||
|
import com.google.gerrit.client.projects.ProjectMap;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
import com.google.gerrit.client.ui.HintTextBox;
|
import com.google.gerrit.client.ui.HintTextBox;
|
||||||
import com.google.gerrit.client.ui.ProjectNameSuggestOracle;
|
import com.google.gerrit.client.ui.ProjectNameSuggestOracle;
|
||||||
@@ -38,8 +40,6 @@ import com.google.gwt.user.client.ui.VerticalPanel;
|
|||||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||||
import com.google.gwtjsonrpc.common.VoidResult;
|
import com.google.gwtjsonrpc.common.VoidResult;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CreateProjectScreen extends Screen {
|
public class CreateProjectScreen extends Screen {
|
||||||
private NpTextBox project;
|
private NpTextBox project;
|
||||||
private Button create;
|
private Button create;
|
||||||
@@ -127,31 +127,30 @@ public class CreateProjectScreen extends Screen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void populate(final int row, final Project k) {
|
protected void populate(final int row, final ProjectInfo k) {
|
||||||
final Anchor projectLink = new Anchor(k.getName());
|
final Anchor projectLink = new Anchor(k.name());
|
||||||
projectLink.addClickHandler(new ClickHandler() {
|
projectLink.addClickHandler(new ClickHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(ClickEvent event) {
|
public void onClick(ClickEvent event) {
|
||||||
sugestParent.setText(getRowItem(row).getName());
|
sugestParent.setText(getRowItem(row).name());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
table.setWidget(row, 1, projectLink);
|
table.setWidget(row, 1, projectLink);
|
||||||
table.setText(row, 2, k.getDescription());
|
table.setText(row, 2, k.description());
|
||||||
|
|
||||||
setRowItem(row, k);
|
setRowItem(row, k);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
suggestedParentsTab.setVisible(false);
|
suggestedParentsTab.setVisible(false);
|
||||||
|
|
||||||
Util.PROJECT_SVC
|
ProjectMap.permissions(new GerritCallback<ProjectMap>() {
|
||||||
.suggestParentCandidates(new GerritCallback<List<Project>>() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<Project> result) {
|
public void onSuccess(ProjectMap list) {
|
||||||
if (result != null && !result.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
suggestedParentsTab.setVisible(true);
|
suggestedParentsTab.setVisible(true);
|
||||||
suggestedParentsTab.display(result);
|
suggestedParentsTab.display(list);
|
||||||
suggestedParentsTab.finishDisplay();
|
suggestedParentsTab.finishDisplay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ import com.google.gerrit.client.Dispatcher;
|
|||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
import com.google.gerrit.client.account.AccountCapabilities;
|
import com.google.gerrit.client.account.AccountCapabilities;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
|
import com.google.gerrit.client.projects.ProjectInfo;
|
||||||
|
import com.google.gerrit.client.projects.ProjectMap;
|
||||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||||
import com.google.gerrit.client.ui.Hyperlink;
|
import com.google.gerrit.client.ui.Hyperlink;
|
||||||
import com.google.gerrit.client.ui.ProjectsTable;
|
import com.google.gerrit.client.ui.ProjectsTable;
|
||||||
import com.google.gerrit.client.ui.Screen;
|
import com.google.gerrit.client.ui.Screen;
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.common.data.ProjectList;
|
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
|
||||||
import com.google.gwt.user.client.History;
|
import com.google.gwt.user.client.History;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
@@ -44,10 +44,10 @@ public class ProjectListScreen extends Screen {
|
|||||||
createProjectLinkPanel.setVisible(ac.canPerform(CREATE_PROJECT));
|
createProjectLinkPanel.setVisible(ac.canPerform(CREATE_PROJECT));
|
||||||
}
|
}
|
||||||
}, CREATE_PROJECT);
|
}, CREATE_PROJECT);
|
||||||
Util.PROJECT_SVC.visibleProjects(new ScreenLoadCallback<ProjectList>(this) {
|
ProjectMap.all(new ScreenLoadCallback<ProjectMap>(this) {
|
||||||
@Override
|
@Override
|
||||||
protected void preDisplay(final ProjectList result) {
|
protected void preDisplay(final ProjectMap result) {
|
||||||
projects.display(result.getProjects());
|
projects.display(result);
|
||||||
projects.finishDisplay();
|
projects.finishDisplay();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -71,14 +71,14 @@ public class ProjectListScreen extends Screen {
|
|||||||
History.newItem(link(getRowItem(row)));
|
History.newItem(link(getRowItem(row)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String link(final Project item) {
|
private String link(final ProjectInfo item) {
|
||||||
return Dispatcher.toProjectAdmin(item.getNameKey(), ProjectScreen.INFO);
|
return Dispatcher.toProjectAdmin(item.name_key(), ProjectScreen.INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void populate(final int row, final Project k) {
|
protected void populate(final int row, final ProjectInfo k) {
|
||||||
table.setWidget(row, 1, new Hyperlink(k.getName(), link(k)));
|
table.setWidget(row, 1, new Hyperlink(k.name(), link(k)));
|
||||||
table.setText(row, 2, k.getDescription());
|
table.setText(row, 2, k.description());
|
||||||
|
|
||||||
setRowItem(row, k);
|
setRowItem(row, k);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2012 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.projects;
|
||||||
|
|
||||||
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
|
import com.google.gwt.core.client.JavaScriptObject;
|
||||||
|
|
||||||
|
public class ProjectInfo extends JavaScriptObject {
|
||||||
|
public final Project.NameKey name_key() {
|
||||||
|
return new Project.NameKey(name());
|
||||||
|
}
|
||||||
|
|
||||||
|
public final native String name() /*-{ return this.name; }-*/;
|
||||||
|
public final native String description() /*-{ return this.description; }-*/;
|
||||||
|
|
||||||
|
protected ProjectInfo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (C) 2012 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.projects;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.rpc.NativeMap;
|
||||||
|
import com.google.gerrit.client.rpc.RestApi;
|
||||||
|
import com.google.gwtjsonrpc.common.AsyncCallback;
|
||||||
|
|
||||||
|
/** Projects available from {@code /projects/}. */
|
||||||
|
public class ProjectMap extends NativeMap<ProjectInfo> {
|
||||||
|
public static void all(AsyncCallback<ProjectMap> callback) {
|
||||||
|
new RestApi("/projects/")
|
||||||
|
.addParameterRaw("type", "ALL")
|
||||||
|
.addParameterTrue("all")
|
||||||
|
.addParameterTrue("d") // description
|
||||||
|
.send(NativeMap.copyKeysIntoChildren(callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void permissions(AsyncCallback<ProjectMap> callback) {
|
||||||
|
new RestApi("/projects/")
|
||||||
|
.addParameterRaw("type", "PERMISSIONS")
|
||||||
|
.addParameterTrue("all")
|
||||||
|
.addParameterTrue("d") // description
|
||||||
|
.send(NativeMap.copyKeysIntoChildren(callback));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ProjectMap() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,16 +15,19 @@
|
|||||||
package com.google.gerrit.client.ui;
|
package com.google.gerrit.client.ui;
|
||||||
|
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.client.projects.ProjectInfo;
|
||||||
|
import com.google.gerrit.client.projects.ProjectMap;
|
||||||
import com.google.gwt.event.dom.client.KeyCodes;
|
import com.google.gwt.event.dom.client.KeyCodes;
|
||||||
import com.google.gwt.user.client.DOM;
|
import com.google.gwt.user.client.DOM;
|
||||||
import com.google.gwt.user.client.Element;
|
import com.google.gwt.user.client.Element;
|
||||||
import com.google.gwt.user.client.Event;
|
import com.google.gwt.user.client.Event;
|
||||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ProjectsTable extends NavigationTable<Project> {
|
public class ProjectsTable extends NavigationTable<ProjectInfo> {
|
||||||
|
|
||||||
public ProjectsTable() {
|
public ProjectsTable() {
|
||||||
keysNavigation.add(new PrevKeyCommand(0, 'k', Util.C.projectListPrev()));
|
keysNavigation.add(new PrevKeyCommand(0, 'k', Util.C.projectListPrev()));
|
||||||
@@ -41,6 +44,7 @@ public class ProjectsTable extends NavigationTable<Project> {
|
|||||||
fmt.addStyleName(0, 2, Gerrit.RESOURCES.css().dataHeader());
|
fmt.addStyleName(0, 2, Gerrit.RESOURCES.css().dataHeader());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected MyFlexTable createFlexTable() {
|
protected MyFlexTable createFlexTable() {
|
||||||
MyFlexTable table = new MyFlexTable() {
|
MyFlexTable table = new MyFlexTable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -78,8 +82,8 @@ public class ProjectsTable extends NavigationTable<Project> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object getRowItemKey(final Project item) {
|
protected Object getRowItemKey(final ProjectInfo item) {
|
||||||
return item.getNameKey();
|
return item.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -89,17 +93,24 @@ public class ProjectsTable extends NavigationTable<Project> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void display(final List<Project> projects) {
|
public void display(ProjectMap projects) {
|
||||||
while (1 < table.getRowCount())
|
while (1 < table.getRowCount())
|
||||||
table.removeRow(table.getRowCount() - 1);
|
table.removeRow(table.getRowCount() - 1);
|
||||||
|
|
||||||
for (final Project k : projects)
|
List<ProjectInfo> list = projects.values().asList();
|
||||||
insert(table.getRowCount(), k);
|
Collections.sort(list, new Comparator<ProjectInfo>() {
|
||||||
|
@Override
|
||||||
|
public int compare(ProjectInfo a, ProjectInfo b) {
|
||||||
|
return a.name().compareTo(b.name());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for(ProjectInfo p : list)
|
||||||
|
insert(table.getRowCount(), p);
|
||||||
|
|
||||||
finishDisplay();
|
finishDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void insert(final int row, final Project k) {
|
protected void insert(final int row, final ProjectInfo k) {
|
||||||
table.insertRow(row);
|
table.insertRow(row);
|
||||||
|
|
||||||
applyDataRowStyle(row);
|
applyDataRowStyle(row);
|
||||||
@@ -112,9 +123,9 @@ public class ProjectsTable extends NavigationTable<Project> {
|
|||||||
populate(row, k);
|
populate(row, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void populate(final int row, final Project k) {
|
protected void populate(final int row, final ProjectInfo k) {
|
||||||
table.setText(row, 1, k.getName());
|
table.setText(row, 1, k.name());
|
||||||
table.setText(row, 2, k.getDescription());
|
table.setText(row, 2, k.description());
|
||||||
|
|
||||||
setRowItem(row, k);
|
setRowItem(row, k);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user