Merge "Replace PatchDetailService saveDraft and deleteDraft"
This commit is contained in:
@@ -34,7 +34,6 @@ import com.google.gerrit.client.ui.PatchLink;
|
||||
import com.google.gerrit.client.ui.SmallHeading;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.changes.ListChangesOption;
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.common.data.ChangeDetail;
|
||||
import com.google.gerrit.common.data.SubmitTypeRecord;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
@@ -485,26 +484,12 @@ public class PublishCommentScreen extends AccountScreen implements
|
||||
for (String path : paths) {
|
||||
JsArray<CommentInfo> comments = drafts.get(path);
|
||||
for (int i = 0; i < comments.length(); i++) {
|
||||
d.add(toComment(path, comments.get(i)));
|
||||
d.add(CommentEditorPanel.toComment(patchSetId, path, comments.get(i)));
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
private PatchLineComment toComment(String path, CommentInfo i) {
|
||||
PatchLineComment p = new PatchLineComment(
|
||||
new PatchLineComment.Key(
|
||||
new Patch.Key(patchSetId, path),
|
||||
i.id()),
|
||||
i.line(),
|
||||
Gerrit.getUserAccount().getId(),
|
||||
i.in_reply_to(),
|
||||
i.updated());
|
||||
p.setMessage(i.message());
|
||||
p.setSide((short) (i.side() == Side.PARENT ? 0 : 1));
|
||||
return p;
|
||||
}
|
||||
|
||||
private static class ValueRadioButton extends RadioButton {
|
||||
final LabelInfo label;
|
||||
final String value;
|
||||
|
@@ -18,6 +18,9 @@ import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.account.AccountInfo;
|
||||
import com.google.gerrit.client.changes.CommentApi;
|
||||
import com.google.gerrit.client.changes.CommentInfo;
|
||||
import com.google.gerrit.client.changes.CommentInput;
|
||||
import com.google.gerrit.client.changes.PatchTable;
|
||||
import com.google.gerrit.client.changes.Util;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
@@ -937,13 +940,17 @@ public abstract class AbstractPatchContentTable extends NavigationTable<Object>
|
||||
CommentEditorPanel p = findOrCreateEditor(newComment, false);
|
||||
if (p == null) {
|
||||
enableButtons(false);
|
||||
PatchUtil.DETAIL_SVC.saveDraft(newComment,
|
||||
new GerritCallback<PatchLineComment>() {
|
||||
final PatchSet.Id psId = newComment.getKey().getParentKey().getParentKey();
|
||||
CommentInput in = CommentEditorPanel.toInput(newComment);
|
||||
CommentApi.createDraft(psId, in,
|
||||
new GerritCallback<CommentInfo>() {
|
||||
@Override
|
||||
public void onSuccess(final PatchLineComment result) {
|
||||
public void onSuccess(CommentInfo result) {
|
||||
enableButtons(true);
|
||||
notifyDraftDelta(1);
|
||||
findOrCreateEditor(result, true).setOpen(false);
|
||||
findOrCreateEditor(CommentEditorPanel.toComment(
|
||||
psId, newComment.getKey().getParentKey().get(), result),
|
||||
true).setOpen(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -15,10 +15,17 @@
|
||||
package com.google.gerrit.client.patches;
|
||||
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.changes.CommentApi;
|
||||
import com.google.gerrit.client.changes.CommentInfo;
|
||||
import com.google.gerrit.client.changes.CommentInput;
|
||||
import com.google.gerrit.client.rpc.GerritCallback;
|
||||
import com.google.gerrit.client.ui.CommentLinkProcessor;
|
||||
import com.google.gerrit.client.ui.CommentPanel;
|
||||
import com.google.gerrit.common.changes.Side;
|
||||
import com.google.gerrit.reviewdb.client.Patch;
|
||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.DoubleClickEvent;
|
||||
@@ -236,30 +243,37 @@ public class CommentEditorPanel extends CommentPanel implements ClickHandler,
|
||||
cancel.setEnabled(false);
|
||||
discard.setEnabled(false);
|
||||
|
||||
PatchUtil.DETAIL_SVC.saveDraft(comment,
|
||||
new GerritCallback<PatchLineComment>() {
|
||||
public void onSuccess(final PatchLineComment result) {
|
||||
notifyDraftDelta(isNew() ? 1 : 0);
|
||||
comment = result;
|
||||
text.setReadOnly(false);
|
||||
save.setEnabled(true);
|
||||
cancel.setEnabled(true);
|
||||
discard.setEnabled(true);
|
||||
render();
|
||||
onSave.onSuccess(VoidResult.INSTANCE);
|
||||
}
|
||||
final PatchSet.Id psId = comment.getKey().getParentKey().getParentKey();
|
||||
final boolean wasNew = isNew();
|
||||
GerritCallback<CommentInfo> cb = new GerritCallback<CommentInfo>() {
|
||||
public void onSuccess(CommentInfo result) {
|
||||
notifyDraftDelta(wasNew ? 1 : 0);
|
||||
comment = toComment(psId, comment.getKey().get(), result);
|
||||
text.setReadOnly(false);
|
||||
save.setEnabled(true);
|
||||
cancel.setEnabled(true);
|
||||
discard.setEnabled(true);
|
||||
render();
|
||||
onSave.onSuccess(VoidResult.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(final Throwable caught) {
|
||||
text.setReadOnly(false);
|
||||
text.setFocus(true);
|
||||
save.setEnabled(true);
|
||||
cancel.setEnabled(true);
|
||||
discard.setEnabled(true);
|
||||
super.onFailure(caught);
|
||||
onSave.onFailure(caught);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(final Throwable caught) {
|
||||
text.setReadOnly(false);
|
||||
text.setFocus(true);
|
||||
save.setEnabled(true);
|
||||
cancel.setEnabled(true);
|
||||
discard.setEnabled(true);
|
||||
super.onFailure(caught);
|
||||
onSave.onFailure(caught);
|
||||
}
|
||||
};
|
||||
CommentInput input = toInput(comment);
|
||||
if (wasNew) {
|
||||
CommentApi.createDraft(psId, input, cb);
|
||||
} else {
|
||||
CommentApi.updateDraft(psId, input.id(), input, cb);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyDraftDelta(final int delta) {
|
||||
@@ -283,9 +297,11 @@ public class CommentEditorPanel extends CommentPanel implements ClickHandler,
|
||||
cancel.setEnabled(false);
|
||||
discard.setEnabled(false);
|
||||
|
||||
PatchUtil.DETAIL_SVC.deleteDraft(comment.getKey(),
|
||||
new GerritCallback<VoidResult>() {
|
||||
public void onSuccess(final VoidResult result) {
|
||||
CommentApi.deleteDraft(
|
||||
comment.getKey().getParentKey().getParentKey(),
|
||||
comment.getKey().get(),
|
||||
new GerritCallback<JavaScriptObject>() {
|
||||
public void onSuccess(JavaScriptObject result) {
|
||||
notifyDraftDelta(-1);
|
||||
removeUI();
|
||||
}
|
||||
@@ -319,4 +335,33 @@ public class CommentEditorPanel extends CommentPanel implements ClickHandler,
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static CommentInput toInput(PatchLineComment c) {
|
||||
CommentInput i = CommentInput.createObject().cast();
|
||||
i.setId(c.getKey().get());
|
||||
i.setPath(c.getKey().getParentKey().get());
|
||||
i.setSide(c.getSide() == 0 ? Side.PARENT : Side.REVISION);
|
||||
if (c.getLine() > 0) {
|
||||
i.setLine(c.getLine());
|
||||
}
|
||||
i.setInReplyTo(c.getParentUuid());
|
||||
i.setMessage(c.getMessage());
|
||||
return i;
|
||||
}
|
||||
|
||||
public static PatchLineComment toComment(PatchSet.Id ps,
|
||||
String path,
|
||||
CommentInfo i) {
|
||||
PatchLineComment p = new PatchLineComment(
|
||||
new PatchLineComment.Key(
|
||||
new Patch.Key(ps, path),
|
||||
i.id()),
|
||||
i.line(),
|
||||
Gerrit.getUserAccount().getId(),
|
||||
i.in_reply_to(),
|
||||
i.updated());
|
||||
p.setMessage(i.message());
|
||||
p.setSide((short) (i.side() == Side.PARENT ? 0 : 1));
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user