Allow to control target of web links

Plugins can now control the target window in which a web link should
be opened.

This is an incompatible change and plugins implementing web links must
be adapted.

Change-Id: I5aec40ce425251b10fcb912131d547982d27cd55
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2014-09-11 17:07:33 +02:00
parent 2970f85486
commit ceeed6b48a
10 changed files with 48 additions and 8 deletions

View File

@ -1775,6 +1775,11 @@ public class MyWeblinkPlugin implements PatchSetWebLink {
public String getImageUrl() {
return imageUrl;
}
@Override
public String getTarget() {
return "_blank";
}
}
----

View File

@ -18,10 +18,12 @@ public class WebLinkInfo {
public String name;
public String imageUrl;
public String url;
public String target;
public WebLinkInfo(String name, String imageUrl, String url) {
public WebLinkInfo(String name, String imageUrl, String url, String target) {
this.name = name;
this.imageUrl = imageUrl;
this.url = url;
this.target = target;
}
}

View File

@ -15,6 +15,12 @@ package com.google.gerrit.extensions.webui;
public interface WebLink {
public static class Target {
public final static String BLANK = "_blank";
public final static String SELF = "_self";
public final static String PARENT = "_parent";
public final static String TOP = "_top";
}
/**
* The link-name displayed in UI.
*
@ -29,4 +35,11 @@ public interface WebLink {
* Recommended image size is 16x16.
*/
String getImageUrl();
/**
* Target window in which the link should be opened (e.g. "_blank", "_self".).
*
* @return link target, if null the link is opened in the current window
*/
String getTarget();
}

View File

@ -21,6 +21,7 @@ public class WebLinkInfo extends JavaScriptObject {
public final native String name() /*-{ return this.name; }-*/;
public final native String imageUrl() /*-{ return this.image_url; }-*/;
public final native String url() /*-{ return this.url; }-*/;
public final native String target() /*-{ return this.target; }-*/;
protected WebLinkInfo() {
}

View File

@ -399,6 +399,9 @@ public class ProjectBranchesScreen extends ProjectScreen {
for (WebLinkInfo weblink : Natives.asList(k.web_links())) {
Anchor a = new Anchor();
a.setHref(weblink.url());
if (weblink.target() != null && !weblink.target().isEmpty()) {
a.setTarget(weblink.target());
}
if (weblink.imageUrl() != null && !weblink.imageUrl().isEmpty()) {
Image img = new Image();
img.setAltText(weblink.name());

View File

@ -240,6 +240,9 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
for (WebLinkInfo weblink : webLinks) {
Anchor a = new Anchor();
a.setHref(weblink.url());
if (weblink.target() != null && !weblink.target().isEmpty()) {
a.setTarget(weblink.target());
}
if (weblink.imageUrl() != null && !weblink.imageUrl().isEmpty()) {
Image img = new Image();
img.setAltText(weblink.name());

View File

@ -127,20 +127,25 @@ class CommitBox extends Composite {
GitwebLink gw = Gerrit.getGitwebLink();
if (gw != null && gw.canLink(revInfo)) {
addWebLink(gw.toRevision(change.project(), revision),
gw.getLinkName(), null);
gw.getLinkName(), null, null);
}
JsArray<WebLinkInfo> links = revInfo.web_links();
if (links != null) {
for (WebLinkInfo link : Natives.asList(links)) {
addWebLink(link.url(), parenthesize(link.name()), link.imageUrl());
addWebLink(link.url(), parenthesize(link.name()), link.imageUrl(),
link.target());
}
}
}
private void addWebLink(String href, String name, String imageUrl) {
private void addWebLink(String href, String name, String imageUrl,
String target) {
Anchor a = new Anchor();
a.setHref(href);
if (target != null && !target.isEmpty()) {
a.setTarget(target);
}
if (imageUrl != null && !imageUrl.isEmpty()) {
Image img = new Image();
img.setAltText(name);

View File

@ -108,6 +108,9 @@ class PatchSetSelectBox2 extends Composite {
for (WebLinkInfo weblink : webLinks) {
Anchor a = new Anchor();
a.setHref(weblink.url());
if (weblink.target() != null && !weblink.target().isEmpty()) {
a.setTarget(weblink.target());
}
if (weblink.imageUrl() != null && !weblink.imageUrl().isEmpty()) {
Image img = new Image();
img.setAltText(weblink.name());

View File

@ -46,7 +46,8 @@ public class WebLinks {
for (PatchSetWebLink webLink : patchSetLinks) {
links.add(new WebLinkInfo(webLink.getLinkName(),
webLink.getImageUrl(),
webLink.getPatchSetUrl(project, commit)));
webLink.getPatchSetUrl(project, commit),
webLink.getTarget()));
}
return links;
}
@ -57,7 +58,8 @@ public class WebLinks {
for (FileWebLink webLink : fileLinks) {
links.add(new WebLinkInfo(webLink.getLinkName(),
webLink.getImageUrl(),
webLink.getFileUrl(project, revision, file)));
webLink.getFileUrl(project, revision, file),
webLink.getTarget()));
}
return links;
}
@ -67,7 +69,8 @@ public class WebLinks {
for (ProjectWebLink webLink : projectLinks) {
links.add(new WebLinkInfo(webLink.getLinkName(),
webLink.getImageUrl(),
webLink.getProjectUrl(project)));
webLink.getProjectUrl(project),
webLink.getTarget()));
}
return links;
}
@ -77,7 +80,8 @@ public class WebLinks {
for (BranchWebLink webLink : branchLinks) {
links.add(new WebLinkInfo(webLink.getLinkName(),
webLink.getImageUrl(),
webLink.getBranchUrl(project, branch)));
webLink.getBranchUrl(project, branch),
webLink.getTarget()));
}
return links;
}

1
plugins/its-base Submodule

@ -0,0 +1 @@
Subproject commit e9135f64e4f38229124392e8007e45f8f4ad0e58