diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java index e8f07e689a..20ff9930b3 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.java @@ -138,4 +138,9 @@ public interface AdminConstants extends Constants { String pagedListPrev(); String pagedListNext(); + + String buttonCreate(); + String buttonCreateDescription(); + String buttonCreateChange(); + String buttonCreateChangeDescription(); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties index f9cba41d29..26b8123b69 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/AdminConstants.properties @@ -162,3 +162,8 @@ sectionTypeSection = Section: sectionNames = \ 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. diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/CreateChangeAction.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/CreateChangeAction.java new file mode 100644 index 0000000000..724bb988ab --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/CreateChangeAction.java @@ -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() { + @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(); + } +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java index 69d7c9e209..558a2e99f5 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/admin/ProjectInfoScreen.java @@ -565,10 +565,27 @@ public class ProjectInfoScreen extends ProjectScreen { actionsPanel.setStyleName(Gerrit.RESOURCES.css().projectActions()); actionsPanel.setVisible(true); actionsGrid.add(Util.C.headingCommands(), actionsPanel); + for (String id : actions.keySet()) { actionsPanel.add(new ActionButton(getProjectKey(), 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() { diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeApi.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeApi.java index 88ba6b419e..eb3c0fd719 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeApi.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeApi.java @@ -34,6 +34,17 @@ public class ChangeApi { call(id, "abandon").post(input, cb); } + /** Create a new change. */ + public static void createChange(String project, String branch, + String subject, AsyncCallback 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. */ public static void restore(int id, String msg, AsyncCallback cb) { 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 { static CherryPickInput create() { return (CherryPickInput) createObject(); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CreateChangeDialog.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CreateChangeDialog.java new file mode 100644 index 0000000000..a5155689f4 --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CreateChangeDialog.java @@ -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 branches; + + public CreateChangeDialog(final FocusWidget enableOnFailure, Project.NameKey project) { + super(enableOnFailure, true, Util.C.dialogCreateChangeTitle(), + Util.C.dialogCreateChangeHeading()); + ProjectApi.getBranches(project, + new GerritCallback>() { + @Override + public void onSuccess(JsArray result) { + branches = Natives.asList(result); + } + }); + + newChange = new SuggestBox(new HighlightSuggestOracle() { + @Override + protected void onRequestSuggestions(Request request, Callback done) { + List 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(); + } + } +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.java index bcfb394ec0..0f5e12ad76 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.java @@ -25,4 +25,8 @@ public interface UIConstants extends Constants { String projectItemHelp(); String projectStateAbbrev(); String projectStateHelp(); + + String dialogCreateChangeTitle(); + String dialogCreateChangeHeading(); + String newChangeBranchSuggestion(); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.properties b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.properties index 1e0e18563d..a0845d980c 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.properties +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/UIConstants.properties @@ -5,4 +5,8 @@ projectName = Project Name projectDescription = Project Description projectItemHelp = project projectStateAbbrev = S -projectStateHelp = State \ No newline at end of file +projectStateHelp = State + +dialogCreateChangeTitle = Create Change +dialogCreateChangeHeading = Description +newChangeBranchSuggestion = Select branch for new change