mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-04 20:45:58 +01:00
(refs #32)First impression of the plugin system
This commit is contained in:
35
src/main/scala/plugin/PluginSystem.scala
Normal file
35
src/main/scala/plugin/PluginSystem.scala
Normal file
@@ -0,0 +1,35 @@
|
||||
package plugin
|
||||
|
||||
import app.Context
|
||||
|
||||
/**
|
||||
* Provides extension points to plug-ins.
|
||||
*/
|
||||
object PluginSystem {
|
||||
|
||||
private val repositoryMenuList = scala.collection.mutable.ListBuffer[Menu]()
|
||||
private val globalMenuList = scala.collection.mutable.ListBuffer[Menu]()
|
||||
|
||||
case class Menu(label: String, url: String, icon: String, condition: Context => Boolean)
|
||||
|
||||
def addRepositoryMenu(label: String, url: String, icon: String = "")(condition: Context => Boolean): Unit = {
|
||||
repositoryMenuList += Menu(label, url, icon, condition)
|
||||
}
|
||||
|
||||
def addGlobalMenu(label: String, url: String, icon: String = "")(condition: Context => Boolean): Unit = {
|
||||
globalMenuList += Menu(label, url, icon, condition)
|
||||
}
|
||||
|
||||
def addAction(path: String): Unit = {
|
||||
// TODO
|
||||
}
|
||||
|
||||
def repositoryMenus: List[Menu] = repositoryMenuList.toList
|
||||
def globalMenus: List[Menu] = globalMenuList.toList
|
||||
|
||||
// TODO This is a test
|
||||
addGlobalMenu("Google", "http://www.google.co.jp/"){ context => context.loginAccount.isDefined }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -60,11 +60,21 @@
|
||||
<li><a href="@path/groups/new">New group</a></li>
|
||||
</ul>
|
||||
<a href="@url(loginAccount.get.userName)/_edit" class="menu" data-toggle="tooltip" data-placement="bottom" title="Account settings"><i class="icon-user"></i></a>
|
||||
@plugin.PluginSystem.globalMenus.map { menu =>
|
||||
@if(menu.condition(context)){
|
||||
<a href="@menu.url" class="menu" data-toggle="tooltip" data-placement="bottom" title="@menu.label">@menu.label</a>
|
||||
}
|
||||
}
|
||||
@if(loginAccount.get.isAdmin){
|
||||
<a href="@path/admin/users" class="menu" data-toggle="tooltip" data-placement="bottom" title="Administration"><i class="icon-wrench"></i></a>
|
||||
}
|
||||
<a href="@path/signout" class="menu-last" data-toggle="tooltip" data-placement="bottom" title="Sign out"><i class="icon-share-alt"></i></a>
|
||||
} else {
|
||||
@plugin.PluginSystem.globalMenus.map { menu =>
|
||||
@if(menu.condition(context)){
|
||||
<a href="@menu.url" class="menu" data-toggle="tooltip" data-placement="bottom" title="@menu.label">@menu.label</a>
|
||||
}
|
||||
}
|
||||
<a href="@path/signin?redirect=@urlEncode(currentPath)" class="btn btn-last" id="signin">Sign in</a>
|
||||
}
|
||||
</div><!--/.nav-collapse -->
|
||||
|
||||
Reference in New Issue
Block a user