Merge "Adapt ProjectInfoScreen to use the REST API"

This commit is contained in:
David Pursehouse
2013-08-22 04:35:13 +00:00
committed by Gerrit Code Review
4 changed files with 242 additions and 89 deletions

View File

@@ -18,6 +18,7 @@ import com.google.gwt.core.client.JavaScriptObject;
public class ProjectAccessInfo extends JavaScriptObject {
public final native boolean canAddRefs() /*-{ return this.can_add ? true : false; }-*/;
public final native boolean isOwner() /*-{ return this.is_owner ? true : false; }-*/;
protected ProjectAccessInfo() {
}

View File

@@ -15,14 +15,18 @@
package com.google.gerrit.client.admin;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.access.AccessMap;
import com.google.gerrit.client.access.ProjectAccessInfo;
import com.google.gerrit.client.download.DownloadPanel;
import com.google.gerrit.client.projects.ConfigInfo;
import com.google.gerrit.client.projects.ConfigInfo.InheritedBooleanInfo;
import com.google.gerrit.client.projects.ProjectApi;
import com.google.gerrit.client.rpc.CallbackGroup;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.ScreenLoadCallback;
import com.google.gerrit.client.ui.OnEditEnabler;
import com.google.gerrit.client.ui.SmallHeading;
import com.google.gerrit.common.data.ProjectDetail;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
import com.google.gerrit.reviewdb.client.InheritedBoolean;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
@@ -39,9 +43,8 @@ import com.google.gwtexpui.globalkey.client.NpTextArea;
import com.google.gwtexpui.globalkey.client.NpTextBox;
public class ProjectInfoScreen extends ProjectScreen {
private String projectName;
private Project project;
private ProjectDetail projectDetail;
private boolean isOwner;
private Project.NameKey parent;
private LabeledWidgetsGrid grid;
@@ -63,7 +66,6 @@ public class ProjectInfoScreen extends ProjectScreen {
public ProjectInfoScreen(final Project.NameKey toShow) {
super(toShow);
projectName = toShow.get();
}
@Override
@@ -78,7 +80,7 @@ public class ProjectInfoScreen extends ProjectScreen {
}
});
add(new ProjectDownloadPanel(projectName, true));
add(new ProjectDownloadPanel(getProjectKey().get(), true));
initDescription();
grid = new LabeledWidgetsGrid();
@@ -91,44 +93,49 @@ public class ProjectInfoScreen extends ProjectScreen {
@Override
protected void onLoad() {
super.onLoad();
Util.PROJECT_SVC.projectDetail(getProjectKey(),
new ScreenLoadCallback<ProjectDetail>(this) {
public void preDisplay(final ProjectDetail result) {
enableForm(result.canModifyAgreements,
result.canModifyDescription, result.canModifyMergeType, result.canModifyState,
result.canModifyMaxObjectSizeLimit);
saveProject.setVisible(
result.canModifyAgreements ||
result.canModifyDescription ||
result.canModifyMergeType ||
result.canModifyState);
Project.NameKey project = getProjectKey();
CallbackGroup cbg = new CallbackGroup();
AccessMap.get(project,
cbg.add(new GerritCallback<ProjectAccessInfo>() {
@Override
public void onSuccess(ProjectAccessInfo result) {
isOwner = result.isOwner();
enableForm();
saveProject.setVisible(isOwner);
}
}));
ProjectApi.getParent(project,
cbg.add(new GerritCallback<Project.NameKey>() {
@Override
public void onSuccess(Project.NameKey result) {
parent = result;
}
}));
ProjectApi.getConfig(project,
cbg.addFinal(new ScreenLoadCallback<ConfigInfo>(this) {
@Override
public void preDisplay(ConfigInfo result) {
display(result);
}
});
}));
savedPanel = INFO;
}
private void enableForm() {
if (projectDetail != null) {
enableForm(projectDetail.canModifyAgreements,
projectDetail.canModifyDescription,
projectDetail.canModifyMergeType,
projectDetail.canModifyState,
projectDetail.canModifyMaxObjectSizeLimit);
}
enableForm(isOwner);
}
private void enableForm(final boolean canModifyAgreements,
final boolean canModifyDescription, final boolean canModifyMergeType,
final boolean canModifyState, final boolean canModifyMaxObjectSizeLimit) {
submitType.setEnabled(canModifyMergeType);
state.setEnabled(canModifyState);
contentMerge.setEnabled(canModifyMergeType);
descTxt.setEnabled(canModifyDescription);
contributorAgreements.setEnabled(canModifyAgreements);
signedOffBy.setEnabled(canModifyAgreements);
requireChangeID.setEnabled(canModifyMergeType);
maxObjectSizeLimit.setEnabled(canModifyMaxObjectSizeLimit);
private void enableForm(boolean isOwner) {
submitType.setEnabled(isOwner);
state.setEnabled(isOwner);
contentMerge.setEnabled(isOwner);
descTxt.setEnabled(isOwner);
contributorAgreements.setEnabled(isOwner);
signedOffBy.setEnabled(isOwner);
requireChangeID.setEnabled(isOwner);
maxObjectSizeLimit.setEnabled(isOwner);
}
private void initDescription() {
@@ -199,9 +206,9 @@ public class ProjectInfoScreen extends ProjectScreen {
if (SubmitType.FAST_FORWARD_ONLY.equals(Project.SubmitType
.valueOf(submitType.getValue(submitType.getSelectedIndex())))) {
contentMerge.setEnabled(false);
final InheritedBoolean inheritedBoolean = new InheritedBoolean();
inheritedBoolean.setValue(InheritableBoolean.FALSE);
setBool(contentMerge, inheritedBoolean);
InheritedBooleanInfo b = InheritedBooleanInfo.create();
b.setConfiguredValue(InheritableBoolean.FALSE);
setBool(contentMerge, b);
} else {
contentMerge.setEnabled(submitType.isEnabled());
}
@@ -246,18 +253,18 @@ public class ProjectInfoScreen extends ProjectScreen {
}
}
private void setBool(ListBox box, InheritedBoolean inheritedBoolean) {
private void setBool(ListBox box, InheritedBooleanInfo inheritedBoolean) {
int inheritedIndex = -1;
for (int i = 0; i < box.getItemCount(); i++) {
if (box.getValue(i).startsWith(InheritableBoolean.INHERIT.name())) {
inheritedIndex = i;
}
if (box.getValue(i).startsWith(inheritedBoolean.value.name())) {
if (box.getValue(i).startsWith(inheritedBoolean.configured_value().name())) {
box.setSelectedIndex(i);
}
}
if (inheritedIndex >= 0) {
if (project.getParent(Gerrit.getConfig().getWildProject()) == null) {
if (parent.equals(Gerrit.getConfig().getWildProject())) {
if (box.getSelectedIndex() == inheritedIndex) {
for (int i = 0; i < box.getItemCount(); i++) {
if (box.getValue(i).equals(InheritableBoolean.FALSE.name())) {
@@ -269,7 +276,7 @@ public class ProjectInfoScreen extends ProjectScreen {
box.removeItem(inheritedIndex);
} else {
box.setItemText(inheritedIndex, InheritableBoolean.INHERIT.name() + " ("
+ inheritedBoolean.inheritedValue + ")");
+ inheritedBoolean.inherited_value() + ")");
}
}
}
@@ -286,53 +293,38 @@ public class ProjectInfoScreen extends ProjectScreen {
return InheritableBoolean.INHERIT;
}
void display(final ProjectDetail result) {
project = result.project;
descTxt.setText(project.getDescription());
setBool(contributorAgreements, result.useContributorAgreements);
setBool(signedOffBy, result.useSignedOffBy);
setBool(contentMerge, result.useContentMerge);
setBool(requireChangeID, result.requireChangeID);
setSubmitType(project.getSubmitType());
setState(project.getState());
maxObjectSizeLimit.setText(project.getMaxObjectSizeLimit());
void display(ConfigInfo result) {
descTxt.setText(result.description());
setBool(contributorAgreements, result.use_contributor_agreements());
setBool(signedOffBy, result.use_signed_off_by());
setBool(contentMerge, result.use_content_merge());
setBool(requireChangeID, result.require_change_id());
setSubmitType(result.submit_type());
setState(result.state());
maxObjectSizeLimit.setText(result.max_object_size_limit().configured_value());
saveProject.setEnabled(false);
projectDetail = result;
}
private void doSave() {
project.setDescription(descTxt.getText().trim());
project.setUseContributorAgreements(getBool(contributorAgreements));
project.setUseSignedOffBy(getBool(signedOffBy));
project.setUseContentMerge(getBool(contentMerge));
project.setRequireChangeID(getBool(requireChangeID));
project.setMaxObjectSizeLimit(maxObjectSizeLimit.getText().trim());
if (submitType.getSelectedIndex() >= 0) {
project.setSubmitType(Project.SubmitType.valueOf(submitType
.getValue(submitType.getSelectedIndex())));
}
if (state.getSelectedIndex() >= 0) {
project.setState(Project.State.valueOf(state
.getValue(state.getSelectedIndex())));
}
enableForm(false, false, false, false, false);
Util.PROJECT_SVC.changeProjectSettings(project,
new GerritCallback<ProjectDetail>() {
public void onSuccess(final ProjectDetail result) {
enableForm(result.canModifyAgreements,
result.canModifyDescription, result.canModifyMergeType, result.canModifyState,
result.canModifyMaxObjectSizeLimit);
enableForm(false);
ProjectApi.setConfig(getProjectKey(), descTxt.getText().trim(),
getBool(contributorAgreements), getBool(contentMerge),
getBool(signedOffBy), getBool(requireChangeID),
maxObjectSizeLimit.getText().trim(),
Project.SubmitType.valueOf(submitType.getValue(submitType.getSelectedIndex())),
Project.State.valueOf(state.getValue(state.getSelectedIndex())),
new GerritCallback<ConfigInfo>() {
@Override
public void onSuccess(ConfigInfo result) {
enableForm();
display(result);
}
@Override
public void onFailure(Throwable caught) {
super.onFailure(caught);
enableForm();
super.onFailure(caught);
}
});
}

View File

@@ -15,7 +15,9 @@
package com.google.gerrit.client.projects;
import com.google.gerrit.client.rpc.NativeMap;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwtexpui.safehtml.client.FindReplace;
@@ -26,6 +28,9 @@ import java.util.ArrayList;
import java.util.List;
public class ConfigInfo extends JavaScriptObject {
public final native String description()
/*-{ return this.description }-*/;
public final native InheritedBooleanInfo require_change_id()
/*-{ return this.require_change_id; }-*/;
@@ -38,6 +43,24 @@ public class ConfigInfo extends JavaScriptObject {
public final native InheritedBooleanInfo use_signed_off_by()
/*-{ return this.use_signed_off_by; }-*/;
public final SubmitType submit_type() {
return SubmitType.valueOf(submit_typeRaw());
}
private final native String submit_typeRaw()
/*-{ return this.submit_type }-*/;
public final Project.State state() {
if (stateRaw() == null) {
return Project.State.ACTIVE;
}
return Project.State.valueOf(stateRaw());
}
private final native String stateRaw()
/*-{ return this.state }-*/;
public final native MaxObjectSizeLimitInfo max_object_size_limit()
/*-{ return this.max_object_size_limit; }-*/;
private final native NativeMap<CommentLinkInfo> commentlinks0()
/*-{ return this.commentlinks; }-*/;
final List<FindReplace> commentlinks() {
@@ -75,6 +98,10 @@ public class ConfigInfo extends JavaScriptObject {
}
public static class InheritedBooleanInfo extends JavaScriptObject {
public static InheritedBooleanInfo create() {
return (InheritedBooleanInfo) createObject();
}
public final native boolean value()
/*-{ return this.value ? true : false; }-*/;
@@ -87,7 +114,22 @@ public class ConfigInfo extends JavaScriptObject {
private final native String configured_valueRaw()
/*-{ return this.configured_value }-*/;
public final void setConfiguredValue(InheritableBoolean v) {
setConfiguredValueRaw(v.name());
}
public final native void setConfiguredValueRaw(String v)
/*-{ if(v)this.configured_value=v; }-*/;
protected InheritedBooleanInfo() {
}
}
public static class MaxObjectSizeLimitInfo extends JavaScriptObject {
public final native String value() /*-{ return this.value; }-*/;
public final native String inherited_value() /*-{ return this.inherited_value; }-*/;
public final native String configured_value() /*-{ return this.configured_value }-*/;
protected MaxObjectSizeLimitInfo() {
}
}
}

View File

@@ -15,8 +15,11 @@ package com.google.gerrit.client.projects;
import com.google.gerrit.client.VoidResult;
import com.google.gerrit.client.rpc.CallbackGroup;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.rpc.RestApi;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
import com.google.gerrit.reviewdb.client.Project.SubmitType;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -38,18 +41,17 @@ public class ProjectApi {
}
/** Create a new branch */
public static void createBranch(Project.NameKey projectName, String ref,
public static void createBranch(Project.NameKey name, String ref,
String revision, AsyncCallback<BranchInfo> cb) {
BranchInput input = BranchInput.create();
input.setRevision(revision);
new RestApi("/projects/").id(projectName.get()).view("branches").id(ref)
.ifNoneMatch().put(input, cb);
project(name).view("branches").id(ref).ifNoneMatch().put(input, cb);
}
/** Retrieve all visible branches of the project */
public static void getBranches(Project.NameKey projectName,
public static void getBranches(Project.NameKey name,
AsyncCallback<JsArray<BranchInfo>> cb) {
new RestApi("/projects/").id(projectName.get()).view("branches").get(cb);
project(name).view("branches").get(cb);
}
/**
@@ -59,11 +61,11 @@ public class ProjectApi {
* callbacks' {@code onFailure} method is invoked. In a failure case it can be
* that still some of the branches were successfully deleted.
*/
public static void deleteBranches(Project.NameKey projectName,
public static void deleteBranches(Project.NameKey name,
Set<String> refs, AsyncCallback<VoidResult> cb) {
CallbackGroup group = new CallbackGroup();
for (String ref : refs) {
new RestApi("/projects/").id(projectName.get()).view("branches").id(ref)
project(name).view("branches").id(ref)
.delete(group.add(cb));
cb = CallbackGroup.emptyCallback();
}
@@ -72,7 +74,61 @@ public class ProjectApi {
public static void getConfig(Project.NameKey name,
AsyncCallback<ConfigInfo> cb) {
new RestApi("/projects/").id(name.get()).view("config").get(cb);
project(name).view("config").get(cb);
}
public static void setConfig(Project.NameKey name, String description,
InheritableBoolean useContributorAgreements,
InheritableBoolean useContentMerge, InheritableBoolean useSignedOffBy,
InheritableBoolean requireChangeId, String maxObjectSizeLimit,
SubmitType submitType, Project.State state, AsyncCallback<ConfigInfo> cb) {
ConfigInput in = ConfigInput.create();
in.setDescription(description);
in.setUseContributorAgreements(useContributorAgreements);
in.setUseContentMerge(useContentMerge);
in.setUseSignedOffBy(useSignedOffBy);
in.setRequireChangeId(requireChangeId);
in.setMaxObjectSizeLimit(maxObjectSizeLimit);
in.setSubmitType(submitType);
in.setState(state);
project(name).view("config").put(in, cb);
}
public static void getParent(Project.NameKey name,
final AsyncCallback<Project.NameKey> cb) {
project(name).view("parent").get(
new AsyncCallback<NativeString>() {
@Override
public void onSuccess(NativeString result) {
cb.onSuccess(new Project.NameKey(result.asString()));
}
@Override
public void onFailure(Throwable caught) {
cb.onFailure(caught);
}
});
}
public static void getDescription(Project.NameKey name,
AsyncCallback<NativeString> cb) {
project(name).view("description").get(cb);
}
public static void setDescription(Project.NameKey name, String description,
AsyncCallback<NativeString> cb) {
RestApi call = project(name).view("description");
if (description != null && !description.isEmpty()) {
DescriptionInput input = DescriptionInput.create();
input.setDescription(description);
call.put(input, cb);
} else {
call.delete(cb);
}
}
private static RestApi project(Project.NameKey name) {
return new RestApi("/projects/").id(name.get());
}
private static class ProjectInput extends JavaScriptObject {
@@ -92,6 +148,57 @@ public class ProjectApi {
final native void setCreateEmptyCommit(boolean cc) /*-{ if(cc)this.create_empty_commit=cc; }-*/;
}
private static class ConfigInput extends JavaScriptObject {
static ConfigInput create() {
return (ConfigInput) createObject();
}
protected ConfigInput() {
}
final native void setDescription(String d)
/*-{ if(d)this.description=d; }-*/;
final void setUseContributorAgreements(InheritableBoolean v) {
setUseContributorAgreementsRaw(v.name());
}
private final native void setUseContributorAgreementsRaw(String v)
/*-{ if(v)this.use_contributor_agreements=v; }-*/;
final void setUseContentMerge(InheritableBoolean v) {
setUseContentMergeRaw(v.name());
}
private final native void setUseContentMergeRaw(String v)
/*-{ if(v)this.use_content_merge=v; }-*/;
final void setUseSignedOffBy(InheritableBoolean v) {
setUseSignedOffByRaw(v.name());
}
private final native void setUseSignedOffByRaw(String v)
/*-{ if(v)this.use_signed_off_by=v; }-*/;
final void setRequireChangeId(InheritableBoolean v) {
setRequireChangeIdRaw(v.name());
}
private final native void setRequireChangeIdRaw(String v)
/*-{ if(v)this.require_change_id=v; }-*/;
final native void setMaxObjectSizeLimit(String l)
/*-{ if(l)this.max_object_size_limit=l; }-*/;
final void setSubmitType(SubmitType t) {
setSubmitTypeRaw(t.name());
}
private final native void setSubmitTypeRaw(String t)
/*-{ if(t)this.submit_type=t; }-*/;
final void setState(Project.State s) {
setStateRaw(s.name());
}
private final native void setStateRaw(String s)
/*-{ if(s)this.state=s; }-*/;
}
private static class BranchInput extends JavaScriptObject {
static BranchInput create() {
return (BranchInput) createObject();
@@ -102,4 +209,15 @@ public class ProjectApi {
final native void setRevision(String r) /*-{ if(r)this.revision=r; }-*/;
}
private static class DescriptionInput extends JavaScriptObject {
static DescriptionInput create() {
return (DescriptionInput) createObject();
}
protected DescriptionInput() {
}
final native void setDescription(String d) /*-{ if(d)this.description=d; }-*/;
}
}