mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Add search condition behavior to the issues page.
This commit is contained in:
@@ -3,6 +3,7 @@ package app
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
import service._
|
||||
import IssuesService._
|
||||
import util.UsersOnlyAuthenticator
|
||||
|
||||
class IssuesController extends IssuesControllerBase
|
||||
@@ -21,12 +22,15 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
)(IssueForm.apply)
|
||||
|
||||
get("/:owner/:repository/issues"){
|
||||
val owner = params("owner")
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
val condition = IssueSearchCondition(request)
|
||||
|
||||
println(condition)
|
||||
|
||||
getRepository(owner, repository, baseUrl) match {
|
||||
case None => NotFound()
|
||||
case Some(r) => {
|
||||
case None => NotFound()
|
||||
case Some(repositoryInfo) => {
|
||||
// search condition
|
||||
val closed = params.get("state") collect {
|
||||
case "closed" => true
|
||||
@@ -35,7 +39,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
issues.html.issues(searchIssue(owner, repository, closed),
|
||||
getLabels(owner, repository),
|
||||
getMilestones(owner, repository).filter(_.closedDate.isEmpty),
|
||||
r, isWritable(owner, repository, context.loginAccount))
|
||||
condition, repositoryInfo, isWritable(owner, repository, context.loginAccount))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,18 @@ case class Label(
|
||||
repositoryName: String,
|
||||
labelId: Int,
|
||||
labelName: String,
|
||||
color: String)
|
||||
color: String){
|
||||
|
||||
val fontColor = {
|
||||
val r = color.substring(0, 2)
|
||||
val g = color.substring(2, 4)
|
||||
val b = color.substring(4, 6)
|
||||
|
||||
if(Integer.parseInt(r, 16) + Integer.parseInt(g, 16) + Integer.parseInt(b, 16) > 408){
|
||||
"000000"
|
||||
} else {
|
||||
"FFFFFF"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -64,4 +64,42 @@ trait IssuesService {
|
||||
currentDate) ).bind
|
||||
} firstOption
|
||||
|
||||
}
|
||||
|
||||
object IssuesService {
|
||||
import java.net.URLEncoder
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
|
||||
case class IssueSearchCondition(labels: Set[String], milestoneId: Option[Int], state: Option[String], sort: Option[String], direction: Option[String]){
|
||||
import IssueSearchCondition._
|
||||
|
||||
def toURL(repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context): String = {
|
||||
val params = List(
|
||||
if(labels.isEmpty) None else Some("labels=" + urlEncode(labels.mkString(" "))),
|
||||
milestoneId.map("milestone=" + _),
|
||||
state.map("state=" + urlEncode(_)),
|
||||
sort.map("sort=" + urlEncode(_)),
|
||||
direction.map("direction=" + urlEncode(_))
|
||||
)
|
||||
"%s/%s/%s/issues?%s".format(context.path, repository.owner, repository.name, params.flatten.mkString("&"))
|
||||
}
|
||||
}
|
||||
|
||||
object IssueSearchCondition {
|
||||
|
||||
private def urlEncode(value: String): String = URLEncoder.encode(value, "UTF-8")
|
||||
|
||||
private def param(request: HttpServletRequest, name: String): Option[String] = {
|
||||
val value = request.getParameter(name)
|
||||
if(value == null || value.isEmpty) None else Some(value)
|
||||
}
|
||||
|
||||
def apply(request: HttpServletRequest): IssueSearchCondition =
|
||||
IssueSearchCondition(
|
||||
param(request, "labels").map(_.split(" ").toSet).getOrElse(Set.empty),
|
||||
param(request, "milestone").map(_.toInt),
|
||||
param(request, "state"),
|
||||
param(request, "sort"),
|
||||
param(request, "direction"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user