Move Anchor creation to WebLinkInfo
Change-Id: Ia763de5f5e49df166ce549454d1a64d3d3c8c374
This commit is contained in:
@@ -15,6 +15,8 @@
|
|||||||
package com.google.gerrit.client;
|
package com.google.gerrit.client;
|
||||||
|
|
||||||
import com.google.gwt.core.client.JavaScriptObject;
|
import com.google.gwt.core.client.JavaScriptObject;
|
||||||
|
import com.google.gwt.user.client.ui.Anchor;
|
||||||
|
import com.google.gwt.user.client.ui.Image;
|
||||||
|
|
||||||
public class WebLinkInfo extends JavaScriptObject {
|
public class WebLinkInfo extends JavaScriptObject {
|
||||||
|
|
||||||
@@ -25,4 +27,22 @@ public class WebLinkInfo extends JavaScriptObject {
|
|||||||
|
|
||||||
protected WebLinkInfo() {
|
protected WebLinkInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final Anchor toAnchor() {
|
||||||
|
Anchor a = new Anchor();
|
||||||
|
a.setHref(url());
|
||||||
|
if (target() != null && !target().isEmpty()) {
|
||||||
|
a.setTarget(target());
|
||||||
|
}
|
||||||
|
if (imageUrl() != null && !imageUrl().isEmpty()) {
|
||||||
|
Image img = new Image();
|
||||||
|
img.setAltText(name());
|
||||||
|
img.setUrl(imageUrl());
|
||||||
|
img.setTitle(name());
|
||||||
|
a.getElement().appendChild(img.getElement());
|
||||||
|
} else {
|
||||||
|
a.setText("(" + name() + ")");
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,22 +396,8 @@ public class ProjectBranchesScreen extends ProjectScreen {
|
|||||||
c.toBranch(new Branch.NameKey(getProjectKey(), k.ref()))));
|
c.toBranch(new Branch.NameKey(getProjectKey(), k.ref()))));
|
||||||
}
|
}
|
||||||
if (k.web_links() != null) {
|
if (k.web_links() != null) {
|
||||||
for (WebLinkInfo weblink : Natives.asList(k.web_links())) {
|
for (WebLinkInfo webLink : Natives.asList(k.web_links())) {
|
||||||
Anchor a = new Anchor();
|
actionsPanel.add(webLink.toAnchor());
|
||||||
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());
|
|
||||||
img.setUrl(weblink.imageUrl());
|
|
||||||
img.setTitle(weblink.name());
|
|
||||||
a.getElement().appendChild(img.getElement());
|
|
||||||
} else {
|
|
||||||
a.setText("(" + weblink.name() + ")");
|
|
||||||
}
|
|
||||||
actionsPanel.add(a);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (k.actions() != null) {
|
if (k.actions() != null) {
|
||||||
|
|||||||
@@ -238,21 +238,7 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (WebLinkInfo weblink : webLinks) {
|
for (WebLinkInfo weblink : webLinks) {
|
||||||
Anchor a = new Anchor();
|
p.add(weblink.toAnchor());
|
||||||
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());
|
|
||||||
img.setUrl(weblink.imageUrl());
|
|
||||||
img.setTitle(weblink.name());
|
|
||||||
a.getElement().appendChild(img.getElement());
|
|
||||||
} else {
|
|
||||||
a.setText("(" + weblink.name() + ")");
|
|
||||||
}
|
|
||||||
p.add(a);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,35 +126,22 @@ class CommitBox extends Composite {
|
|||||||
RevisionInfo revInfo) {
|
RevisionInfo revInfo) {
|
||||||
GitwebLink gw = Gerrit.getGitwebLink();
|
GitwebLink gw = Gerrit.getGitwebLink();
|
||||||
if (gw != null && gw.canLink(revInfo)) {
|
if (gw != null && gw.canLink(revInfo)) {
|
||||||
addWebLink(gw.toRevision(change.project(), revision),
|
toAnchor(gw.toRevision(change.project(), revision),
|
||||||
gw.getLinkName(), null, null);
|
gw.getLinkName());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsArray<WebLinkInfo> links = revInfo.web_links();
|
JsArray<WebLinkInfo> links = revInfo.web_links();
|
||||||
if (links != null) {
|
if (links != null) {
|
||||||
for (WebLinkInfo link : Natives.asList(links)) {
|
for (WebLinkInfo link : Natives.asList(links)) {
|
||||||
addWebLink(link.url(), parenthesize(link.name()), link.imageUrl(),
|
webLinkPanel.add(link.toAnchor());
|
||||||
link.target());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addWebLink(String href, String name, String imageUrl,
|
private void toAnchor(String href, String name) {
|
||||||
String target) {
|
|
||||||
Anchor a = new Anchor();
|
Anchor a = new Anchor();
|
||||||
a.setHref(href);
|
a.setHref(href);
|
||||||
if (target != null && !target.isEmpty()) {
|
a.setText(name);
|
||||||
a.setTarget(target);
|
|
||||||
}
|
|
||||||
if (imageUrl != null && !imageUrl.isEmpty()) {
|
|
||||||
Image img = new Image();
|
|
||||||
img.setAltText(name);
|
|
||||||
img.setUrl(imageUrl);
|
|
||||||
img.setTitle(name);
|
|
||||||
a.getElement().appendChild(img.getElement());
|
|
||||||
} else {
|
|
||||||
a.setText(name);
|
|
||||||
}
|
|
||||||
webLinkPanel.add(a);
|
webLinkPanel.add(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,14 +185,6 @@ class CommitBox extends Composite {
|
|||||||
date.setInnerText(FormatUtil.mediumFormat(person.date()));
|
date.setInnerText(FormatUtil.mediumFormat(person.date()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String parenthesize(String str) {
|
|
||||||
return new StringBuilder()
|
|
||||||
.append("(")
|
|
||||||
.append(str)
|
|
||||||
.append(")")
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String renderName(GitPerson person) {
|
private static String renderName(GitPerson person) {
|
||||||
return person.name() + " <" + person.email() + ">";
|
return person.name() + " <" + person.email() + ">";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,22 +123,8 @@ class PatchSetSelectBox2 extends Composite {
|
|||||||
}
|
}
|
||||||
List<WebLinkInfo> webLinks = Natives.asList(meta.web_links());
|
List<WebLinkInfo> webLinks = Natives.asList(meta.web_links());
|
||||||
if (webLinks != null) {
|
if (webLinks != null) {
|
||||||
for (WebLinkInfo weblink : webLinks) {
|
for (WebLinkInfo webLink : webLinks) {
|
||||||
Anchor a = new Anchor();
|
linkPanel.add(webLink.toAnchor());
|
||||||
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());
|
|
||||||
img.setUrl(weblink.imageUrl());
|
|
||||||
img.setTitle(weblink.name());
|
|
||||||
a.getElement().appendChild(img.getElement());
|
|
||||||
} else {
|
|
||||||
a.setText("(" + weblink.name() + ")");
|
|
||||||
}
|
|
||||||
linkPanel.add(a);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user