(refs #1161)Add new extension point to add global menu

This commit is contained in:
Naoki Takezoe
2016-04-03 00:50:57 +09:00
parent 1968bf871a
commit 102a02d527
3 changed files with 40 additions and 10 deletions

View File

@@ -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)
}
} }
/** /**

View File

@@ -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,

View File

@@ -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;">