Skip to content

Commit 3e83d0b

Browse files
committed
Change routing
1 parent 459883a commit 3e83d0b

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed

Diff for: src/main/scala/gitbucket/gist/controller/GistController.scala

+22-28
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,23 @@ trait GistControllerBase extends ControllerBase {
4545
////////////////////////////////////////////////////////////////////////////////
4646

4747
get("/gist"){
48-
if(context.loginAccount.isDefined){
49-
val gists = getRecentGists(context.loginAccount.get.userName, 0, 4)
50-
html.edit(gists, None, Seq(("", JGitUtil.ContentInfo("text", None, Some("UTF-8")))))
51-
} else _discoverGists()
48+
val page = request.getParameter("page") match {
49+
case ""|null => 1
50+
case s => s.toInt
51+
}
52+
val result = getVisibleGists((page - 1) * Limit, Limit, None)
53+
val count = countPublicGists()
54+
55+
val gists: Seq[(Gist, GistInfo)] = result.map { gist =>
56+
val userName = gist.userName
57+
val repoName = gist.repositoryName
58+
val files = getGistFiles(userName, repoName)
59+
val (fileName, source) = files.head
60+
61+
(gist, GistInfo(fileName, getLines(source), files.length, getForkedCount(userName, repoName), getCommentCount(userName, repoName)))
62+
}
63+
64+
html.list(None, gists, page, page * Limit < count)
5265
}
5366

5467
get("/gist/:userName/:repoName"){
@@ -265,20 +278,20 @@ trait GistControllerBase extends ControllerBase {
265278
}
266279
}
267280

268-
269281
get("/gist/:userName"){
270282
_gist(params("userName"))
271283
}
272284

285+
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")))))
288+
})
289+
273290
get("/gist/_add"){
274291
val count = params("count").toInt
275292
html.editor(count, "", JGitUtil.ContentInfo("text", None, Some("UTF-8")))
276293
}
277294

278-
get("/gist/discover"){
279-
_discoverGists()
280-
}
281-
282295
////////////////////////////////////////////////////////////////////////////////
283296
//
284297
// Fork Actions
@@ -413,25 +426,6 @@ trait GistControllerBase extends ControllerBase {
413426
// Private Methods
414427
//
415428
////////////////////////////////////////////////////////////////////////////////
416-
private def _discoverGists(): Html = {
417-
val page = request.getParameter("page") match {
418-
case ""|null => 1
419-
case s => s.toInt
420-
}
421-
val result = getVisibleGists((page - 1) * Limit, Limit, None)
422-
val count = countPublicGists()
423-
424-
val gists: Seq[(Gist, GistInfo)] = result.map { gist =>
425-
val userName = gist.userName
426-
val repoName = gist.repositoryName
427-
val files = getGistFiles(userName, repoName)
428-
val (fileName, source) = files.head
429-
430-
(gist, GistInfo(fileName, getLines(source), files.length, getForkedCount(userName, repoName), getCommentCount(userName, repoName)))
431-
}
432-
433-
html.list(None, gists, page, page * Limit < count)
434-
}
435429

436430
private def _gist(userName: String, repoName: Option[String] = None, revision: String = "master"): Html = {
437431
repoName match {

Diff for: src/main/twirl/gitbucket/gist/edit.scala.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<hr style="margin-bottom: 20px;"/>
5555
<div class="container body">
5656
<form id="form" method="POST" action="#" class="form-inline">
57-
<input type="text" name="description" id="description" class="form-control input-lg" style="width: 900px; margin-bottom: 8px;" value="@gist.map(_.description)" placeholder="Snippet descriptions..."/>
57+
<input type="text" name="description" id="description" class="form-control input-lg" style="width: 950px; margin-bottom: 8px;" value="@gist.map(_.description)" placeholder="Snippet descriptions..."/>
5858
<div id="editors">
5959
@files.zipWithIndex.map { case ((fileName, content), i) =>
6060
@gitbucket.gist.html.editor(i, fileName, content)

Diff for: src/main/twirl/gitbucket/gist/list.scala.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
@gitbucket.gist.html.style()
99
<div class="container">
1010
@if(gistUser.isEmpty){
11-
<div class="head">Discover Snippets</div>
11+
<div class="head">
12+
Discover Snippets
13+
<div class="pull-right">
14+
<a href="@path/gist/_new" class="btn btn-default">New snippet</a>
15+
</div>
16+
</div>
1217
} else {
1318
<div class="head">
1419
@avatar(gistUser.get.userName, 24)

0 commit comments

Comments
 (0)