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 global menu
This commit is contained in:
@@ -77,6 +77,16 @@ abstract class Plugin {
|
|||||||
*/
|
*/
|
||||||
def receiveHooks(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[ReceiveHook] = Nil
|
def receiveHooks(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[ReceiveHook] = Nil
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override to add global menus.
|
||||||
|
*/
|
||||||
|
val globalMenus: Seq[GlobalMenu] = Nil
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override to add global menus.
|
||||||
|
*/
|
||||||
|
def globalMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[GlobalMenu] = Nil
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is invoked in initialization of plugin system.
|
* This method is invoked in initialization of plugin system.
|
||||||
* Register plugin functionality to PluginRegistry.
|
* Register plugin functionality to PluginRegistry.
|
||||||
@@ -100,6 +110,9 @@ abstract class Plugin {
|
|||||||
(receiveHooks ++ receiveHooks(registry, context, settings)).foreach { receiveHook =>
|
(receiveHooks ++ receiveHooks(registry, context, settings)).foreach { receiveHook =>
|
||||||
registry.addReceiveHook(receiveHook)
|
registry.addReceiveHook(receiveHook)
|
||||||
}
|
}
|
||||||
|
(globalMenus ++ globalMenus(registry, context, settings)).foreach { menu =>
|
||||||
|
registry.addGlobalMenu(menu)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ class PluginRegistry {
|
|||||||
private val receiveHooks = new ListBuffer[ReceiveHook]
|
private val receiveHooks = new ListBuffer[ReceiveHook]
|
||||||
receiveHooks += new ProtectedBranchReceiveHook()
|
receiveHooks += new ProtectedBranchReceiveHook()
|
||||||
|
|
||||||
|
private val globalMenus = new ListBuffer[GlobalMenu]
|
||||||
|
|
||||||
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
||||||
plugins += pluginInfo
|
plugins += pluginInfo
|
||||||
}
|
}
|
||||||
@@ -107,17 +109,23 @@ class PluginRegistry {
|
|||||||
|
|
||||||
def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq
|
def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq
|
||||||
|
|
||||||
private case class GlobalAction(
|
def addGlobalMenu(menu: GlobalMenu): Unit = {
|
||||||
method: String,
|
globalMenus += menu
|
||||||
path: String,
|
}
|
||||||
function: (HttpServletRequest, HttpServletResponse, Context) => Any
|
|
||||||
)
|
|
||||||
|
|
||||||
private case class RepositoryAction(
|
def getGlobalMenus: Seq[GlobalMenu] = globalMenus.toSeq
|
||||||
method: String,
|
|
||||||
path: String,
|
// private case class GlobalAction(
|
||||||
function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any
|
// method: String,
|
||||||
)
|
// path: String,
|
||||||
|
// function: (HttpServletRequest, HttpServletResponse, Context) => Any
|
||||||
|
// )
|
||||||
|
//
|
||||||
|
// private case class RepositoryAction(
|
||||||
|
// method: String,
|
||||||
|
// path: String,
|
||||||
|
// function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any
|
||||||
|
// )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +209,10 @@ object PluginRegistry {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class GlobalMenu {
|
||||||
|
def createLink(context: Context): Option[(String, String)]
|
||||||
|
}
|
||||||
|
|
||||||
case class PluginInfo(
|
case class PluginInfo(
|
||||||
pluginId: String,
|
pluginId: String,
|
||||||
pluginName: String,
|
pluginName: String,
|
||||||
|
|||||||
@@ -71,6 +71,11 @@
|
|||||||
<input type="hidden" name="repository" value="@repository.name"/>
|
<input type="hidden" name="repository" value="@repository.name"/>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@gitbucket.core.plugin.PluginRegistry().getGlobalMenus.map { menu =>
|
||||||
|
@menu.createLink(context).map { case (label, link) =>
|
||||||
|
<a href="@path/@link" class="global-header-menu">@label</a>
|
||||||
|
}
|
||||||
|
}
|
||||||
@if(loginAccount.isDefined){
|
@if(loginAccount.isDefined){
|
||||||
<div class="pull-right" style="margin-top: 6px;">
|
<div class="pull-right" style="margin-top: 6px;">
|
||||||
<div class="btn-group" style="margin-right: 8px;">
|
<div class="btn-group" style="margin-right: 8px;">
|
||||||
|
|||||||
Reference in New Issue
Block a user