mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 15:35:59 +01:00
(refs #1161)Add new extension point to add repository menu
This commit is contained in:
@@ -3,6 +3,7 @@ package gitbucket.core.plugin
|
||||
import javax.servlet.ServletContext
|
||||
import gitbucket.core.controller.{Context, ControllerBase}
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.Version
|
||||
@@ -88,6 +89,16 @@ abstract class Plugin {
|
||||
*/
|
||||
def globalMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(Context) => Option[Link]] = Nil
|
||||
|
||||
/**
|
||||
* Override to add repository menus.
|
||||
*/
|
||||
val repositoryMenus: Seq[(RepositoryInfo, Context) => Option[Link]] = Nil
|
||||
|
||||
/**
|
||||
* Override to add repository menus.
|
||||
*/
|
||||
def repositoryMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(RepositoryInfo, Context) => Option[Link]] = Nil
|
||||
|
||||
/**
|
||||
* Override to add profile tabs.
|
||||
*/
|
||||
@@ -124,6 +135,9 @@ abstract class Plugin {
|
||||
(globalMenus ++ globalMenus(registry, context, settings)).foreach { globalMenu =>
|
||||
registry.addGlobalMenu(globalMenu)
|
||||
}
|
||||
(repositoryMenus ++ repositoryMenus(registry, context, settings)).foreach { repositoryMenu =>
|
||||
registry.addRepositoryMenu(repositoryMenu)
|
||||
}
|
||||
(profileTabs ++ profileTabs(registry, context, settings)).foreach { profileTab =>
|
||||
registry.addProfileTab(profileTab)
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.servlet.ServletContext
|
||||
import gitbucket.core.controller.{Context, ControllerBase}
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.ProtectedBranchService.ProtectedBranchReceiveHook
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.Directory._
|
||||
@@ -33,6 +34,7 @@ class PluginRegistry {
|
||||
receiveHooks += new ProtectedBranchReceiveHook()
|
||||
|
||||
private val globalMenus = new ListBuffer[(Context) => Option[Link]]
|
||||
private val repositoryMenus = new ListBuffer[(RepositoryInfo, Context) => Option[Link]]
|
||||
private val profileTabs = new ListBuffer[(Account, Context) => Option[Link]]
|
||||
|
||||
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
||||
@@ -109,14 +111,20 @@ class PluginRegistry {
|
||||
|
||||
def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq
|
||||
|
||||
def addGlobalMenu(menu: (Context) => Option[Link]): Unit = {
|
||||
globalMenus += menu
|
||||
def addGlobalMenu(globalMenu: (Context) => Option[Link]): Unit = {
|
||||
globalMenus += globalMenu
|
||||
}
|
||||
|
||||
def getGlobalMenus: Seq[(Context) => Option[Link]] = globalMenus.toSeq
|
||||
|
||||
def addProfileTab(tab: (Account, Context) => Option[Link]): Unit = {
|
||||
profileTabs += tab
|
||||
def addRepositoryMenu(repositoryMenu: (RepositoryInfo, Context) => Option[Link]): Unit = {
|
||||
repositoryMenus += repositoryMenu
|
||||
}
|
||||
|
||||
def getRepositoryMenus: Seq[(RepositoryInfo, Context) => Option[Link]] = repositoryMenus.toSeq
|
||||
|
||||
def addProfileTab(profileTab: (Account, Context) => Option[Link]): Unit = {
|
||||
profileTabs += profileTab
|
||||
}
|
||||
|
||||
def getProfileTabs: Seq[(Account, Context) => Option[Link]] = profileTabs.toSeq
|
||||
|
||||
@@ -55,6 +55,11 @@
|
||||
@if(loginAccount.isDefined && (loginAccount.get.isAdmin || repository.managers.contains(loginAccount.get.userName))){
|
||||
@menuitem("/settings" , "settings" , "Settings")
|
||||
}
|
||||
@gitbucket.core.plugin.PluginRegistry().getRepositoryMenus.map { menu =>
|
||||
@menu(repository, context).map { link =>
|
||||
@menuitem(link.path, link.id, link.label)
|
||||
}
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="main-content">
|
||||
|
||||
Reference in New Issue
Block a user