Add UiAction to create change from project info page

Change-Id: I2c9f23e644a020bcd30a478fbd3156e94a0c00d5
This commit is contained in:
Alan Tokaev
2014-08-10 21:51:14 +02:00
committed by Dave Borowitz
parent 74b27c6ac4
commit 0ec2763bc3
8 changed files with 223 additions and 1 deletions

View File

@@ -138,4 +138,9 @@ public interface AdminConstants extends Constants {
String pagedListPrev(); String pagedListPrev();
String pagedListNext(); String pagedListNext();
String buttonCreate();
String buttonCreateDescription();
String buttonCreateChange();
String buttonCreateChangeDescription();
} }

View File

@@ -162,3 +162,8 @@ sectionTypeSection = Section:
sectionNames = \ sectionNames = \
GLOBAL_CAPABILITIES GLOBAL_CAPABILITIES
GLOBAL_CAPABILITIES = Global Capabilities GLOBAL_CAPABILITIES = Global Capabilities
buttonCreate = Create
buttonCreateDescription = Insert the description of the change.
buttonCreateChange = Create Change
buttonCreateChangeDescription = Create change directly in the browser.

View File

@@ -0,0 +1,57 @@
// Copyright (C) 2014 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.admin;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.changes.ChangeApi;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.CreateChangeDialog;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.user.client.ui.Button;
class CreateChangeAction {
static void call(Button b, final String project) {
// TODO Replace CreateChangeDialog with a nicer looking display.
b.setEnabled(false);
new CreateChangeDialog(b, new Project.NameKey(project)) {
{
sendButton.setText(Util.C.buttonCreate());
message.setText(Util.C.buttonCreateDescription());
}
@Override
public void onSend() {
ChangeApi.createChange(project, getDestinationBranch(),
message.getText(),
new GerritCallback<ChangeInfo>() {
@Override
public void onSuccess(ChangeInfo result) {
sent = true;
hide();
Gerrit.display(PageLinks.toChange(result.legacy_id()));
}
@Override
public void onFailure(Throwable caught) {
enableButtons(true);
super.onFailure(caught);
}
});
}
}.center();
}
}

View File

