Support setting HEAD from WebUI
Project owners can now change HEAD from the ProjectBranchesScreen. Change-Id: I1394312bd9bdead3c71772ba35fd2e0798c04d44 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
@@ -70,6 +70,10 @@ public class PageLinks {
|
|||||||
return "/admin/projects/" + p.get() + ",access";
|
return "/admin/projects/" + p.get() + ",access";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String toProjectBranches(Project.NameKey p) {
|
||||||
|
return "/admin/projects/" + p.get() + ",branches";
|
||||||
|
}
|
||||||
|
|
||||||
public static String toAccountQuery(String fullname, Status status) {
|
public static String toAccountQuery(String fullname, Status status) {
|
||||||
return toChangeQuery(op("owner", fullname) + " " + status(status), TOP);
|
return toChangeQuery(op("owner", fullname) + " " + status(status), TOP);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public interface GerritCss extends CssResource {
|
|||||||
String downloadLinkListCell();
|
String downloadLinkListCell();
|
||||||
String downloadLink_Active();
|
String downloadLink_Active();
|
||||||
String drafts();
|
String drafts();
|
||||||
|
String editHeadButton();
|
||||||
String emptySection();
|
String emptySection();
|
||||||
String errorDialog();
|
String errorDialog();
|
||||||
String errorDialogButtons();
|
String errorDialogButtons();
|
||||||
|
|||||||
@@ -92,6 +92,8 @@ public interface AdminConstants extends Constants {
|
|||||||
String initialRevision();
|
String initialRevision();
|
||||||
String buttonAddBranch();
|
String buttonAddBranch();
|
||||||
String buttonDeleteBranch();
|
String buttonDeleteBranch();
|
||||||
|
String saveHeadButton();
|
||||||
|
String cancelHeadButton();
|
||||||
|
|
||||||
String groupItemHelp();
|
String groupItemHelp();
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ columnBranchRevision = Revision
|
|||||||
initialRevision = Initial Revision
|
initialRevision = Initial Revision
|
||||||
buttonAddBranch = Create Branch
|
buttonAddBranch = Create Branch
|
||||||
buttonDeleteBranch = Delete
|
buttonDeleteBranch = Delete
|
||||||
|
saveHeadButton = Save
|
||||||
|
cancelHeadButton = Cancel
|
||||||
|
|
||||||
groupItemHelp = group
|
groupItemHelp = group
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,13 @@ import com.google.gerrit.client.access.ProjectAccessInfo;
|
|||||||
import com.google.gerrit.client.projects.BranchInfo;
|
import com.google.gerrit.client.projects.BranchInfo;
|
||||||
import com.google.gerrit.client.projects.ProjectApi;
|
import com.google.gerrit.client.projects.ProjectApi;
|
||||||
import com.google.gerrit.client.rpc.GerritCallback;
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
|
import com.google.gerrit.client.rpc.NativeString;
|
||||||
import com.google.gerrit.client.rpc.Natives;
|
import com.google.gerrit.client.rpc.Natives;
|
||||||
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
||||||
import com.google.gerrit.client.ui.FancyFlexTable;
|
import com.google.gerrit.client.ui.FancyFlexTable;
|
||||||
import com.google.gerrit.client.ui.HintTextBox;
|
import com.google.gerrit.client.ui.HintTextBox;
|
||||||
|
import com.google.gerrit.client.ui.OnEditEnabler;
|
||||||
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.reviewdb.client.Project;
|
import com.google.gerrit.reviewdb.client.Project;
|
||||||
import com.google.gwt.core.client.JsArray;
|
import com.google.gwt.core.client.JsArray;
|
||||||
@@ -47,8 +50,11 @@ import com.google.gwt.user.client.ui.CheckBox;
|
|||||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||||
import com.google.gwt.user.client.ui.FlowPanel;
|
import com.google.gwt.user.client.ui.FlowPanel;
|
||||||
import com.google.gwt.user.client.ui.Grid;
|
import com.google.gwt.user.client.ui.Grid;
|
||||||
|
import com.google.gwt.user.client.ui.Image;
|
||||||
|
import com.google.gwt.user.client.ui.InlineLabel;
|
||||||
import com.google.gwt.user.client.ui.TextBox;
|
import com.google.gwt.user.client.ui.TextBox;
|
||||||
import com.google.gwt.user.client.ui.Widget;
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
|
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||||
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
import com.google.gwtexpui.safehtml.client.SafeHtmlBuilder;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -371,7 +377,11 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
|||||||
table.setText(row, 2, k.getShortName());
|
table.setText(row, 2, k.getShortName());
|
||||||
|
|
||||||
if (k.revision() != null) {
|
if (k.revision() != null) {
|
||||||
table.setText(row, 3, k.revision());
|
if ("HEAD".equals(k.getShortName())) {
|
||||||
|
setHeadRevision(row, 3, k.revision());
|
||||||
|
} else {
|
||||||
|
table.setText(row, 3, k.revision());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
table.setText(row, 3, "");
|
table.setText(row, 3, "");
|
||||||
}
|
}
|
||||||
@@ -400,6 +410,92 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
|||||||
setRowItem(row, k);
|
setRowItem(row, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setHeadRevision(final int row, final int column,
|
||||||
|
final String rev) {
|
||||||
|
AccessMap.get(getProjectKey(),
|
||||||
|
new GerritCallback<ProjectAccessInfo>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(ProjectAccessInfo result) {
|
||||||
|
if (result.isOwner()) {
|
||||||
|
table.setWidget(row, column, getHeadRevisionWidget(rev));
|
||||||
|
} else {
|
||||||
|
table.setText(row, 3, rev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Widget getHeadRevisionWidget(final String headRevision) {
|
||||||
|
FlowPanel p = new FlowPanel();
|
||||||
|
final InlineLabel l = new InlineLabel(headRevision);
|
||||||
|
final Image edit = new Image(Gerrit.RESOURCES.edit());
|
||||||
|
edit.addStyleName(Gerrit.RESOURCES.css().editHeadButton());
|
||||||
|
|
||||||
|
final NpTextBox input = new NpTextBox();
|
||||||
|
input.setVisibleLength(35);
|
||||||
|
input.setValue(headRevision);
|
||||||
|
input.setVisible(false);
|
||||||
|
final Button save = new Button();
|
||||||
|
save.setText(Util.C.saveHeadButton());
|
||||||
|
save.setVisible(false);
|
||||||
|
save.setEnabled(false);
|
||||||
|
final Button cancel = new Button();
|
||||||
|
cancel.setText(Util.C.cancelHeadButton());
|
||||||
|
cancel.setVisible(false);
|
||||||
|
|
||||||
|
OnEditEnabler e = new OnEditEnabler(save);
|
||||||
|
e.listenTo(input);
|
||||||
|
|
||||||
|
edit.addClickHandler(new ClickHandler() {
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickEvent event) {
|
||||||
|
l.setVisible(false);
|
||||||
|
edit.setVisible(false);
|
||||||
|
input.setVisible(true);
|
||||||
|
save.setVisible(true);
|
||||||
|
cancel.setVisible(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
save.addClickHandler(new ClickHandler() {
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickEvent event) {
|
||||||
|
save.setEnabled(false);
|
||||||
|
ProjectApi.setHead(getProjectKey(), input.getValue().trim(),
|
||||||
|
new GerritCallback<NativeString>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(NativeString result) {
|
||||||
|
Gerrit.display(PageLinks.toProjectBranches(getProjectKey()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
super.onFailure(caught);
|
||||||
|
save.setEnabled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cancel.addClickHandler(new ClickHandler() {
|
||||||
|
@Override
|
||||||
|
public void onClick(ClickEvent event) {
|
||||||
|
l.setVisible(true);
|
||||||
|
edit.setVisible(true);
|
||||||
|
input.setVisible(false);
|
||||||
|
input.setValue(headRevision);
|
||||||
|
save.setVisible(false);
|
||||||
|
save.setEnabled(false);
|
||||||
|
cancel.setVisible(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
p.add(l);
|
||||||
|
p.add(edit);
|
||||||
|
p.add(input);
|
||||||
|
p.add(save);
|
||||||
|
p.add(cancel);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
boolean hasBranchCanDelete() {
|
boolean hasBranchCanDelete() {
|
||||||
return canDelete;
|
return canDelete;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1571,6 +1571,11 @@ a:hover.downloadLink {
|
|||||||
padding: 2px 6px 1px;
|
padding: 2px 6px 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.editHeadButton {
|
||||||
|
float: right;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
/** PluginListScreen **/
|
/** PluginListScreen **/
|
||||||
.pluginsTable {
|
.pluginsTable {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,6 +136,14 @@ public class ProjectApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setHead(Project.NameKey name, String ref,
|
||||||
|
AsyncCallback<NativeString> cb) {
|
||||||
|
RestApi call = project(name).view("HEAD");
|
||||||
|
HeadInput input = HeadInput.create();
|
||||||
|
input.setRef(ref);
|
||||||
|
call.put(input, cb);
|
||||||
|
}
|
||||||
|
|
||||||
public static RestApi project(Project.NameKey name) {
|
public static RestApi project(Project.NameKey name) {
|
||||||
return new RestApi("/projects/").id(name.get());
|
return new RestApi("/projects/").id(name.get());
|
||||||
}
|
}
|
||||||
@@ -229,4 +237,15 @@ public class ProjectApi {
|
|||||||
|
|
||||||
final native void setDescription(String d) /*-{ if(d)this.description=d; }-*/;
|
final native void setDescription(String d) /*-{ if(d)this.description=d; }-*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class HeadInput extends JavaScriptObject {
|
||||||
|
static HeadInput create() {
|
||||||
|
return createObject().cast();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HeadInput() {
|
||||||
|
}
|
||||||
|
|
||||||
|
final native void setRef(String r) /*-{ if(r)this.ref=r; }-*/;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user