mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 18:05:50 +01:00
(refs #79)Wiki page search is available
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.api._
|
|
||||||
import gitbucket.core.helper.xml
|
import gitbucket.core.helper.xml
|
||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service.{RepositoryService, ActivityService, AccountService, RepositorySearchService, IssuesService}
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.ControlUtil._
|
import gitbucket.core.util.ControlUtil._
|
||||||
import gitbucket.core.util.{LDAPUtil, Keys, UsersAuthenticator, ReferrerAuthenticator, StringUtil}
|
import gitbucket.core.util.{LDAPUtil, Keys, UsersAuthenticator, ReferrerAuthenticator, StringUtil}
|
||||||
@@ -138,13 +137,21 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
target.toLowerCase match {
|
target.toLowerCase match {
|
||||||
case "issue" => gitbucket.core.search.html.issues(
|
case "issue" => gitbucket.core.search.html.issues(
|
||||||
searchIssues(repository.owner, repository.name, query),
|
|
||||||
countFiles(repository.owner, repository.name, query),
|
countFiles(repository.owner, repository.name, query),
|
||||||
|
searchIssues(repository.owner, repository.name, query),
|
||||||
|
countWikiPages(repository.owner, repository.name, query),
|
||||||
|
query, page, repository)
|
||||||
|
|
||||||
|
case "wiki" => gitbucket.core.search.html.wiki(
|
||||||
|
countFiles(repository.owner, repository.name, query),
|
||||||
|
countIssues(repository.owner, repository.name, query),
|
||||||
|
searchWikiPages(repository.owner, repository.name, query),
|
||||||
query, page, repository)
|
query, page, repository)
|
||||||
|
|
||||||
case _ => gitbucket.core.search.html.code(
|
case _ => gitbucket.core.search.html.code(
|
||||||
searchFiles(repository.owner, repository.name, query),
|
searchFiles(repository.owner, repository.name, query),
|
||||||
countIssues(repository.owner, repository.name, query),
|
countIssues(repository.owner, repository.name, query),
|
||||||
|
countWikiPages(repository.owner, repository.name, query),
|
||||||
query, page, repository)
|
query, page, repository)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import org.eclipse.jgit.api.Git
|
|||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
class WikiController extends WikiControllerBase
|
class WikiController extends WikiControllerBase
|
||||||
with WikiService with RepositoryService with AccountService with ActivityService with CollaboratorsAuthenticator with ReferrerAuthenticator
|
with WikiService with RepositoryService with AccountService with ActivityService
|
||||||
|
with CollaboratorsAuthenticator with ReferrerAuthenticator
|
||||||
|
|
||||||
trait WikiControllerBase extends ControllerBase {
|
trait WikiControllerBase extends ControllerBase {
|
||||||
self: WikiService with RepositoryService with ActivityService with CollaboratorsAuthenticator with ReferrerAuthenticator =>
|
self: WikiService with RepositoryService with ActivityService with CollaboratorsAuthenticator with ReferrerAuthenticator =>
|
||||||
|
|||||||
@@ -53,7 +53,30 @@ trait RepositorySearchService { self: IssuesService =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def searchRepositoryFiles(git: Git, query: String): List[(String, String)] = {
|
def countWikiPages(owner: String, repository: String, query: String): Int =
|
||||||
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
|
if(JGitUtil.isEmpty(git)) 0 else searchRepositoryFiles(git, query).length
|
||||||
|
}
|
||||||
|
|
||||||
|
def searchWikiPages(owner: String, repository: String, query: String): List[FileSearchResult] =
|
||||||
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
|
if(JGitUtil.isEmpty(git)){
|
||||||
|
Nil
|
||||||
|
} else {
|
||||||
|
val files = searchRepositoryFiles(git, query)
|
||||||
|
val commits = JGitUtil.getLatestCommitFromPaths(git, files.map(_._1), "HEAD")
|
||||||
|
files.map { case (path, text) =>
|
||||||
|
val (highlightText, lineNumber) = getHighlightText(text, query)
|
||||||
|
FileSearchResult(
|
||||||
|
path.replaceFirst("\\.md$", ""),
|
||||||
|
commits(path).getCommitterIdent.getWhen,
|
||||||
|
highlightText,
|
||||||
|
lineNumber)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def searchRepositoryFiles(git: Git, query: String): List[(String, String)] = {
|
||||||
val revWalk = new RevWalk(git.getRepository)
|
val revWalk = new RevWalk(git.getRepository)
|
||||||
val objectId = git.getRepository.resolve("HEAD")
|
val objectId = git.getRepository.resolve("HEAD")
|
||||||
val revCommit = revWalk.parseCommit(objectId)
|
val revCommit = revWalk.parseCommit(objectId)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
@(files: List[gitbucket.core.service.RepositorySearchService.FileSearchResult],
|
@(files: List[gitbucket.core.service.RepositorySearchService.FileSearchResult],
|
||||||
issueCount: Int,
|
issueCount: Int,
|
||||||
|
wikiCount: Int,
|
||||||
query: String,
|
query: String,
|
||||||
page: Int,
|
page: Int,
|
||||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||||
@@ -7,7 +8,7 @@
|
|||||||
@import gitbucket.core.view.helpers._
|
@import gitbucket.core.view.helpers._
|
||||||
@import gitbucket.core.service.RepositorySearchService._
|
@import gitbucket.core.service.RepositorySearchService._
|
||||||
@html.main("Search Results", Some(repository)){
|
@html.main("Search Results", Some(repository)){
|
||||||
@menu("code", files.size, issueCount, query, repository){
|
@menu("code", files.size, issueCount, wikiCount, query, repository){
|
||||||
@if(files.isEmpty){
|
@if(files.isEmpty){
|
||||||
<h4>We couldn't find any code matching '@query'</h4>
|
<h4>We couldn't find any code matching '@query'</h4>
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
@(issues: List[gitbucket.core.service.RepositorySearchService.IssueSearchResult],
|
@(fileCount: Int,
|
||||||
fileCount: Int,
|
issues: List[gitbucket.core.service.RepositorySearchService.IssueSearchResult],
|
||||||
|
wikiCount: Int,
|
||||||
query: String,
|
query: String,
|
||||||
page: Int,
|
page: Int,
|
||||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||||
@@ -7,7 +8,7 @@
|
|||||||
@import gitbucket.core.view.helpers._
|
@import gitbucket.core.view.helpers._
|
||||||
@import gitbucket.core.service.RepositorySearchService._
|
@import gitbucket.core.service.RepositorySearchService._
|
||||||
@html.main("Search Results", Some(repository)){
|
@html.main("Search Results", Some(repository)){
|
||||||
@menu("issue", fileCount, issues.size, query, repository){
|
@menu("issue", fileCount, issues.size, wikiCount, query, repository){
|
||||||
@if(issues.isEmpty){
|
@if(issues.isEmpty){
|
||||||
<h4>We couldn't find any code matching '@query'</h4>
|
<h4>We couldn't find any code matching '@query'</h4>
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
@(active: String, fileCount: Int, issueCount: Int, query: String,
|
@(active: String, fileCount: Int, issueCount: Int, wikiCount: Int, query: String,
|
||||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(body: Html)(implicit context: gitbucket.core.controller.Context)
|
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(body: Html)(implicit context: gitbucket.core.controller.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import gitbucket.core.view.helpers._
|
@import gitbucket.core.view.helpers._
|
||||||
@@ -21,6 +21,14 @@
|
|||||||
}
|
}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li@if(active=="wiki"){ class="active"}>
|
||||||
|
<a href="@url(repository)/search?q=@urlEncode(query)&type=wiki">
|
||||||
|
Wiki
|
||||||
|
@if(wikiCount != 0){
|
||||||
|
<span class="badge">@wikiCount</span>
|
||||||
|
}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<form action="@url(repository)/search" method="GET" class="form-inline">
|
<form action="@url(repository)/search" method="GET" class="form-inline">
|
||||||
<input type="text" name="q" value="@query" class="form-control" style="width: 400px; margin-bottom: 0px;"/>
|
<input type="text" name="q" value="@query" class="form-control" style="width: 400px; margin-bottom: 0px;"/>
|
||||||
|
|||||||
27
src/main/twirl/gitbucket/core/search/wiki.scala.html
Normal file
27
src/main/twirl/gitbucket/core/search/wiki.scala.html
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
@(fileCount: Int,
|
||||||
|
issueCount: Int,
|
||||||
|
wikis: List[gitbucket.core.service.RepositorySearchService.FileSearchResult],
|
||||||
|
query: String,
|
||||||
|
page: Int,
|
||||||
|
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||||
|
@import context._
|
||||||
|
@import gitbucket.core.view.helpers._
|
||||||
|
@import gitbucket.core.service.RepositorySearchService._
|
||||||
|
@html.main("Search Results", Some(repository)){
|
||||||
|
@menu("wiki", fileCount, issueCount, wikis.size, query, repository){
|
||||||
|
@if(wikis.isEmpty){
|
||||||
|
<h4>We couldn't find any code matching '@query'</h4>
|
||||||
|
} else {
|
||||||
|
<h4>We've found @wikis.size code @plural(wikis.size, "result")</h4>
|
||||||
|
}
|
||||||
|
@wikis.drop((page - 1) * CodeLimit).take(CodeLimit).map { file =>
|
||||||
|
<div>
|
||||||
|
<h5><a href="@url(repository)/wiki/@file.path">@file.path</a></h5>
|
||||||
|
<div class="small muted">Last committed @helper.html.datetimeago(file.lastModified)</div>
|
||||||
|
<pre class="prettyprint linenums:@file.highlightLineNumber" style="padding-left: 25px;">@Html(file.highlightText)</pre>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@helper.html.paginator(page, wikis.size, CodeLimit, 10,
|
||||||
|
s"${url(repository)}/search?q=${urlEncode(query)}&type=code")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user