Replace gitweb glue with WebLink extensions
Keep the gitweb configuration section, but bind the URLs through the WebLink extension points instead of specific support in the web UI. This simplifies the server and UI implementations a bit by using only code paths that other plugins like the gitiles plugin use. Change-Id: I8508dcaf3a4405b3ce3a47f2f717472a46e5a8ca
This commit is contained in:
@@ -15,16 +15,12 @@
|
||||
package com.google.gerrit.client.admin;
|
||||
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.info.GitwebInfo;
|
||||
import com.google.gerrit.client.ui.Hyperlink;
|
||||
import com.google.gerrit.client.ui.ParentProjectBox;
|
||||
import com.google.gerrit.common.data.AccessSection;
|
||||
import com.google.gerrit.common.data.ProjectAccess;
|
||||
import com.google.gerrit.common.data.WebLinkInfoCommon;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.DivElement;
|
||||
import com.google.gwt.dom.client.Style.Display;
|
||||
@@ -156,32 +152,14 @@ public class ProjectAccessEditor extends Composite implements
|
||||
}
|
||||
|
||||
private void setUpWebLinks() {
|
||||
if (!value.isConfigVisible()) {
|
||||
List<WebLinkInfoCommon> links = value.getFileHistoryLinks();
|
||||
if (!value.isConfigVisible() || links == null || links.isEmpty()) {
|
||||
history.getStyle().setDisplay(Display.NONE);
|
||||
} else {
|
||||
GitwebInfo c = Gerrit.info().gitweb();
|
||||
List<WebLinkInfoCommon> links = value.getFileHistoryLinks();
|
||||
if (c == null && links == null) {
|
||||
history.getStyle().setDisplay(Display.NONE);
|
||||
}
|
||||
if (c != null) {
|
||||
webLinkPanel.add(toAnchor(c.toFileHistory(new Branch.NameKey(value.getProjectName(),
|
||||
RefNames.REFS_CONFIG), "project.config"), c.getLinkName()));
|
||||
}
|
||||
|
||||
if (links != null) {
|
||||
for (WebLinkInfoCommon link : links) {
|
||||
webLinkPanel.add(toAnchor(link));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (WebLinkInfoCommon link : links) {
|
||||
webLinkPanel.add(toAnchor(link));
|
||||
}
|
||||
}
|
||||
|
||||
private Anchor toAnchor(String href, String name) {
|
||||
Anchor a = new Anchor();
|
||||
a.setHref(href);
|
||||
a.setText(name);
|
||||
return a;
|
||||
}
|
||||
|
||||
private static Anchor toAnchor(WebLinkInfoCommon info) {
|
||||
|
@@ -25,7 +25,6 @@ import com.google.gerrit.client.access.AccessMap;
|
||||
import com.google.gerrit.client.access.ProjectAccessInfo;
|
||||
import com.google.gerrit.client.actions.ActionButton;
|
||||
import com.google.gerrit.client.info.ActionInfo;
|
||||
import com.google.gerrit.client.info.GitwebInfo;
|
||||
import com.google.gerrit.client.info.WebLinkInfo;
|
||||
import com.google.gerrit.client.projects.BranchInfo;
|
||||
import com.google.gerrit.client.projects.ProjectApi;
|
||||
@@ -39,7 +38,6 @@ import com.google.gerrit.client.ui.NavigationTable;
|
||||
import com.google.gerrit.client.ui.OnEditEnabler;
|
||||
import com.google.gerrit.client.ui.PagingHyperlink;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.client.Branch;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gwt.core.client.JsArray;
|
||||
@@ -54,7 +52,6 @@ import com.google.gwt.event.dom.client.KeyUpEvent;
|
||||
import com.google.gwt.event.dom.client.KeyUpHandler;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.CheckBox;
|
||||
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
|
||||
@@ -408,8 +405,6 @@ public class ProjectBranchesScreen extends PaginatedProjectScreen {
|
||||
}
|
||||
|
||||
void populate(int row, BranchInfo k) {
|
||||
GitwebInfo c = Gerrit.info().gitweb();
|
||||
|
||||
if (k.canDelete()) {
|
||||
CheckBox sel = new CheckBox();
|
||||
sel.addValueChangeHandler(updateDeleteHandler);
|
||||
@@ -432,10 +427,6 @@ public class ProjectBranchesScreen extends PaginatedProjectScreen {
|
||||
}
|
||||
|
||||
FlowPanel actionsPanel = new FlowPanel();
|
||||
if (c != null) {
|
||||
actionsPanel.add(new Anchor(c.getLinkName(), false,
|
||||
c.toBranch(new Branch.NameKey(getProjectKey(), k.ref()))));
|
||||
}
|
||||
if (k.webLinks() != null) {
|
||||
for (WebLinkInfo webLink : Natives.asList(k.webLinks())) {
|
||||
actionsPanel.add(webLink.toAnchor());
|
||||
|
@@ -18,7 +18,6 @@ import static com.google.gerrit.common.PageLinks.ADMIN_PROJECTS;
|
||||
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.info.GitwebInfo;
|
||||
import com.google.gerrit.client.info.WebLinkInfo;
|
||||
import com.google.gerrit.client.projects.ProjectInfo;
|
||||
import com.google.gerrit.client.projects.ProjectMap;
|
||||
@@ -34,7 +33,6 @@ import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyUpEvent;
|
||||
import com.google.gwt.event.dom.client.KeyUpHandler;
|
||||
import com.google.gwt.user.client.History;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
@@ -141,22 +139,12 @@ public class ProjectListScreen extends PaginatedProjectScreen {
|
||||
}
|
||||
|
||||
private void addWebLinks(int row, ProjectInfo k) {
|
||||
GitwebInfo gitwebLink = Gerrit.info().gitweb();
|
||||
List<WebLinkInfo> webLinks = Natives.asList(k.webLinks());
|
||||
if (gitwebLink != null || (webLinks != null && !webLinks.isEmpty())) {
|
||||
if (webLinks != null && !webLinks.isEmpty()) {
|
||||
FlowPanel p = new FlowPanel();
|
||||
table.setWidget(row, ProjectsTable.C_REPO_BROWSER, p);
|
||||
|
||||
if (gitwebLink != null) {
|
||||
Anchor a = new Anchor();
|
||||
a.setText(gitwebLink.getLinkName());
|
||||
a.setHref(gitwebLink.toProject(k.name_key()));
|
||||
p.add(a);
|
||||
}
|
||||
if (webLinks != null) {
|
||||
for (WebLinkInfo weblink : webLinks) {
|
||||
p.add(weblink.toAnchor());
|
||||
}
|
||||
for (WebLinkInfo weblink : webLinks) {
|
||||
p.add(weblink.toAnchor());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,13 +16,11 @@ package com.google.gerrit.client.change;
|
||||
|
||||
import com.google.gerrit.client.AvatarImage;
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.info.AccountInfo;
|
||||
import com.google.gerrit.client.info.ChangeInfo;
|
||||
import com.google.gerrit.client.info.ChangeInfo.CommitInfo;
|
||||
import com.google.gerrit.client.info.ChangeInfo.GitPerson;
|
||||
import com.google.gerrit.client.info.ChangeInfo.RevisionInfo;
|
||||
import com.google.gerrit.client.info.GitwebInfo;
|
||||
import com.google.gerrit.client.info.WebLinkInfo;
|
||||
import com.google.gerrit.client.rpc.Natives;
|
||||
import com.google.gerrit.client.ui.CommentLinkProcessor;
|
||||
@@ -38,7 +36,6 @@ import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
@@ -118,13 +115,13 @@ class CommitBox extends Composite {
|
||||
committerDate, change);
|
||||
text.setHTML(commentLinkProcessor.apply(
|
||||
new SafeHtmlBuilder().append(commit.message()).linkify()));
|
||||
setWebLinks(change, revision, revInfo);
|
||||
setWebLinks(revInfo);
|
||||
|
||||
if (revInfo.commit().parents().length() > 1) {
|
||||
mergeCommit.setVisible(true);
|
||||
}
|
||||
|
||||
setParents(change.project(), revInfo.commit().parents());
|
||||
setParents(revInfo.commit().parents());
|
||||
}
|
||||
|
||||
void setParentNotCurrent(boolean parentNotCurrent) {
|
||||
@@ -133,14 +130,7 @@ class CommitBox extends Composite {
|
||||
parentNotCurrentText.setInnerText(parentNotCurrent ? "\u25CF" : "");
|
||||
}
|
||||
|
||||
private void setWebLinks(ChangeInfo change, String revision,
|
||||
RevisionInfo revInfo) {
|
||||
GitwebInfo gw = Gerrit.info().gitweb();
|
||||
if (gw != null && gw.canLink(revInfo)) {
|
||||
toAnchor(gw.toRevision(change.project(), revision),
|
||||
gw.getLinkName());
|
||||
}
|
||||
|
||||
private void setWebLinks(RevisionInfo revInfo) {
|
||||
JsArray<WebLinkInfo> links = revInfo.commit().webLinks();
|
||||
if (links != null) {
|
||||
for (WebLinkInfo link : Natives.asList(links)) {
|
||||
@@ -149,14 +139,7 @@ class CommitBox extends Composite {
|
||||
}
|
||||
}
|
||||
|
||||
private void toAnchor(String href, String name) {
|
||||
Anchor a = new Anchor();
|
||||
a.setHref(href);
|
||||
a.setText(name);
|
||||
webLinkPanel.add(a);
|
||||
}
|
||||
|
||||
private void setParents(String project, JsArray<CommitInfo> commits) {
|
||||
private void setParents(JsArray<CommitInfo> commits) {
|
||||
setVisible(firstParent, true);
|
||||
TableRowElement next = firstParent;
|
||||
TableRowElement previous = null;
|
||||
@@ -164,18 +147,11 @@ class CommitBox extends Composite {
|
||||
if (next == firstParent) {
|
||||
CopyableLabel copyLabel = getCommitLabel(c);
|
||||
parentCommits.add(copyLabel);
|
||||
addLinks(project, c, parentWebLinks);
|
||||
} else {
|
||||
next.appendChild(DOM.createTD());
|
||||
Element td1 = DOM.createTD();
|
||||
td1.appendChild(getCommitLabel(c).getElement());
|
||||
next.appendChild(td1);
|
||||
FlowPanel linksPanel = new FlowPanel();
|
||||
linksPanel.addStyleName(style.parentWebLink());
|
||||
addLinks(project, c, linksPanel);
|
||||
Element td2 = DOM.createTD();
|
||||
td2.appendChild(linksPanel.getElement());
|
||||
next.appendChild(td2);
|
||||
previous.getParentElement().insertAfter(next, previous);
|
||||
}
|
||||
previous = next;
|
||||
@@ -183,16 +159,6 @@ class CommitBox extends Composite {
|
||||
}
|
||||
}
|
||||
|
||||
private void addLinks(String project, CommitInfo c, FlowPanel panel) {
|
||||
GitwebInfo gw = Gerrit.info().gitweb();
|
||||
if (gw != null) {
|
||||
Anchor a =
|
||||
new Anchor(gw.getLinkName(), gw.toRevision(project, c.commit()));
|
||||
a.setStyleName(style.parentWebLink());
|
||||
panel.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
private CopyableLabel getCommitLabel(CommitInfo c) {
|
||||
CopyableLabel copyLabel;
|
||||
copyLabel = new CopyableLabel(c.commit());
|
||||
|
@@ -18,7 +18,6 @@ import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.change.RelatedChanges.ChangeAndCommit;
|
||||
import com.google.gerrit.client.changes.Util;
|
||||
import com.google.gerrit.client.info.ChangeInfo.CommitInfo;
|
||||
import com.google.gerrit.client.info.GitwebInfo;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
@@ -306,12 +305,7 @@ class RelatedChangesTab implements IsWidget {
|
||||
sb.closeSpan();
|
||||
|
||||
sb.openSpan();
|
||||
GitwebInfo gw = Gerrit.info().gitweb();
|
||||
if (gw != null && (!info.hasChangeNumber() || !info.hasRevisionNumber())) {
|
||||
sb.setStyleName(RelatedChanges.R.css().gitweb());
|
||||
sb.setAttribute("title", gw.getLinkName());
|
||||
sb.append('\u25CF'); // Unicode 'BLACK CIRCLE'
|
||||
} else if (info.status() != null && !info.status().isOpen()) {
|
||||
if (info.status() != null && !info.status().isOpen()) {
|
||||
sb.setStyleName(RelatedChanges.R.css().gitweb());
|
||||
sb.setAttribute("title", Util.toLongString(info.status()));
|
||||
sb.append('\u25CF'); // Unicode 'BLACK CIRCLE'
|
||||
@@ -340,11 +334,6 @@ class RelatedChangesTab implements IsWidget {
|
||||
if (info.hasChangeNumber() && info.hasRevisionNumber()) {
|
||||
return "#" + PageLinks.toChange(info.patchSetId());
|
||||
}
|
||||
|
||||
GitwebInfo gw = Gerrit.info().gitweb();
|
||||
if (gw != null && project != null) {
|
||||
return gw.toRevision(project, info.commit().commit());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -22,9 +22,7 @@ import com.google.gerrit.client.changes.ReviewInfo;
|
||||
import com.google.gerrit.client.changes.Util;
|
||||
import com.google.gerrit.client.diff.DiffInfo.Region;
|
||||
import com.google.gerrit.client.info.ChangeInfo;
|
||||
import com.google.gerrit.client.info.ChangeInfo.RevisionInfo;
|
||||
import com.google.gerrit.client.info.FileInfo;
|
||||
import com.google.gerrit.client.info.GitwebInfo;
|
||||
import com.google.gerrit.client.info.WebLinkInfo;
|
||||
import com.google.gerrit.client.patches.PatchUtil;
|
||||
import com.google.gerrit.client.rpc.CallbackGroup;
|
||||
@@ -114,32 +112,20 @@ public class Header extends Composite {
|
||||
if (!Gerrit.isSignedIn()) {
|
||||
reviewed.getElement().getStyle().setVisibility(Visibility.HIDDEN);
|
||||
}
|
||||
SafeHtml.setInnerHTML(filePath, formatPath(path, null, null));
|
||||
SafeHtml.setInnerHTML(filePath, formatPath(path));
|
||||
up.setTargetHistoryToken(PageLinks.toChange(
|
||||
patchSetId.getParentKey(),
|
||||
base != null ? base.getId() : null, patchSetId.getId()));
|
||||
}
|
||||
|
||||
public static SafeHtml formatPath(String path, String project, String commit) {
|
||||
public static SafeHtml formatPath(String path) {
|
||||
SafeHtmlBuilder b = new SafeHtmlBuilder();
|
||||
if (Patch.COMMIT_MSG.equals(path)) {
|
||||
return b.append(Util.C.commitMessage());
|
||||
}
|
||||
|
||||
GitwebInfo gw = (project != null && commit != null)
|
||||
? Gerrit.info().gitweb() : null;
|
||||
int s = path.lastIndexOf('/') + 1;
|
||||
if (gw != null && s > 0) {
|
||||
String base = path.substring(0, s - 1);
|
||||
b.openAnchor()
|
||||
.setAttribute("href", gw.toFile(project, commit, base))
|
||||
.setAttribute("title", gw.getLinkName())
|
||||
.append(base)
|
||||
.closeAnchor()
|
||||
.append('/');
|
||||
} else {
|
||||
b.append(path.substring(0, s));
|
||||
}
|
||||
b.append(path.substring(0, s));
|
||||
b.openElement("b");
|
||||
b.append(path.substring(s));
|
||||
b.closeElement("b");
|
||||
@@ -200,23 +186,6 @@ public class Header extends Composite {
|
||||
}
|
||||
|
||||
void setChangeInfo(ChangeInfo info) {
|
||||
GitwebInfo gw = Gerrit.info().gitweb();
|
||||
if (gw != null) {
|
||||
for (RevisionInfo rev : Natives.asList(info.revisions().values())) {
|
||||
if (patchSetId.getId().equals(rev.id())) {
|
||||
String c = rev.name();
|
||||
SafeHtml.setInnerHTML(filePath, formatPath(path, info.project(), c));
|
||||
SafeHtml.setInnerHTML(project, new SafeHtmlBuilder()
|
||||
.openAnchor()
|
||||
.setAttribute("href", gw.toFile(info.project(), c, ""))
|
||||
.setAttribute("title", gw.getLinkName())
|
||||
.append(info.project())
|
||||
.closeAnchor());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
project.setInnerText(info.project());
|
||||
}
|
||||
|
||||
|
@@ -191,7 +191,7 @@ public class EditScreen extends Screen {
|
||||
@Override
|
||||
public void onSuccess(ChangeInfo c) {
|
||||
project.setInnerText(c.project());
|
||||
SafeHtml.setInnerHTML(filePath, Header.formatPath(path, null, null));
|
||||
SafeHtml.setInnerHTML(filePath, Header.formatPath(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user