mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 06:55:54 +01:00
(refs #464)Add extension point to inject JavaScript instead of adding button
This commit is contained in:
@@ -397,8 +397,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
condition,
|
||||
filter,
|
||||
repository,
|
||||
hasWritePermission(owner, repoName, context.loginAccount),
|
||||
PluginSystem.buttons("issues"))
|
||||
hasWritePermission(owner, repoName, context.loginAccount))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
condition: service.IssuesService.IssueSearchCondition,
|
||||
filter: String,
|
||||
repository: service.RepositoryService.RepositoryInfo,
|
||||
hasWritePermission: Boolean,
|
||||
buttons: List[plugin.PluginSystem.Button])(implicit context: app.Context)
|
||||
hasWritePermission: Boolean)(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
@html.main(s"Issues - ${repository.owner}/${repository.name}", Some(repository)){
|
||||
@html.menu("issues", repository){
|
||||
@tab("issues", false, repository, buttons)
|
||||
@tab("issues", false, repository)
|
||||
<div class="row-fluid">
|
||||
<div class="span3">
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@(active: String, create: Boolean, repository: service.RepositoryService.RepositoryInfo,
|
||||
buttons: List[plugin.PluginSystem.Button] = Nil)(implicit context: app.Context)
|
||||
@(active: String, create: Boolean, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
|
||||
@import context._
|
||||
@import view.helpers._
|
||||
<ul class="nav nav-tabs pull-left fill-width">
|
||||
@@ -8,9 +7,6 @@
|
||||
@if(loginAccount.isDefined){
|
||||
<li class="pull-right">
|
||||
<div class="btn-group">
|
||||
@buttons.map { button =>
|
||||
<a class="btn btn-small" href="@button.href">@button.label</a>
|
||||
}
|
||||
@if(create){
|
||||
<a class="btn btn-small btn-success" href="#" disabled="disabled">New Issue</a>
|
||||
} else {
|
||||
|
||||
@@ -88,6 +88,9 @@
|
||||
$('#search').submit(function(){
|
||||
return $.trim($(this).find('input[name=query]').val()) != '';
|
||||
});
|
||||
@plugin.PluginSystem.javaScripts.filter(_.filter(context.currentPath)).map { js =>
|
||||
@Html(js.script)
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user