Skip to content

Commit d0f662b

Browse files
committed
Adjust layout to GitBucket new UI and add user profile page
1 parent a2e35bb commit d0f662b

11 files changed

+71
-39
lines changed

install-local.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
./sbt.sh package
3+
cp target/scala-2.11/gitbucket-gist-plugin_2.11-3.13.0.jar ~/.gitbucket/plugins/

project/build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object MyBuild extends Build {
2626
"amateras-snapshot-repo" at "http://amateras.sourceforge.jp/mvn-snapshot/"
2727
),
2828
libraryDependencies ++= Seq(
29-
"gitbucket" % "gitbucket-assembly" % "3.12.0" % "provided",
29+
"gitbucket" % "gitbucket-assembly" % "3.13.0" % "provided",
3030
"com.typesafe.play" %% "twirl-compiler" % "1.0.4" % "provided",
3131
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
3232
),

src/main/scala/Plugin.scala

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,16 @@ class Plugin extends gitbucket.core.plugin.Plugin {
4949
val path = settings.baseUrl.getOrElse(context.getContextPath)
5050
Seq(
5151
".*" -> s"""
52-
|$$('a.global-header-menu:last').after(
53-
| $$('<a href="${path}/gist" class="global-header-menu">Gist</a>')
52+
|$$('a.global-header-menu:last, nav.navbar input[name=query], a.navbar-brand').last().after(
53+
| $$('<a href="${path}/gist" class="global-header-menu">Snippets</a>')
5454
|);
55+
|var accountName = $$('div.account-username').text();
56+
|if(accountName != ''){
57+
| var active = location.href.endsWith('_profile');
58+
| $$('li:has(a:contains(Public Activity))').after(
59+
| $$('<li' + (active ? ' class="active"' : '') + '><a href="${path}/gist/' + accountName + '/_profile">Snippets</a></li>')
60+
| );
61+
|}
5562
""".stripMargin
5663
)
5764
}

src/main/scala/gitbucket/gist/controller/GistController.scala

+19-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ trait GistControllerBase extends ControllerBase {
8181
val files: Seq[(String, JGitUtil.ContentInfo)] = JGitUtil.getFileList(git, "master", ".").map { file =>
8282
(if(isGistFile(file.name)) "" else file.name) -> JGitUtil.getContentInfo(git, file.name, file.id)
8383
}
84-
html.edit(Nil, getGist(userName, repoName), files)
84+
html.edit(getGist(userName, repoName), files)
8585
}
8686
}
8787
})
@@ -278,13 +278,28 @@ trait GistControllerBase extends ControllerBase {
278278
}
279279
}
280280

281+
get("/gist/:userName/_profile"){
282+
val userName = params("userName")
283+
284+
val result: (Seq[Gist], Int) = (
285+
getUserGists(userName, context.loginAccount.map(_.userName), 0, Limit),
286+
countUserGists(userName, context.loginAccount.map(_.userName))
287+
)
288+
getAccountByUserName(userName).map { account =>
289+
html.profile(
290+
account,
291+
if(account.isGroupAccount) Nil else getGroupsByUserName(userName),
292+
result._1
293+
)
294+
} getOrElse NotFound
295+
}
296+
281297
get("/gist/:userName"){
282298
_gist(params("userName"))
283299
}
284300

285301
get("/gist/_new")(usersOnly {
286-
val gists = getRecentGists(context.loginAccount.get.userName, 0, 4)
287-
html.edit(gists, None, Seq(("", JGitUtil.ContentInfo("text", None, Some("UTF-8")))))
302+
html.edit(None, Seq(("", JGitUtil.ContentInfo("text", None, Some("UTF-8")))))
288303
})
289304

