Merge "Add support for branch web links"
This commit is contained in:
		| @@ -1781,6 +1781,8 @@ public class MyWeblinkPlugin implements PatchSetWebLink { | ||||
| ProjectWebLinks will appear in the project list in the | ||||
| `Repository Browser` column. | ||||
|  | ||||
| BranchWebLinks will appear in the branch list in the last column. | ||||
|  | ||||
| [[documentation]] | ||||
| == Documentation | ||||
|  | ||||
|   | ||||
| @@ -1573,6 +1573,9 @@ The `BranchInfo` entity contains information about a branch. | ||||
| |`revision`  ||The revision to which the branch points. | ||||
| |`can_delete`|`false` if not set| | ||||
| Whether the calling user can delete this branch. | ||||
| |'web_links' |optional| | ||||
| Links to the branch in external sites as a list of | ||||
| link:rest-api-changes.html#web-link-info[WebLinkInfo] entries. | ||||
| |========================= | ||||
|  | ||||
| [[ban-input]] | ||||
|   | ||||
| @@ -0,0 +1,30 @@ | ||||
| // Copyright (C) 2014 The Android Open Source Project | ||||
| // | ||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| // you may not use this file except in compliance with the License. | ||||
| // You may obtain a copy of the License at | ||||
| // | ||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||
| // | ||||
| // Unless required by applicable law or agreed to in writing, software | ||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| // See the License for the specific language governing permissions and | ||||
| // limitations under the License. | ||||
|  | ||||
| package com.google.gerrit.extensions.webui; | ||||
|  | ||||
| import com.google.gerrit.extensions.annotations.ExtensionPoint; | ||||
|  | ||||
| @ExtensionPoint | ||||
| public interface BranchWebLink extends WebLink { | ||||
|  | ||||
|   /** | ||||
|    * URL to branch in external service. | ||||
|    * | ||||
|    * @param projectName Name of the project | ||||
|    * @param branchName Name of the branch | ||||
|    * @return url to branch in external service. | ||||
|    */ | ||||
|   String getBranchUrl(String projectName, String branchName); | ||||
| } | ||||
| @@ -20,6 +20,7 @@ import com.google.gerrit.client.ErrorDialog; | ||||
| import com.google.gerrit.client.Gerrit; | ||||
| import com.google.gerrit.client.GitwebLink; | ||||
| import com.google.gerrit.client.VoidResult; | ||||
| import com.google.gerrit.client.WebLinkInfo; | ||||
| import com.google.gerrit.client.access.AccessMap; | ||||
| import com.google.gerrit.client.access.ProjectAccessInfo; | ||||
| import com.google.gerrit.client.actions.ActionButton; | ||||
| @@ -396,6 +397,22 @@ public class ProjectBranchesScreen extends ProjectScreen { | ||||
|         actionsPanel.add(new Anchor(c.getLinkName(), false, | ||||
|             c.toBranch(new Branch.NameKey(getProjectKey(), k.ref())))); | ||||
|       } | ||||
|       if (k.web_links() != null) { | ||||
|         for (WebLinkInfo weblink : Natives.asList(k.web_links())) { | ||||
|           Anchor a = new Anchor(); | ||||
|           a.setHref(weblink.url()); | ||||
|           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) { | ||||
|         k.actions().copyKeysIntoChildren("id"); | ||||
|         for (ActionInfo a : Natives.asList(k.actions().values())) { | ||||
|   | ||||
| @@ -14,10 +14,12 @@ | ||||
|  | ||||
| package com.google.gerrit.client.projects; | ||||
|  | ||||
| import com.google.gerrit.client.WebLinkInfo; | ||||
| import com.google.gerrit.client.actions.ActionInfo; | ||||
| import com.google.gerrit.client.rpc.NativeMap; | ||||
| import com.google.gerrit.reviewdb.client.Branch; | ||||
| import com.google.gwt.core.client.JavaScriptObject; | ||||
| import com.google.gwt.core.client.JsArray; | ||||
|  | ||||
| public class BranchInfo extends JavaScriptObject { | ||||
|   public final String getShortName() { | ||||
| @@ -30,6 +32,7 @@ public class BranchInfo extends JavaScriptObject { | ||||
|   public final native String revision() /*-{ return this.revision; }-*/; | ||||
|   public final native boolean canDelete() /*-{ return this['can_delete'] ? true : false; }-*/; | ||||
|   public final native NativeMap<ActionInfo> actions() /*-{ return this.actions }-*/; | ||||
|   public final native JsArray<WebLinkInfo> web_links() /*-{ return this.web_links; }-*/; | ||||
|  | ||||
|   protected BranchInfo() { | ||||
|   } | ||||
|   | ||||
| @@ -17,6 +17,7 @@ package com.google.gerrit.server; | ||||
| import com.google.common.collect.Lists; | ||||
| import com.google.gerrit.extensions.common.WebLinkInfo; | ||||
| import com.google.gerrit.extensions.registration.DynamicSet; | ||||
| import com.google.gerrit.extensions.webui.BranchWebLink; | ||||
| import com.google.gerrit.extensions.webui.PatchSetWebLink; | ||||
| import com.google.gerrit.extensions.webui.ProjectWebLink; | ||||
|  | ||||
| @@ -26,11 +27,14 @@ public class WebLinks { | ||||
|  | ||||
|   private final DynamicSet<PatchSetWebLink> patchSetLinks; | ||||
|   private final DynamicSet<ProjectWebLink> projectLinks; | ||||
|   private final DynamicSet<BranchWebLink> branchLinks; | ||||
|  | ||||
|   public WebLinks(DynamicSet<PatchSetWebLink> patchSetLinks, | ||||
|       DynamicSet<ProjectWebLink> projectLinks) { | ||||
|       DynamicSet<ProjectWebLink> projectLinks, | ||||
|       DynamicSet<BranchWebLink> branchLinks) { | ||||
|     this.patchSetLinks = patchSetLinks; | ||||
|     this.projectLinks = projectLinks; | ||||
|     this.branchLinks = branchLinks; | ||||
|   } | ||||
|  | ||||
|   public Iterable<WebLinkInfo> getPatchSetLinks(String project, String commit) { | ||||
| @@ -52,4 +56,14 @@ public class WebLinks { | ||||
|     } | ||||
|     return links; | ||||
|   } | ||||
|  | ||||
|   public Iterable<WebLinkInfo> getBranchLinks(String project, String branch) { | ||||
|     List<WebLinkInfo> links = Lists.newArrayList(); | ||||
|     for (BranchWebLink webLink : branchLinks) { | ||||
|       links.add(new WebLinkInfo(webLink.getLinkName(), | ||||
|           webLink.getImageUrl(), | ||||
|           webLink.getBranchUrl(project, branch))); | ||||
|     } | ||||
|     return links; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -15,6 +15,7 @@ | ||||
| package com.google.gerrit.server; | ||||
|  | ||||
| import com.google.gerrit.extensions.registration.DynamicSet; | ||||
| import com.google.gerrit.extensions.webui.BranchWebLink; | ||||
| import com.google.gerrit.extensions.webui.PatchSetWebLink; | ||||
| import com.google.gerrit.extensions.webui.ProjectWebLink; | ||||
| import com.google.inject.Inject; | ||||
| @@ -24,17 +25,20 @@ public class WebLinksProvider implements Provider<WebLinks> { | ||||
|  | ||||
|   private final DynamicSet<PatchSetWebLink> patchSetLinks; | ||||
|   private final DynamicSet<ProjectWebLink> projectLinks; | ||||
|   private final DynamicSet<BranchWebLink> branchLinks; | ||||
|  | ||||
|   @Inject | ||||
|   public WebLinksProvider(DynamicSet<PatchSetWebLink> patchSetLinks, | ||||
|       DynamicSet<ProjectWebLink> projectLinks) { | ||||
|       DynamicSet<ProjectWebLink> projectLinks, | ||||
|       DynamicSet<BranchWebLink> branchLinks) { | ||||
|     this.patchSetLinks = patchSetLinks; | ||||
|     this.projectLinks = projectLinks; | ||||
|     this.branchLinks = branchLinks; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
|   public WebLinks get() { | ||||
|     WebLinks webLinks = new WebLinks(patchSetLinks, projectLinks); | ||||
|     WebLinks webLinks = new WebLinks(patchSetLinks, projectLinks, branchLinks); | ||||
|     return webLinks; | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -32,6 +32,7 @@ import com.google.gerrit.extensions.registration.DynamicItem; | ||||
| import com.google.gerrit.extensions.registration.DynamicMap; | ||||
| import com.google.gerrit.extensions.registration.DynamicSet; | ||||
| import com.google.gerrit.extensions.systemstatus.MessageOfTheDay; | ||||
| import com.google.gerrit.extensions.webui.BranchWebLink; | ||||
| import com.google.gerrit.extensions.webui.PatchSetWebLink; | ||||
| import com.google.gerrit.extensions.webui.ProjectWebLink; | ||||
| import com.google.gerrit.extensions.webui.TopMenu; | ||||
| @@ -281,6 +282,7 @@ public class GerritGlobalModule extends FactoryModule { | ||||
|     DynamicMap.mapOf(binder(), ProjectConfigEntry.class); | ||||
|     DynamicSet.setOf(binder(), PatchSetWebLink.class); | ||||
|     DynamicSet.setOf(binder(), ProjectWebLink.class); | ||||
|     DynamicSet.setOf(binder(), BranchWebLink.class); | ||||
|  | ||||
|     factory(UploadValidators.Factory.class); | ||||
|     DynamicSet.setOf(binder(), UploadValidationListener.class); | ||||
|   | ||||
| @@ -14,18 +14,22 @@ | ||||
|  | ||||
| package com.google.gerrit.server.project; | ||||
|  | ||||
| import com.google.common.base.Strings; | ||||
| import com.google.common.collect.Lists; | ||||
| import com.google.common.collect.Sets; | ||||
| import com.google.gerrit.extensions.common.ActionInfo; | ||||
| import com.google.gerrit.extensions.common.WebLinkInfo; | ||||
| import com.google.gerrit.extensions.registration.DynamicMap; | ||||
| import com.google.gerrit.extensions.restapi.ResourceNotFoundException; | ||||
| import com.google.gerrit.extensions.restapi.RestReadView; | ||||
| import com.google.gerrit.extensions.restapi.RestView; | ||||
| import com.google.gerrit.extensions.webui.UiAction; | ||||
| import com.google.gerrit.reviewdb.client.RefNames; | ||||
| import com.google.gerrit.server.WebLinks; | ||||
| import com.google.gerrit.server.extensions.webui.UiActions; | ||||
| import com.google.gerrit.server.git.GitRepositoryManager; | ||||
| import com.google.inject.Inject; | ||||
| import com.google.inject.Provider; | ||||
| import com.google.inject.Singleton; | ||||
| import com.google.inject.util.Providers; | ||||
|  | ||||
| @@ -47,12 +51,15 @@ import java.util.TreeMap; | ||||
| public class ListBranches implements RestReadView<ProjectResource> { | ||||
|   private final GitRepositoryManager repoManager; | ||||
|   private final DynamicMap<RestView<BranchResource>> branchViews; | ||||
|   private final Provider<WebLinks> webLinks; | ||||
|  | ||||
|   @Inject | ||||
|   public ListBranches(GitRepositoryManager repoManager, | ||||
|       DynamicMap<RestView<BranchResource>> branchViews) { | ||||
|       DynamicMap<RestView<BranchResource>> branchViews, | ||||
|       Provider<WebLinks> webLinks) { | ||||
|     this.repoManager = repoManager; | ||||
|     this.branchViews = branchViews; | ||||
|     this.webLinks = webLinks; | ||||
|   } | ||||
|  | ||||
|   @Override | ||||
| @@ -161,6 +168,13 @@ public class ListBranches implements RestReadView<ProjectResource> { | ||||
|       } | ||||
|       info.actions.put(d.getId(), new ActionInfo(d)); | ||||
|     } | ||||
|     info.webLinks = Lists.newArrayList(); | ||||
|     for (WebLinkInfo link : webLinks.get().getBranchLinks( | ||||
|         refControl.getProjectControl().getProject().getName(), ref.getName())) { | ||||
|       if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) { | ||||
|         info.webLinks.add(link); | ||||
|       } | ||||
|     } | ||||
|     return info; | ||||
|   } | ||||
|  | ||||
| @@ -169,6 +183,7 @@ public class ListBranches implements RestReadView<ProjectResource> { | ||||
|     public String revision; | ||||
|     public Boolean canDelete; | ||||
|     public Map<String, ActionInfo> actions; | ||||
|     public List<WebLinkInfo> webLinks; | ||||
|  | ||||
|     public BranchInfo(String ref, String revision, boolean canDelete) { | ||||
|       this.ref = ref; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Edwin Kempin
					Edwin Kempin