(refs #1161)Add new extension point to add a tab to the profile page

This commit is contained in:
Naoki Takezoe
2016-04-03 03:02:06 +09:00
parent 102a02d527
commit c851b7582f
4 changed files with 37 additions and 26 deletions

View File

@@ -1,7 +1,8 @@
package gitbucket.core.plugin package gitbucket.core.plugin
import javax.servlet.ServletContext 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.service.SystemSettingsService.SystemSettings
import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.ControlUtil._
import gitbucket.core.util.Version import gitbucket.core.util.Version
@@ -80,12 +81,22 @@ abstract class Plugin {
/** /**
* Override to add global menus. * Override to add global menus.
*/ */
val globalMenus: Seq[GlobalMenu] = Nil val globalMenus: Seq[(Context) => Option[Link]] = Nil
/** /**
* Override to add global menus. * 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. * This method is invoked in initialization of plugin system.
@@ -110,8 +121,11 @@ 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 => (globalMenus ++ globalMenus(registry, context, settings)).foreach { globalMenu =>
registry.addGlobalMenu(menu) registry.addGlobalMenu(globalMenu)
}
(profileTabs ++ profileTabs(registry, context, settings)).foreach { profileTab =>
registry.addProfileTab(profileTab)
} }
} }

View File

@@ -3,11 +3,10 @@ package gitbucket.core.plugin
import java.io.{File, FilenameFilter, InputStream} import java.io.{File, FilenameFilter, InputStream}
import java.net.URLClassLoader import java.net.URLClassLoader
import javax.servlet.ServletContext import javax.servlet.ServletContext
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import gitbucket.core.controller.{Context, ControllerBase} import gitbucket.core.controller.{Context, ControllerBase}
import gitbucket.core.model.Account
import gitbucket.core.service.ProtectedBranchService.ProtectedBranchReceiveHook import gitbucket.core.service.ProtectedBranchService.ProtectedBranchReceiveHook
import gitbucket.core.service.RepositoryService.RepositoryInfo
import gitbucket.core.service.SystemSettingsService.SystemSettings import gitbucket.core.service.SystemSettingsService.SystemSettings
import gitbucket.core.util.ControlUtil._ import gitbucket.core.util.ControlUtil._
import gitbucket.core.util.Directory._ import gitbucket.core.util.Directory._
@@ -33,7 +32,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] private val globalMenus = new ListBuffer[(Context) => Option[Link]]
private val profileTabs = new ListBuffer[(Account, Context) => Option[Link]]
def addPlugin(pluginInfo: PluginInfo): Unit = { def addPlugin(pluginInfo: PluginInfo): Unit = {
plugins += pluginInfo plugins += pluginInfo
@@ -109,23 +109,17 @@ class PluginRegistry {
def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq
def addGlobalMenu(menu: GlobalMenu): Unit = { def addGlobalMenu(menu: (Context) => Option[Link]): Unit = {
globalMenus += menu globalMenus += menu
} }
def getGlobalMenus: Seq[GlobalMenu] = globalMenus.toSeq def getGlobalMenus: Seq[(Context) => Option[Link]] = globalMenus.toSeq
// private case class GlobalAction( def addProfileTab(tab: (Account, Context) => Option[Link]): Unit = {
// method: String, profileTabs += tab
// path: String, }
// function: (HttpServletRequest, HttpServletResponse, Context) => Any
// ) def getProfileTabs: Seq[(Account, Context) => Option[Link]] = profileTabs.toSeq
//
// private case class RepositoryAction(
// method: String,
// path: String,
// function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any
// )
} }
@@ -209,9 +203,7 @@ object PluginRegistry {
} }
abstract class GlobalMenu { case class Link(id: String, label: String, path: String)
def createLink(context: Context): Option[(String, String)]
}
case class PluginInfo( case class PluginInfo(
pluginId: String, pluginId: String,

View File

@@ -33,6 +33,11 @@
} else { } else {
<li@if(active == "activity"){ class="active"}><a href="@url(account.userName)?tab=activity">Public Activity</a></li> <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){ @if(loginAccount.isDefined && loginAccount.get.userName == account.userName){
<li class="pull-right"> <li class="pull-right">
<div class="button-group"> <div class="button-group">

View File

@@ -72,8 +72,8 @@
} }
} }
@gitbucket.core.plugin.PluginRegistry().getGlobalMenus.map { menu => @gitbucket.core.plugin.PluginRegistry().getGlobalMenus.map { menu =>
@menu.createLink(context).map { case (label, link) => @menu(context).map { link =>
<a href="@path/@link" class="global-header-menu">@label</a> <a href="@path/@link.path" class="global-header-menu">@link.label</a>
} }
} }
@if(loginAccount.isDefined){ @if(loginAccount.isDefined){