@@ -565,10 +565,27 @@ public class ProjectInfoScreen extends ProjectScreen {
actionsPanel.setStyleName(Gerrit.RESOURCES.css().projectActions()); actionsPanel.setStyleName(Gerrit.RESOURCES.css().projectActions());
actionsPanel.setVisible(true); actionsPanel.setVisible(true);
actionsGrid.add(Util.C.headingCommands(), actionsPanel); actionsGrid.add(Util.C.headingCommands(), actionsPanel);
for (String id : actions.keySet()) { for (String id : actions.keySet()) {
actionsPanel.add(new ActionButton(getProjectKey(), actionsPanel.add(new ActionButton(getProjectKey(),
actions.get(id))); actions.get(id)));
} }
if (Gerrit.isSignedIn()) {
actionsPanel.add(createChangeAction());
}
}
private Button createChangeAction() {
final Button createChange = new Button(Util.C.buttonCreateChange());
createChange.setTitle(Util.C.buttonCreateChangeDescription());
createChange.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
CreateChangeAction.call(createChange, getProjectKey().get());
}
});
return createChange;
} }
private void doSave() { private void doSave() {

View File

@@ -34,6 +34,17 @@ public class ChangeApi {
call(id, "abandon").post(input, cb); call(id, "abandon").post(input, cb);
} }
/** Create a new change. */
public static void createChange(String project, String branch,
String subject, AsyncCallback<ChangeInfo> cb) {
CreateChangeInput input = CreateChangeInput.create();
input.project(emptyToNull(project));
input.branch(emptyToNull(branch));
input.subject(emptyToNull(subject));
new RestApi("/changes/").post(input, cb);
}
/** Restore a previously abandoned change to be open again. */ /** Restore a previously abandoned change to be open again. */
public static void restore(int id, String msg, AsyncCallback<ChangeInfo> cb) { public static void restore(int id, String msg, AsyncCallback<ChangeInfo> cb) {
Input input = Input.create(); Input input = Input.create();
@@ -194,6 +205,19 @@ public class ChangeApi {
} }
} }
private static class CreateChangeInput extends JavaScriptObject {
static CreateChangeInput create() {
return (CreateChangeInput) createObject();
}
public final native void branch(String b) /*-{ if(b)this.branch=b; }-*/;
public final native void project(String p) /*-{ if(p)this.project=p; }-*/;
public final native void subject(String s) /*-{ if(s)this.subject=s; }-*/;
protected CreateChangeInput() {
}
}
private static class CherryPickInput extends JavaScriptObject { private static class CherryPickInput extends JavaScriptObject {
static CherryPickInput create() { static CherryPickInput create() {
return (CherryPickInput) createObject(); return (CherryPickInput) createObject();

View File

@@ -0,0 +1,106 @@
// Copyright (C) 2014 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.ui;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.projects.BranchInfo;
import com.google.gerrit.client.projects.ProjectApi;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;
import com.google.gwtexpui.globalkey.client.GlobalKey;
import com.google.gwtexpui.safehtml.client.HighlightSuggestOracle;
import java.util.ArrayList;
import java.util.List;
public abstract class CreateChangeDialog extends ActionDialog {
private SuggestBox newChange;
private List<BranchInfo> branches;
public CreateChangeDialog(final FocusWidget enableOnFailure, Project.NameKey project) {
super(enableOnFailure, true, Util.C.dialogCreateChangeTitle(),
Util.C.dialogCreateChangeHeading());
ProjectApi.getBranches(project,
new GerritCallback<JsArray<BranchInfo>>() {
@Override
public void onSuccess(JsArray<BranchInfo> result) {
branches = Natives.asList(result);
}
});
newChange = new SuggestBox(new HighlightSuggestOracle() {
@Override
protected void onRequestSuggestions(Request request, Callback done) {
List<BranchSuggestion> suggestions = new ArrayList<>();
for (BranchInfo b : branches) {
if (b.ref().contains(request.getQuery())) {
suggestions.add(new BranchSuggestion(b));
}
}
done.onSuggestionsReady(request, new Response(suggestions));
}
});
newChange.setWidth("100%");
newChange.getElement().getStyle().setProperty("boxSizing", "border-box");
message.setCharacterWidth(70);
FlowPanel mwrap = new FlowPanel();
mwrap.setStyleName(Gerrit.RESOURCES.css().commentedActionMessage());
mwrap.add(newChange);
panel.insert(mwrap, 0);
panel.insert(new SmallHeading(Util.C.newChangeBranchSuggestion()), 0);
}
@Override
public void center() {
super.center();
GlobalKey.dialog(this);
newChange.setFocus(true);
}
public String getDestinationBranch() {
return newChange.getText();
}
class BranchSuggestion implements Suggestion {
private BranchInfo branch;
public BranchSuggestion(BranchInfo branch) {
this.branch = branch;
}
@Override
public String getDisplayString() {
if (branch.ref().startsWith(Branch.R_HEADS)) {
return branch.ref().substring(Branch.R_HEADS.length());
}
return branch.ref();
}
@Override
public String getReplacementString() {
return branch.getShortName();
}
}
}

View File

@@ -25,4 +25,8 @@ public interface UIConstants extends Constants {
String projectItemHelp(); String projectItemHelp();
String projectStateAbbrev(); String projectStateAbbrev();
String projectStateHelp(); String projectStateHelp();
String dialogCreateChangeTitle();
String dialogCreateChangeHeading();
String newChangeBranchSuggestion();
} }

View File

@@ -5,4 +5,8 @@ projectName = Project Name
projectDescription = Project Description projectDescription = Project Description
projectItemHelp = project projectItemHelp = project
projectStateAbbrev = S projectStateAbbrev = S
projectStateHelp = State projectStateHelp = State
dialogCreateChangeTitle = Create Change
dialogCreateChangeHeading = Description
newChangeBranchSuggestion = Select branch for new change