mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
(refs #464)Add extension point to inject JavaScript instead of adding button
This commit is contained in:
@@ -14,7 +14,7 @@ trait Plugin {
|
||||
def globalMenus : List[GlobalMenu]
|
||||
def repositoryActions : List[RepositoryAction]
|
||||
def globalActions : List[Action]
|
||||
def buttons(name: String) : List[Button]
|
||||
def javaScripts : List[JavaScript]
|
||||
}
|
||||
|
||||
object PluginConnectionHolder {
|
||||
|
||||
@@ -85,7 +85,7 @@ object PluginSystem {
|
||||
def globalMenus : List[GlobalMenu] = pluginsMap.values.flatMap(_.globalMenus).toList
|
||||
def repositoryActions : List[RepositoryAction] = pluginsMap.values.flatMap(_.repositoryActions).toList
|
||||
def globalActions : List[Action] = pluginsMap.values.flatMap(_.globalActions).toList
|
||||
def buttons(name: String) : List[Button] = pluginsMap.values.flatMap(_.buttons(name)).toList
|
||||
def javaScripts : List[JavaScript] = pluginsMap.values.flatMap(_.javaScripts).toList
|
||||
|
||||
// Case classes to hold plug-ins information internally in GitBucket
|
||||
case class PluginRepository(id: String, url: String)
|
||||
@@ -94,6 +94,7 @@ object PluginSystem {
|
||||
case class Action(path: String, function: (HttpServletRequest, HttpServletResponse) => Any)
|
||||
case class RepositoryAction(path: String, function: (HttpServletRequest, HttpServletResponse, RepositoryInfo) => Any)
|
||||
case class Button(label: String, href: String)
|
||||
case class JavaScript(filter: String => Boolean, script: String)
|
||||
|
||||
/**
|
||||
* Checks whether the plugin is updatable.
|
||||
|
||||
@@ -18,13 +18,13 @@ class ScalaPlugin(val id: String, val version: String,
|
||||
private val globalMenuList = ListBuffer[GlobalMenu]()
|
||||
private val repositoryActionList = ListBuffer[RepositoryAction]()
|
||||
private val globalActionList = ListBuffer[Action]()
|
||||
private val buttonMap = MutableMap[String, ListBuffer[Button]]()
|
||||
private val javaScriptList = ListBuffer[JavaScript]()
|
||||
|
||||
def repositoryMenus : List[RepositoryMenu] = repositoryMenuList.toList
|
||||
def globalMenus : List[GlobalMenu] = globalMenuList.toList
|
||||
def repositoryActions : List[RepositoryAction] = repositoryActionList.toList
|
||||
def globalActions : List[Action] = globalActionList.toList
|
||||
def buttons(name: String) : List[Button] = buttonMap.get(name).map(_.toList).getOrElse(Nil)
|
||||
def javaScripts : List[JavaScript] = javaScriptList.toList
|
||||
|
||||
def addRepositoryMenu(label: String, name: String, url: String, icon: String)(condition: (Context) => Boolean): Unit = {
|
||||
repositoryMenuList += RepositoryMenu(label, name, url, icon, condition)
|
||||
@@ -42,12 +42,8 @@ class ScalaPlugin(val id: String, val version: String,
|
||||
repositoryActionList += RepositoryAction(path, function)
|
||||
}
|
||||
|
||||
def addButton(name: String, label: String, href: String): Unit = {
|
||||
if(!buttonMap.contains(name)){
|
||||
buttonMap.put(name, ListBuffer[Button]())
|
||||
}
|
||||
val list = buttonMap(name)
|
||||
list += Button(label, href)
|
||||
def addJavaScript(filter: String => Boolean, script: String): Unit = {
|
||||
javaScriptList += JavaScript(filter, script)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user