ChangeScreen2: Add 'Diff against' to select base revision

Add dropdown on the Files header section to select
reference version for loading the revision.

Change-Id: I5c40a52b0018fea7e11ac67696ee6fb7b4674349
(cherry picked from commit 2d2a3c405e)
This commit is contained in:
David Ostrovsky
2013-11-21 08:10:40 +01:00
committed by Michael Zhou
parent a310bbc448
commit bdcb9cff23
3 changed files with 81 additions and 15 deletions

View File

@@ -58,6 +58,8 @@ import com.google.gwt.core.client.JsArrayString;
import com.google.gwt.dom.client.AnchorElement;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.dom.client.SelectElement;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;
@@ -73,6 +75,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.ToggleButton;
import com.google.gwtexpui.clippy.client.CopyableLabel;
import com.google.gwtexpui.globalkey.client.GlobalKey;
@@ -124,6 +127,7 @@ public class ChangeScreen2 extends Screen {
private Timestamp lastDisplayedUpdate;
private UpdateAvailableBar updateAvailable;
private boolean openReplyBox;
private boolean loaded;
@UiField HTMLPanel headerLine;
@UiField Style style;
@@ -151,6 +155,7 @@ public class ChangeScreen2 extends Screen {
@UiField CommitBox commit;
@UiField RelatedChanges related;
@UiField FileTable files;
@UiField ListBox diffBase;
@UiField History history;
@UiField Button includedIn;
@@ -185,7 +190,7 @@ public class ChangeScreen2 extends Screen {
@Override
public void onSuccess(ChangeInfo info) {
info.init();
loadConfigInfo(info);
loadConfigInfo(info, null);
}
});
}
@@ -194,9 +199,7 @@ public class ChangeScreen2 extends Screen {
RestApi call = ChangeApi.detail(changeId.get());
ChangeList.addOptions(call, EnumSet.of(
ListChangesOption.CURRENT_ACTIONS,
fg && revision != null
? ListChangesOption.ALL_REVISIONS
: ListChangesOption.CURRENT_REVISION));
ListChangesOption.ALL_REVISIONS));
if (!fg) {
call.background();
}
@@ -444,25 +447,40 @@ public class ChangeScreen2 extends Screen {
collapseAll.setVisible(false);
}
private void loadConfigInfo(final ChangeInfo info) {
@UiHandler("diffBase")
void onChangeRevision(ChangeEvent e) {
int idx = diffBase.getSelectedIndex();
if (0 <= idx) {
String n = diffBase.getValue(idx);
loadConfigInfo(changeInfo, !n.isEmpty() ? n : null);
}
}
private void loadConfigInfo(final ChangeInfo info, final String base) {
info.revisions().copyKeysIntoChildren("name");
final RevisionInfo rev = resolveRevisionToDisplay(info);
CallbackGroup group = new CallbackGroup();
loadDiff(rev, myLastReply(info), group);
loadDiff(info.revisions().get(base), rev, myLastReply(info), group);
loadCommit(rev, group);
if (loaded) {
group.done();
return;
}
RevisionInfoCache.add(changeId, rev);
ConfigInfoCache.add(info);
ConfigInfoCache.get(info.project_name_key(),
group.add(new ScreenLoadCallback<ConfigInfoCache.Entry>(this) {
group.addFinal(new ScreenLoadCallback<ConfigInfoCache.Entry>(this) {
@Override
protected void preDisplay(Entry result) {
loaded = true;
commentLinkProcessor = result.getCommentLinkProcessor();
setTheme(result.getTheme());
renderChangeInfo(info);
}
}));
group.done();
}
private static Timestamp myLastReply(ChangeInfo info) {
@@ -478,16 +496,19 @@ public class ChangeScreen2 extends Screen {
return null;
}
private void loadDiff(final RevisionInfo rev, final Timestamp myLastReply,
CallbackGroup group) {
private void loadDiff(final RevisionInfo base, final RevisionInfo rev,
final Timestamp myLastReply, CallbackGroup group) {
final List<NativeMap<JsArray<CommentInfo>>> comments = loadComments(rev, group);
final List<NativeMap<JsArray<CommentInfo>>> drafts = loadDrafts(rev, group);
DiffApi.list(changeId.get(),
base != null ? base.name() : null,
rev.name(),
group.add(new AsyncCallback<NativeMap<FileInfo>>() {
@Override
public void onSuccess(NativeMap<FileInfo> m) {
files.setRevisions(null, new PatchSet.Id(changeId, rev._number()));
files.setRevisions(
base != null ? new PatchSet.Id(changeId, base._number()) : null,
new PatchSet.Id(changeId, rev._number()));
files.setValue(m, myLastReply, comments.get(0), drafts.get(0));
}
@@ -653,6 +674,7 @@ public class ChangeScreen2 extends Screen {
renderOwner(info);
renderActionTextDate(info);
renderDiffBaseListBox(info);
initIncludedInAction(info);
initRevisionsAction(info, revision);
initDownloadAction(info, revision);
@@ -728,6 +750,28 @@ public class ChangeScreen2 extends Screen {
actionDate.setInnerText(FormatUtil.relativeFormat(info.updated()));
}
private void renderDiffBaseListBox(ChangeInfo info) {
JsArray<RevisionInfo> list = info.revisions().values();
RevisionInfo.sortRevisionInfoByNumber(list);
for (int i = list.length() - 1; i >= 0; i--) {
RevisionInfo r = list.get(i);
diffBase.addItem(
r._number() + ": " + r.name().substring(0, 6),
r.name());
if (r.name().equals(revision)) {
SelectElement.as(diffBase.getElement()).getOptions()
.getItem(diffBase.getItemCount() - 1).setDisabled(true);
}
}
RevisionInfo rev = info.revisions().get(revision);
JsArray<CommitInfo> parents = rev.commit().parents();
diffBase.addItem(
parents.length() > 1 ? Util.C.autoMerge() : Util.C.baseDiffItem(),
"");
diffBase.setSelectedIndex(diffBase.getItemCount() - 1);
}
void showUpdates(ChangeInfo newInfo) {
if (!isAttached() || newInfo.updated().equals(lastDisplayedUpdate)) {
return;

View File

@@ -251,12 +251,27 @@ limitations under the License.
.sectionHeader .headerButtons {
top: 2px;
height: 18px;
line-height: 18px;
border-left: 1px inset #fff;
padding-top: 3px;
padding-bottom: 3px;
}
.sectionHeader button { margin-top: 0; }
.diffBase {
display: inline-block;
height: 18px;
line-height: 18px;
font-size: smaller;
font-weight: normal;
vertical-align: top;
}
.diffBase select {
margin: 0;
border: 1px solid #bbb;
font-size: smaller;
}
.replyBox {
background-color: trimColor;
}
@@ -390,6 +405,11 @@ limitations under the License.
<div class='{style.sectionHeader}'>
<ui:msg>Files</ui:msg>
<div class='{style.headerButtons}'>
<div class='{style.diffBase}'>
<ui:msg>Diff against: <g:ListBox ui:field='diffBase' styleName=''/></ui:msg>
</div>
</div>
</div>
<c:FileTable ui:field='files'/>

View File

@@ -26,11 +26,13 @@ public class DiffApi {
NONE, TRAILING, CHANGED, ALL;
};
public static void list(int id, String revision,
public static void list(int id, String base, String revision,
AsyncCallback<NativeMap<FileInfo>> cb) {
ChangeApi.revision(id, revision)
.view("files")
.get(NativeMap.copyKeysIntoChildren("path", cb));
RestApi api = ChangeApi.revision(id, revision).view("files");
if (base != null) {
api.addParameter("base", base);
}
api.get(NativeMap.copyKeysIntoChildren("path", cb));
}
public static DiffApi diff(PatchSet.Id id, String path) {