Hide/show active comment editors upon sign out/sign in

They can't save the editor's contents without their cookie, so we
need to throw the editor away.

Upon sign in again we need to make sure the current set of draft
editors is valid.  We load all current drafts back in, allowing
the user to resume editing their unpublished comments.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-01-14 18:18:17 -08:00
parent 2711645183
commit 57fd9e3856
5 changed files with 103 additions and 0 deletions

View File

@@ -16,10 +16,12 @@ package com.google.gerrit.client.patches;
import com.google.gerrit.client.FormatUtil;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.SignedInListener;
import com.google.gerrit.client.changes.Util;
import com.google.gerrit.client.data.AccountInfoCache;
import com.google.gerrit.client.reviewdb.Patch;
import com.google.gerrit.client.reviewdb.PatchLineComment;
import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.ComplexDisclosurePanel;
import com.google.gerrit.client.ui.FancyFlexTable;
import com.google.gwt.user.client.DOM;
@@ -40,11 +42,58 @@ public abstract class AbstractPatchContentTable extends FancyFlexTable<Object> {
protected Patch.Key patchKey;
private final Timestamp aged =
new Timestamp(System.currentTimeMillis() - AGE);
private final SignedInListener signedInListener = new SignedInListener() {
public void onSignIn() {
if (patchKey != null) {
PatchUtil.DETAIL_SVC.myDrafts(patchKey,
new GerritCallback<List<PatchLineComment>>() {
public void onSuccess(final List<PatchLineComment> result) {
if (!result.isEmpty()) {
bindDrafts(result);
}
}
});
}
}
public void onSignOut() {
// TODO we should probably confirm with the user before sign out starts
// that its OK to sign out if any of our editors are unsaved.
// (bug GERRIT-16)
//
int nRows = table.getRowCount();
for (int row = 0; row < nRows;) {
final int nCells = table.getCellCount(row);
int inc = 1;
for (int cell = 0; cell < nCells; cell++) {
if (table.getWidget(row, cell) instanceof CommentEditorPanel) {
table.removeRow(row);
nRows--;
inc = 0;
break;
}
}
row += inc;
}
}
};
protected AbstractPatchContentTable() {
table.setStyleName("gerrit-PatchContentTable");
}
@Override
public void onLoad() {
super.onLoad();
Gerrit.addSignedInListener(signedInListener);
}
@Override
public void onUnload() {
Gerrit.removeSignedInListener(signedInListener);
super.onUnload();
}
@Override
protected MyFlexTable createFlexTable() {
return new DoubleClickFlexTable();
@@ -58,6 +107,8 @@ public abstract class AbstractPatchContentTable extends FancyFlexTable<Object> {
/** Invoked when the user clicks on a table cell. */
protected abstract void onCellDoubleClick(int row, int column);
protected abstract void bindDrafts(List<PatchLineComment> drafts);
protected void createCommentEditor(int suggestRow, final int column,
final int line, final short side) {
while (getRowItem(suggestRow) instanceof CommentList) {

View File

@@ -23,6 +23,8 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.RemoteJsonService;
import com.google.gwtjsonrpc.client.VoidResult;
import java.util.List;
public interface PatchDetailService extends RemoteJsonService {
void sideBySidePatchDetail(Patch.Key key,
AsyncCallback<SideBySidePatchDetail> callback);
@@ -30,6 +32,9 @@ public interface PatchDetailService extends RemoteJsonService {
void unifiedPatchDetail(Patch.Key key,
AsyncCallback<UnifiedPatchDetail> callback);
@SignInRequired
void myDrafts(Patch.Key key, AsyncCallback<List<PatchLineComment>> callback);
@SignInRequired
void saveDraft(PatchLineComment comment,
AsyncCallback<PatchLineComment> callback);

View File

@@ -60,6 +60,25 @@ public class SideBySideTable extends AbstractPatchContentTable {
super.onOpenItem(item);
}
@Override
protected void bindDrafts(final List<PatchLineComment> drafts) {
int row = 0;
for (final PatchLineComment c : drafts) {
while (row < table.getRowCount()) {
if (getRowItem(row) instanceof SideBySideLineList) {
final SideBySideLineList pl = (SideBySideLineList) getRowItem(row);
final SideBySideLine line = pl.lines.get(c.getSide());
if (line != null && line.getLineNumber() >= c.getLine()) {
break;
}
}
row++;
}
table.insertRow(row + 1);
bindComment(row + 1, 1 + c.getSide() * 2 + 1, c, true);
}
}
public void display(final SideBySidePatchDetail detail) {
setAccountInfoCache(detail.getAccounts());
setPatchKey(detail.getPatch().getKey());

View File

@@ -57,6 +57,24 @@ public class UnifiedDiffTable extends AbstractPatchContentTable {
super.onOpenItem(item);
}
@Override
protected void bindDrafts(final List<PatchLineComment> drafts) {
int row = 0;
for (final PatchLineComment c : drafts) {
while (row < table.getRowCount()) {
if (getRowItem(row) instanceof PatchLine) {
final PatchLine pl = (PatchLine) getRowItem(row);
if (pl.getOldLineNumber() >= c.getLine()) {
break;
}
}
row++;
}
table.insertRow(row + 1);
bindComment(row + 1, 1, c, true);
}
}
public void display(final List<PatchLine> list) {
final StringBuilder nc = new StringBuilder();
for (final PatchLine pLine : list) {

View File

@@ -33,6 +33,7 @@ import com.google.gwtjsonrpc.client.VoidResult;
import com.google.gwtorm.client.OrmException;
import java.util.Collections;
import java.util.List;
public class PatchDetailServiceImpl extends BaseServiceImplementation implements
PatchDetailService {
@@ -57,6 +58,15 @@ public class PatchDetailServiceImpl extends BaseServiceImplementation implements
run(callback, new UnifiedPatchDetailAction(key));
}
public void myDrafts(final Patch.Key key,
final AsyncCallback<List<PatchLineComment>> callback) {
run(callback, new Action<List<PatchLineComment>>() {
public List<PatchLineComment> run(ReviewDb db) throws OrmException {
return db.patchComments().draft(key, Common.getAccountId()).toList();
}
});
}
public void saveDraft(final PatchLineComment comment,
final AsyncCallback<PatchLineComment> callback) {
run(callback, new Action<PatchLineComment>() {