290305
get("/gist/_add"){
@@ -426,6 +441,7 @@ trait GistControllerBase extends ControllerBase {
426441
//
427442
////////////////////////////////////////////////////////////////////////////////
428443

444+
429445
private def _gist(userName: String, repoName: Option[String] = None, revision: String = "master"): Html = {
430446
repoName match {
431447
case None => {

src/main/twirl/gitbucket/gist/detail.scala.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@gitbucket.gist.html.header(gist, forkedCount, editable)
1313
<div class="container body">
1414
@gitbucket.gist.html.menu("code", gist, repositoryUrl)
15-
<div style="margin-right: 180px;">
15+
<div style="margin-right: 260px;">
1616
<div style="margin-bottom: 10px;">
1717
@gist.description
1818
</div>

src/main/twirl/gitbucket/gist/edit.scala.html

+7-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
1-
@(recent: Seq[gitbucket.gist.model.Gist],
2-
gist: Option[gitbucket.gist.model.Gist],
1+
@(gist: Option[gitbucket.gist.model.Gist],
32
files: Seq[(String, gitbucket.core.util.JGitUtil.ContentInfo)])(implicit context: gitbucket.core.controller.Context)
43
@import context._
54
@import gitbucket.core.view.helpers._
65
@gitbucket.core.html.main("Snippets"){
6+
@gitbucket.gist.html.style()
77
<div class="container head">
88
<div id="error"></div>
99
@if(gist.isEmpty){
10-
<div>
11-
<ul style="list-style: none; margin-left: 0px; padding-left: 0px;">
12-
@recent.map { gist =>
13-
<li style="float: left; width: 200px;">
14-
<i class="octicon octicon-gist" style="width: 24px; height: 24px;"></i>
15-
<div style="margin-left: 26px; font-size: 90%; position: relative; top: -24px; line-height: normal; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
16-
<a class="strong" href="@path/gist/@gist.userName/@gist.repositoryName">@gist.title</a><br>
17-
@if(gist.description.nonEmpty){
18-
<span class="muted">@gist.description</span>
19-
} else {
20-
<span style="color: #dddddd;">No description.</span>
21-
}
22-
</div>
23-
</li>
24-
}
25-
</ul>
26-
<div class="pull-right">
27-
<a href="@path/gist/@context.loginAccount.get.userName" class="btn btn-default">Your Snippets</a>
28-
</div>
29-
</div>
10+
<h1 style="margin: 0px;">New snippet</h1>
3011
} else {
3112
@gist.map { x =>
3213
@avatar(gist.get.userName, 24)
@@ -41,18 +22,18 @@
4122
} else {
4223
<a href="@path/gist/@gist.get.userName/@gist.get.repositoryName/secret" class="btn btn-default">Make secret</a>
4324
}
44-
<a href="@path/gist/@gist.get.userName/@gist.get.repositoryName/delete" class="btn btn-default" id="delete">Delete</a>
25+
<a href="@path/gist/@gist.get.userName/@gist.get.repositoryName/delete" class="btn btn-danger" id="delete">Delete</a>
4526
</div>
46-
<div class="muted" style="margin-top: -10px; margin-left: 30px;">
27+
<div class="muted" style="margin-left: 30px; font-size: 80%;">
4728
Created at @gist.get.registeredDate
4829
</div>
4930
}
5031
}
5132
</div>
5233
<hr style="margin-bottom: 20px;"/>
5334
<div class="container body">
54-
<form id="form" method="POST" action="#" class="form-inline">
55-
<input type="text" name="description" id="description" class="form-control" style="width: 950px; margin-bottom: 8px;" value="@gist.map(_.description)" placeholder="Snippet descriptions..."/>
35+
<form id="form" method="POST" action="#">
36+
<input type="text" name="description" id="description" class="form-control" style="margin-bottom: 8px;" value="@gist.map(_.description)" placeholder="Snippet descriptions..."/>
5637
<div id="editors">
5738
@files.zipWithIndex.map { case ((fileName, content), i) =>
5839
@gitbucket.gist.html.editor(i, fileName, content)

src/main/twirl/gitbucket/gist/forks.scala.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@gitbucket.gist.html.header(gist, forkedCount, editable)
1111
<div class="container body">
1212
@gitbucket.gist.html.menu("forks", gist, repositoryUrl)
13-
<div style="margin-right: 180px;">
13+
<div style="margin-right: 260px;">
1414
@forkedGists.map { forkedGist =>
1515
<div class="block">
1616
@avatar(forkedGist.userName, 20)

src/main/twirl/gitbucket/gist/list.scala.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
@gitbucket.gist.html.style()
99
<div class="container head">
1010
@if(gistUser.isEmpty){
11-
Discover Snippets
1211
<div class="pull-right">
1312
<a href="@path/gist/_new" class="btn btn-success">New snippet</a>
1413
</div>
14+
<h1 style="margin-top: 0px;">Discover Snippets</h1>
1515
} else {
1616
@avatar(gistUser.get.userName, 24)
1717
<span class="strong">@gistUser.get.fullName</span>
@@ -50,7 +50,7 @@
5050
</div>
5151
</div>
5252
<div class="panel-body">
53-
<div class="small" style="margin-left: 22px; margin-top: 2px; margin-bottom: 2px;">
53+
<div style="margin-bottom: 10px;">
5454
@gist.description
5555
</div>
5656
<div>

src/main/twirl/gitbucket/gist/menu.scala.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</li>
1717
}
1818

19-
<div style="width: 170px;" class="pull-right">
19+
<div style="width: 250px;" class="pull-right">
2020
<ul class="nav nav-pills nav-stacked">
2121
<li style="height: 12px"><div class="gradient pull-left" style="height: 12px"></div></li>
2222
@menuitem(
@@ -47,7 +47,7 @@
4747
}
4848
<div style="margin-top: 10px;">
4949
<a href="@path/gist/@{gist.userName}/@{gist.repositoryName}/download/@{gist.repositoryName}.zip"
50-
class="btn btn-default" style="width: 170px;"><i class="icon-download-alt"></i>Download ZIP</a>
50+
class="btn btn-default btn-block"><i class="icon-download-alt"></i>Download ZIP</a>
5151
</div>
5252
</div>
5353
@if(settings.ssh && loginAccount.isDefined){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@(account: gitbucket.core.model.Account, groupNames: List[String],
2+
gists: Seq[gitbucket.gist.model.Gist])(implicit context: gitbucket.core.controller.Context)
3+
@gitbucket.core.account.html.main(account, groupNames, "snippets"){
4+
@if(gists.isEmpty){
5+
No snippets
6+
} else {
7+
@gists.map { gist =>
8+
<div class="block">
9+
<div class="repository-icon">
10+
<i class="mega-octicon octicon-gist"></i>
11+
</div>
12+
<div class="repository-content">
13+
<div class="block-header">
14+
<a href="@context.path/gist/@gist.userName/@gist.repositoryName">@gist.title</a>
15+
@if(gist.isPrivate){
16+
<span class="label label-warning">Secret</span>
17+
}
18+
</div>
19+
<div>@gist.description</div>
20+
<div><span class="muted small">Updated @gitbucket.core.helper.html.datetimeago(gist.updatedDate)</span></div>
21+
</div>
22+
</div>
23+
}
24+
}
25+
}

src/main/twirl/gitbucket/gist/revisions.scala.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@gitbucket.gist.html.header(gist, forkedCount, editable)
1313
<div class="container body">
1414
@gitbucket.gist.html.menu("revision", gist, repositoryUrl)
15-
<div style="margin-right: 180px;">
15+
<div style="margin-right: 260px;">
1616
@revisions.map { case (revision, diffs) =>
1717
<div>
1818
<div style="margin-bottom: 8px;">

0 commit comments

Comments
 (0)