mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 23:15:49 +01:00
(refs #1161)Add new extension point to add a tab to the profile page
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package gitbucket.core.plugin
|
||||
|
||||
import javax.servlet.ServletContext
|
||||
import gitbucket.core.controller.ControllerBase
|
||||
import gitbucket.core.controller.{Context, ControllerBase}
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.Version
|
||||
@@ -80,12 +81,22 @@ abstract class Plugin {
|
||||
/**
|
||||
* Override to add global menus.
|
||||
*/
|
||||
val globalMenus: Seq[GlobalMenu] = Nil
|
||||
val globalMenus: Seq[(Context) => Option[Link]] = Nil
|
||||
|
||||
/**
|
||||
* Override to add global menus.
|
||||
*/
|
||||
def globalMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[GlobalMenu] = Nil
|
||||
def globalMenus(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(Context) => Option[Link]] = Nil
|
||||
|
||||
/**
|
||||
* Override to add profile tabs.
|
||||
*/
|
||||
val profileTabs: Seq[(Account, Context) => Option[Link]] = Nil
|
||||
|
||||
/**
|
||||
* Override to add profile tabs.
|
||||
*/
|
||||
def profileTabs(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[(Account, Context) => Option[Link]] = Nil
|
||||
|
||||
/**
|
||||
* This method is invoked in initialization of plugin system.
|
||||
@@ -110,8 +121,11 @@ abstract class Plugin {
|
||||
(receiveHooks ++ receiveHooks(registry, context, settings)).foreach { receiveHook =>
|
||||
registry.addReceiveHook(receiveHook)
|
||||
}
|
||||
(globalMenus ++ globalMenus(registry, context, settings)).foreach { menu =>
|
||||
registry.addGlobalMenu(menu)
|
||||
(globalMenus ++ globalMenus(registry, context, settings)).foreach { globalMenu =>
|
||||
registry.addGlobalMenu(globalMenu)
|
||||
}
|
||||
(profileTabs ++ profileTabs(registry, context, settings)).foreach { profileTab =>
|
||||
registry.addProfileTab(profileTab)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,10 @@ package gitbucket.core.plugin
|
||||
import java.io.{File, FilenameFilter, InputStream}
|
||||
import java.net.URLClassLoader
|
||||
import javax.servlet.ServletContext
|
||||
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||
|
||||
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,7 +32,8 @@ class PluginRegistry {
|
||||
private val receiveHooks = new ListBuffer[ReceiveHook]
|
||||
receiveHooks += new ProtectedBranchReceiveHook()
|
||||
|
||||
private val globalMenus = new ListBuffer[GlobalMenu]
|
||||
private val globalMenus = new ListBuffer[(Context) => Option[Link]]
|
||||
private val profileTabs = new ListBuffer[(Account, Context) => Option[Link]]
|
||||
|
||||
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
||||
plugins += pluginInfo
|
||||
@@ -109,23 +109,17 @@ class PluginRegistry {
|
||||
|
||||
def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq
|
||||
|
||||
def addGlobalMenu(menu: GlobalMenu): Unit = {
|
||||
def addGlobalMenu(menu: (Context) => Option[Link]): Unit = {
|
||||
globalMenus += menu
|
||||
}
|
||||
|
||||
def getGlobalMenus: Seq[GlobalMenu] = globalMenus.toSeq
|
||||
def getGlobalMenus: Seq[(Context) => Option[Link]] = globalMenus.toSeq
|
||||
|
||||
// private case class GlobalAction(
|
||||
// method: String,
|
||||
// path: String,
|
||||
// function: (HttpServletRequest, HttpServletResponse, Context) => Any
|
||||
// )
|
||||
//
|
||||
// private case class RepositoryAction(
|
||||
// method: String,
|
||||
// path: String,
|
||||
// function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any
|
||||
// )
|
||||
def addProfileTab(tab: (Account, Context) => Option[Link]): Unit = {
|
||||
profileTabs += tab
|
||||
}
|
||||
|
||||
def getProfileTabs: Seq[(Account, Context) => Option[Link]] = profileTabs.toSeq
|
||||
|
||||
}
|
||||
|
||||
@@ -209,9 +203,7 @@ object PluginRegistry {
|
||||
|
||||
}
|
||||
|
||||
abstract class GlobalMenu {
|
||||
def createLink(context: Context): Option[(String, String)]
|
||||
}
|
||||
case class Link(id: String, label: String, path: String)
|
||||
|
||||
case class PluginInfo(
|
||||
pluginId: String,
|
||||
|
||||
@@ -33,6 +33,11 @@
|
||||
} else {
|
||||
<li@if(active == "activity"){ class="active"}><a href="@url(account.userName)?tab=activity">Public Activity</a></li>
|
||||
}
|
||||
@gitbucket.core.plugin.PluginRegistry().getProfileTabs.map { tab =>
|
||||
@tab(account, context).map { link =>
|
||||
<li@if(active == link.id){ class="active"}><a href="@path/@link.path">@link.label</a></li>
|
||||
}
|
||||
}
|
||||
@if(loginAccount.isDefined && loginAccount.get.userName == account.userName){
|
||||
<li class="pull-right">
|
||||
<div class="button-group">
|
||||
|
||||
@@ -72,8 +72,8 @@
|
||||
}
|
||||
}
|
||||
@gitbucket.core.plugin.PluginRegistry().getGlobalMenus.map { menu =>
|
||||
@menu.createLink(context).map { case (label, link) =>
|
||||
<a href="@path/@link" class="global-header-menu">@label</a>
|
||||
@menu(context).map { link =>
|
||||
<a href="@path/@link.path" class="global-header-menu">@link.label</a>
|
||||
}
|
||||
}
|
||||
@if(loginAccount.isDefined){
|
||||
|
||||
Reference in New Issue
Block a user