Merge changes I5abaa282,Ifa7701d0,If7ff2115
* changes: ChangeScreen2: Support draft changes and draft patch sets Allow to delete non current draft patch sets Expose UiActions also for non current draft patch sets
This commit is contained in:
@@ -36,12 +36,16 @@ import java.util.TreeSet;
|
||||
class Actions extends Composite {
|
||||
private static final String[] CORE = {
|
||||
"abandon", "restore", "revert", "topic",
|
||||
"cherrypick", "submit", "rebase", "message"};
|
||||
"cherrypick", "submit", "rebase", "message",
|
||||
"publish", "/"};
|
||||
|
||||
interface Binder extends UiBinder<FlowPanel, Actions> {}
|
||||
private static final Binder uiBinder = GWT.create(Binder.class);
|
||||
|
||||
@UiField Button cherrypick;
|
||||
@UiField Button deleteChange;
|
||||
@UiField Button deleteRevision;
|
||||
@UiField Button publish;
|
||||
@UiField Button rebase;
|
||||
@UiField Button revert;
|
||||
@UiField Button submit;
|
||||
@@ -87,11 +91,11 @@ class Actions extends Composite {
|
||||
: NativeMap.<ActionInfo> create();
|
||||
actions.copyKeysIntoChildren("id");
|
||||
|
||||
abandon.setVisible(hasUser && actions.containsKey("abandon"));
|
||||
restore.setVisible(hasUser && actions.containsKey("restore"));
|
||||
revert.setVisible(hasUser && actions.containsKey("revert"));
|
||||
|
||||
if (hasUser) {
|
||||
a2b(actions, "/", deleteChange);
|
||||
a2b(actions, "abandon", abandon);
|
||||
a2b(actions, "restore", restore);
|
||||
a2b(actions, "revert", revert);
|
||||
for (String id : filterNonCore(actions)) {
|
||||
add(new ActionButton(info, actions.get(id)));
|
||||
}
|
||||
@@ -105,11 +109,16 @@ class Actions extends Composite {
|
||||
: NativeMap.<ActionInfo> create();
|
||||
actions.copyKeysIntoChildren("id");
|
||||
|
||||
cherrypick.setVisible(hasUser && actions.containsKey("cherrypick"));
|
||||
rebase.setVisible(hasUser && actions.containsKey("rebase"));
|
||||
canSubmit = hasUser && actions.containsKey("submit");
|
||||
|
||||
canSubmit = false;
|
||||
if (hasUser) {
|
||||
canSubmit = actions.containsKey("submit");
|
||||
if (canSubmit) {
|
||||
submit.setTitle(actions.get("submit").title());
|
||||
}
|
||||
a2b(actions, "/", deleteRevision);
|
||||
a2b(actions, "cherrypick", cherrypick);
|
||||
a2b(actions, "publish", publish);
|
||||
a2b(actions, "rebase", rebase);
|
||||
for (String id : filterNonCore(actions)) {
|
||||
add(new ActionButton(info, revInfo, actions.get(id)));
|
||||
}
|
||||
@@ -144,6 +153,21 @@ class Actions extends Composite {
|
||||
abandonAction.show();
|
||||
}
|
||||
|
||||
@UiHandler("publish")
|
||||
void onPublish(ClickEvent e) {
|
||||
DraftActions.publish(changeId, revision);
|
||||
}
|
||||
|
||||
@UiHandler("deleteRevision")
|
||||
void onDeleteRevision(ClickEvent e) {
|
||||
DraftActions.delete(changeId, revision);
|
||||
}
|
||||
|
||||
@UiHandler("deleteChange")
|
||||
void onDeleteChange(ClickEvent e) {
|
||||
DraftActions.delete(changeId);
|
||||
}
|
||||
|
||||
@UiHandler("restore")
|
||||
void onRestore(ClickEvent e) {
|
||||
if (restoreAction == null) {
|
||||
@@ -171,4 +195,11 @@ class Actions extends Composite {
|
||||
void onRevert(ClickEvent e) {
|
||||
RevertAction.call(cherrypick, changeId, revision, project, subject);
|
||||
}
|
||||
|
||||
private static void a2b(NativeMap<ActionInfo> actions, String a, Button b) {
|
||||
if (actions.containsKey(a)) {
|
||||
b.setVisible(true);
|
||||
b.setTitle(actions.get(a).title());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,20 +69,29 @@ limitations under the License.
|
||||
</ui:style>
|
||||
|
||||
<g:FlowPanel>
|
||||
<g:Button ui:field='cherrypick' styleName=''>
|
||||
<g:Button ui:field='cherrypick' styleName='' visible='false'>
|
||||
<div><ui:msg>Cherry Pick</ui:msg></div>
|
||||
</g:Button>
|
||||
<g:Button ui:field='rebase' styleName=''>
|
||||
<g:Button ui:field='rebase' styleName='' visible='false'>
|
||||
<div><ui:msg>Rebase</ui:msg></div>
|
||||
</g:Button>
|
||||
<g:Button ui:field='revert' styleName=''>
|
||||
<g:Button ui:field='revert' styleName='' visible='false'>
|
||||
<div><ui:msg>Revert</ui:msg></div>
|
||||
</g:Button>
|
||||
<g:Button ui:field='deleteChange' styleName='' visible='false'>
|
||||
<div><ui:msg>Delete Change</ui:msg></div>
|
||||
</g:Button>
|
||||
<g:Button ui:field='deleteRevision' styleName='' visible='false'>
|
||||
<div><ui:msg>Delete Revision</ui:msg></div>
|
||||
</g:Button>
|
||||
<g:Button ui:field='publish' styleName='' visible='false'>
|
||||
<div><ui:msg>Publish</ui:msg></div>
|
||||
</g:Button>
|
||||
|
||||
<g:Button ui:field='abandon' styleName='{style.red}'>
|
||||
<g:Button ui:field='abandon' styleName='{style.red}' visible='false'>
|
||||
<div><ui:msg>Abandon</ui:msg></div>
|
||||
</g:Button>
|
||||
<g:Button ui:field='restore' styleName='{style.red}'>
|
||||
<g:Button ui:field='restore' styleName='{style.red}' visible='false'>
|
||||
<div><ui:msg>Restore</ui:msg></div>
|
||||
</g:Button>
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// Copyright (C) 2013 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.change;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.changes.ChangeApi;
|
||||
import com.google.gerrit.client.changes.SubmitFailureDialog;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
class DraftActions {
|
||||
|
||||
static void publish(Change.Id id, String revision) {
|
||||
ChangeApi.publish(id.get(), revision, cs(id));
|
||||
}
|
||||
|
||||
static void delete(Change.Id id, String revision) {
|
||||
ChangeApi.deleteRevision(id.get(), revision, cs(id));
|
||||
}
|
||||
|
||||
static void delete(Change.Id id) {
|
||||
ChangeApi.deleteChange(id.get(), mine());
|
||||
}
|
||||
|
||||
private static GerritCallback<JavaScriptObject> cs(
|
||||
final Change.Id id) {
|
||||
return new GerritCallback<JavaScriptObject>() {
|
||||
public void onSuccess(JavaScriptObject result) {
|
||||
Gerrit.display(PageLinks.toChange(id));
|
||||
}
|
||||
|
||||
public void onFailure(Throwable err) {
|
||||
if (SubmitFailureDialog.isConflict(err)) {
|
||||
new SubmitFailureDialog(err.getMessage()).center();
|
||||
Gerrit.display(PageLinks.toChange(id));
|
||||
} else {
|
||||
super.onFailure(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static AsyncCallback<JavaScriptObject> mine() {
|
||||
return new GerritCallback<JavaScriptObject>() {
|
||||
public void onSuccess(JavaScriptObject result) {
|
||||
Gerrit.display(PageLinks.MINE);
|
||||
}
|
||||
|
||||
public void onFailure(Throwable err) {
|
||||
if (SubmitFailureDialog.isConflict(err)) {
|
||||
new SubmitFailureDialog(err.getMessage()).center();
|
||||
Gerrit.display(PageLinks.MINE);
|
||||
} else {
|
||||
super.onFailure(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,22 @@ public class ChangeApi {
|
||||
call(id, commit, "submit").post(in, cb);
|
||||
}
|
||||
|
||||
/** Publish a specific revision of a draft change. */
|
||||
public static void publish(int id, String commit, AsyncCallback<JavaScriptObject> cb) {
|
||||
JavaScriptObject in = JavaScriptObject.createObject();
|
||||
call(id, commit, "publish").post(in, cb);
|
||||
}
|
||||
|
||||
/** Delete a specific draft change. */
|
||||
public static void deleteChange(int id, AsyncCallback<JavaScriptObject> cb) {
|
||||
change(id).delete(cb);
|
||||
}
|
||||
|
||||
/** Delete a specific draft patch set. */
|
||||
public static void deleteRevision(int id, String commit, AsyncCallback<JavaScriptObject> cb) {
|
||||
revision(id, commit).delete(cb);
|
||||
}
|
||||
|
||||
/** Rebase a revision onto the branch tip. */
|
||||
public static void rebase(int id, String commit, AsyncCallback<ChangeInfo> cb) {
|
||||
JavaScriptObject in = JavaScriptObject.createObject();
|
||||
|
||||
@@ -822,7 +822,8 @@ public class ChangeJson {
|
||||
}
|
||||
}
|
||||
|
||||
if (out.isCurrent && has(CURRENT_ACTIONS)
|
||||
if ((out.isCurrent || out.draft)
|
||||
&& has(CURRENT_ACTIONS)
|
||||
&& userProvider.get().isIdentifiedUser()) {
|
||||
out.actions = Maps.newTreeMap();
|
||||
for (UiAction.Description d : UiActions.from(
|
||||
|
||||
@@ -87,7 +87,6 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
||||
|
||||
@Override
|
||||
public UiAction.Description getDescription(RevisionResource rsrc) {
|
||||
PatchSet.Id current = rsrc.getChange().currentPatchSetId();
|
||||
try {
|
||||
int psCount = dbProvider.get().patchSets()
|
||||
.byChange(rsrc.getChange().getId()).toList().size();
|
||||
@@ -95,7 +94,6 @@ public class DeleteDraftPatchSet implements RestModifyView<RevisionResource, Inp
|
||||
.setTitle(String.format("Delete Draft Revision %d",
|
||||
rsrc.getPatchSet().getPatchSetId()))
|
||||
.setVisible(rsrc.getPatchSet().isDraft()
|
||||
&& rsrc.getPatchSet().getId().equals(current)
|
||||
&& rsrc.getControl().canDeleteDraft(dbProvider.get())
|
||||
&& psCount > 1);
|
||||
} catch (OrmException e) {
|
||||
|
||||
@@ -146,7 +146,7 @@ public class Submit implements RestModifyView<RevisionResource, Input>,
|
||||
public UiAction.Description getDescription(RevisionResource resource) {
|
||||
PatchSet.Id current = resource.getChange().currentPatchSetId();
|
||||
return new UiAction.Description()
|
||||
.setLabel(String.format(
|
||||
.setTitle(String.format(
|
||||
"Submit Revision %d",
|
||||
resource.getPatchSet().getPatchSetId()))
|
||||
.setVisible(resource.getChange().getStatus().isOpen()
|
||||
|
||||
Reference in New Issue
Block a user