SideBySide2: Add download links

Re-implemented the old download links. To avoid adding bogus links
on empty files, PatchSetSelectBox2 needs to know the meta info
for the diff. Don't add the download link if meta == null.

Change-Id: Ied3e0287a17144ab2d6d50289625495568cb53a6
This commit is contained in:
Michael Zhou
2013-10-17 20:21:23 -04:00
parent bcce4e3bdf
commit e53acd1086
3 changed files with 35 additions and 20 deletions

View File

@@ -133,9 +133,9 @@ class DiffTable extends Composite {
return fileCommentRow.getOffsetHeight() + patchSetSelectBoxA.getOffsetHeight(); return fileCommentRow.getOffsetHeight() + patchSetSelectBoxA.getOffsetHeight();
} }
void setUpPatchSetNav(JsArray<RevisionInfo> list) { void setUpPatchSetNav(JsArray<RevisionInfo> list, DiffInfo info) {
patchSetSelectBoxA.setUpPatchSetNav(list); patchSetSelectBoxA.setUpPatchSetNav(list, info.meta_a());
patchSetSelectBoxB.setUpPatchSetNav(list); patchSetSelectBoxB.setUpPatchSetNav(list, info.meta_b());
} }
void add(Widget widget) { void add(Widget widget) {

View File

@@ -20,6 +20,7 @@ import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.patches.PatchUtil; import com.google.gerrit.client.patches.PatchUtil;
import com.google.gerrit.client.ui.InlineHyperlink; import com.google.gerrit.client.ui.InlineHyperlink;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray; import com.google.gwt.core.client.JsArray;
@@ -28,14 +29,14 @@ import com.google.gwt.resources.client.CssResource;
import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler; import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ImageResourceRenderer;
import com.google.gwtorm.client.KeyUtil;
/** /** HTMLPanel to select among patch sets */
* HTMLPanel to select among patch sets
* TODO: Implement download link.
*/
class PatchSetSelectBox2 extends Composite { class PatchSetSelectBox2 extends Composite {
interface Binder extends UiBinder<HTMLPanel, PatchSetSelectBox2> {} interface Binder extends UiBinder<HTMLPanel, PatchSetSelectBox2> {}
private static final Binder uiBinder = GWT.create(Binder.class); private static final Binder uiBinder = GWT.create(Binder.class);
@@ -71,7 +72,7 @@ class PatchSetSelectBox2 extends Composite {
this.path = path; this.path = path;
} }
void setUpPatchSetNav(JsArray<RevisionInfo> list) { void setUpPatchSetNav(JsArray<RevisionInfo> list, DiffInfo.FileMeta meta) {
InlineHyperlink baseLink = null; InlineHyperlink baseLink = null;
InlineHyperlink selectedLink = null; InlineHyperlink selectedLink = null;
if (sideA) { if (sideA) {
@@ -92,6 +93,9 @@ class PatchSetSelectBox2 extends Composite {
} else if (sideA) { } else if (sideA) {
baseLink.setStyleName(style.selected()); baseLink.setStyleName(style.selected());
} }
if (meta != null && !Patch.COMMIT_MSG.equals(path)) {
linkPanel.add(createDownloadLink());
}
} }
static void link(PatchSetSelectBox2 a, PatchSetSelectBox2 b) { static void link(PatchSetSelectBox2 a, PatchSetSelectBox2 b) {
@@ -110,6 +114,17 @@ class PatchSetSelectBox2 extends Composite {
path)); path));
} }
private Anchor createDownloadLink() {
PatchSet.Id id = (idActive == null) ? other.idActive : idActive;
String sideURL = (idActive == null) ? "1" : "0";
String base = GWT.getHostPageBaseURL() + "cat/";
Anchor anchor = new Anchor(
new ImageResourceRenderer().render(Gerrit.RESOURCES.downloadIcon()),
base + KeyUtil.encode(id + "," + path) + "^" + sideURL);
anchor.setTitle(PatchUtil.C.download());
return anchor;
}
@UiHandler("icon") @UiHandler("icon")
void onIconClick(ClickEvent e) { void onIconClick(ClickEvent e) {
table.createOrEditFileComment(side); table.createOrEditFileComment(side);

View File

@@ -204,6 +204,18 @@ public class SideBySide2 extends Screen {
CommentApi.drafts(revision, group.add(getCommentCallback(DisplaySide.B, true))); CommentApi.drafts(revision, group.add(getCommentCallback(DisplaySide.B, true)));
} }
RestApi call = ChangeApi.detail(changeId.get());
ChangeList.addOptions(call, EnumSet.of(
ListChangesOption.ALL_REVISIONS));
call.get(group.add(new GerritCallback<ChangeInfo>() {
@Override
public void onSuccess(ChangeInfo info) {
info.revisions().copyKeysIntoChildren("name");
JsArray<RevisionInfo> list = info.revisions().values();
RevisionInfo.sortRevisionInfoByNumber(list);
diffTable.setUpPatchSetNav(list, diff);
}}));
ConfigInfoCache.get(changeId, group.addFinal( ConfigInfoCache.get(changeId, group.addFinal(
new ScreenLoadCallback<ConfigInfoCache.Entry>(SideBySide2.this) { new ScreenLoadCallback<ConfigInfoCache.Entry>(SideBySide2.this) {
@Override @Override
@@ -216,18 +228,6 @@ public class SideBySide2 extends Screen {
display(diffInfo); display(diffInfo);
} }
})); }));
RestApi call = ChangeApi.detail(changeId.get());
ChangeList.addOptions(call, EnumSet.of(
ListChangesOption.ALL_REVISIONS));
call.get(new GerritCallback<ChangeInfo>() {
@Override
public void onSuccess(ChangeInfo info) {
info.revisions().copyKeysIntoChildren("name");
JsArray<RevisionInfo> list = info.revisions().values();
RevisionInfo.sortRevisionInfoByNumber(list);
diffTable.setUpPatchSetNav(list);
}});
} }
@Override @Override