-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
*.class | ||
*.log | ||
*~ | ||
|
||
# sbt specific | ||
dist/* | ||
target/ | ||
lib_managed/ | ||
src_managed/ | ||
project/boot/ | ||
project/plugins/project/ | ||
|
||
# Scala-IDE specific | ||
.scala_dependencies | ||
.classpath | ||
.project | ||
.cache | ||
.settings | ||
|
||
# IntelliJ specific | ||
.idea/ | ||
.idea_modules/ | ||
|
||
# Ensime | ||
.ensime | ||
.ensime_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
project.git = true | ||
|
||
maxColumn = 120 | ||
docstrings = JavaDoc | ||
|
||
align.tokens = ["%", "%%", {code = "=>", owner = "Case"}] | ||
align.openParenCallSite = false | ||
align.openParenDefnSite = false | ||
continuationIndent.callSite = 2 | ||
continuationIndent.defnSite = 2 | ||
danglingParentheses = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name := "gitbucket-navlink-plugin" | ||
organization := "com.github.sikebe" | ||
version := "0.0.1-SNAPSHOT" | ||
scalaVersion := "2.12.4" | ||
gitbucketVersion := "4.22.0" | ||
scalacOptions := Seq("-deprecation") | ||
javacOptions in compile ++= Seq("-source", | ||
"1.8", | ||
"-target", | ||
"1.8", | ||
"-encoding", | ||
"UTF-8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version = 1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
addSbtPlugin("io.github.gitbucket" % "sbt-gitbucket-plugin" % "1.2.0") | ||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.4.0") | ||
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import com.github.sikebe.navlink.controller.NavLinkSettingsController | ||
import com.github.sikebe.navlink.service.NavLinkSettingsService | ||
import gitbucket.core.controller.Context | ||
import gitbucket.core.plugin.Link | ||
import io.github.gitbucket.solidbase.model.Version | ||
|
||
class Plugin extends gitbucket.core.plugin.Plugin with NavLinkSettingsService { | ||
override val pluginId: String = "navlink" | ||
override val pluginName: String = "NavLink Plugin" | ||
override val description: String = "Adding NavLinks" | ||
override val versions: List[Version] = List(new Version("1.0.0")) | ||
|
||
override val controllers = Seq( | ||
"/*" -> new NavLinkSettingsController() | ||
) | ||
|
||
override val globalMenus = Seq( | ||
(_: Context) => Some(Link("navlink", navLinkSettings.globalMenuName, navLinkSettings.globalMenuPath)) | ||
) | ||
|
||
override val systemSettingMenus = Seq( | ||
(_: Context) => Some(Link("navlink", "NavLink", "navlink/settings")) | ||
) | ||
|
||
val navLinkSettings = loadNavLinkSettings() | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/scala/com/github/sikebe/navlink/controller/NavLinkSettingsController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.github.sikebe.navlink.controller | ||
|
||
import gitbucket.core.controller.ControllerBase | ||
import gitbucket.core.util.AdminAuthenticator | ||
import org.scalatra.forms._ | ||
import sikebe.gitbucket.navlink.html | ||
import com.github.sikebe.navlink.service.NavLinkSettingsService | ||
import com.github.sikebe.navlink.service.NavLinkSettingsService._ | ||
import gitbucket.core.plugin.PluginRegistry._ | ||
import gitbucket.core.util.Implicits._ | ||
|
||
class NavLinkSettingsController | ||
extends NavLinkSettingsControllerBase | ||
with NavLinkSettingsService | ||
with AdminAuthenticator | ||
|
||
trait NavLinkSettingsControllerBase extends ControllerBase { | ||
self: NavLinkSettingsService with AdminAuthenticator => | ||
|
||
val settingsForm: MappingValueType[NavLinkSettings] = mapping( | ||
"globalMenuName" -> text(required, maxlength(200)), | ||
"globalMenuPath" -> text(required, maxlength(200)) | ||
)(NavLinkSettings.apply) | ||
|
||
get("/navlink/settings")(adminOnly { | ||
val settings = loadNavLinkSettings() | ||
html.settings(settings.globalMenuName, settings.globalMenuPath, isAdmin = true) | ||
}) | ||
|
||
post("/navlink/settings", settingsForm)(adminOnly { form => | ||
assert(form.globalMenuName != null) | ||
assert(!form.globalMenuName.isEmpty) | ||
assert(form.globalMenuPath != null) | ||
assert(!form.globalMenuPath.isEmpty) | ||
|
||
saveNavLinkSettings(form) | ||
reload(request.getServletContext(), loadSystemSettings(), request2Session(request).conn) | ||
redirect("/navlink/settings") | ||
}) | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/scala/com/github/sikebe/navlink/service/NavLinkSettingsService.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.github.sikebe.navlink.service | ||
|
||
import java.io.File | ||
|
||
import gitbucket.core.util.Directory._ | ||
import gitbucket.core.util.SyntaxSugars._ | ||
import NavLinkSettingsService._ | ||
|
||
trait NavLinkSettingsService { | ||
|
||
val NavLinkConf = new File(GitBucketHome, "navlink.conf") | ||
|
||
def saveNavLinkSettings(settings: NavLinkSettings): Unit = | ||
defining(new java.util.Properties()) { props => | ||
props.setProperty(GlobalMenuName, settings.globalMenuName) | ||
props.setProperty(GlobalMenuPath, settings.globalMenuPath) | ||
using(new java.io.FileOutputStream(NavLinkConf)) { out => | ||
props.store(out, null) | ||
} | ||
} | ||
|
||
def loadNavLinkSettings(): NavLinkSettings = | ||
defining(new java.util.Properties()) { props => | ||
if (NavLinkConf.exists) { | ||
using(new java.io.FileInputStream(NavLinkConf)) { in => | ||
props.load(in) | ||
} | ||
} | ||
NavLinkSettings( | ||
getValue[String](props, GlobalMenuName, ""), | ||
getValue[String](props, GlobalMenuPath, "") | ||
) | ||
} | ||
} | ||
|
||
object NavLinkSettingsService { | ||
import scala.reflect.ClassTag | ||
|
||
case class NavLinkSettings(globalMenuName: String, globalMenuPath: String) | ||
|
||
private val GlobalMenuName = "global_menu_name" | ||
private val GlobalMenuPath = "global_menu_path" | ||
|
||
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A = | ||
defining(props.getProperty(key)) { value => | ||
if (value == null || value.isEmpty) default | ||
else convertType(value).asInstanceOf[A] | ||
} | ||
|
||
private def convertType[A: ClassTag](value: String) = | ||
defining(implicitly[ClassTag[A]].runtimeClass) { c => | ||
if (c == classOf[Boolean]) value.toBoolean | ||
else if (c == classOf[Int]) value.toInt | ||
else value | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/twirl/sikebe/gitbucket/navlink/settings.scala.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@(name: String, path: String, isAdmin: Boolean)(implicit context: gitbucket.core.controller.Context) | ||
@gitbucket.core.html.main("NavLink Setting", None){ | ||
@sikebe.gitbucket.navlink.html.sidebar("settings", isAdmin){ | ||
<div class="content-wrapper"> | ||
<div class="content body"> | ||
<form id="form" method="post" action="@context.path/navlink/settings" validate="true"> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading strong">Settings for NavLink</div> | ||
<div class="panel-body"> | ||
<fieldset class="form-group"> | ||
<label for="globalMenuName" class="strong">Global Menu Name:</label> | ||
<input type="text" name="globalMenuName" id="globalMenuName" class="form-control" value="@name"/> | ||
</fieldset> | ||
<fieldset class="border-top form-group"> | ||
<label for="globalMenuPath" class="strong">Relative Path (e.g. <code>navlink/settings</code>):</label> | ||
<input type="text" name="globalMenuPath" id="globalMenuPath" class="form-control" value="@path"/> | ||
</fieldset> | ||
<div class="align-right" style="margin-top: 20px;"> | ||
<input type="submit" class="btn btn-success" value="Apply changes"/> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
}} |
16 changes: 16 additions & 0 deletions
16
src/main/twirl/sikebe/gitbucket/navlink/sidebar.scala.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@(active: String, isAdmin: Boolean)(body: Html)(implicit context: gitbucket.core.controller.Context) | ||
<div class="main-sidebar"> | ||
<div class="sidebar"> | ||
<ul class="sidebar-menu"> | ||
@if(isAdmin) { | ||
<li @if(active == "settings") { | ||
class="active"}> | ||
<a href="@context.path/navlink/settings"> | ||
<i class="menu-icon octicon octicon-tools"></i> Settings | ||
</a> | ||
</li> | ||
} | ||
</ul> | ||
</div> | ||
</div> | ||
@body |