mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +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 jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
import service._
|
import service._
|
||||||
|
import IssuesService._
|
||||||
import util.UsersOnlyAuthenticator
|
import util.UsersOnlyAuthenticator
|
||||||
|
|
||||||
class IssuesController extends IssuesControllerBase
|
class IssuesController extends IssuesControllerBase
|
||||||
@@ -23,10 +24,13 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/issues"){
|
get("/:owner/:repository/issues"){
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
|
val condition = IssueSearchCondition(request)
|
||||||
|
|
||||||
|
println(condition)
|
||||||
|
|
||||||
getRepository(owner, repository, baseUrl) match {
|
getRepository(owner, repository, baseUrl) match {
|
||||||
case None => NotFound()
|
case None => NotFound()
|
||||||
case Some(r) => {
|
case Some(repositoryInfo) => {
|
||||||
// search condition
|
// search condition
|
||||||
val closed = params.get("state") collect {
|
val closed = params.get("state") collect {
|
||||||
case "closed" => true
|
case "closed" => true
|
||||||
@@ -35,7 +39,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
issues.html.issues(searchIssue(owner, repository, closed),
|
issues.html.issues(searchIssue(owner, repository, closed),
|
||||||
getLabels(owner, repository),
|
getLabels(owner, repository),
|
||||||
getMilestones(owner, repository).filter(_.closedDate.isEmpty),
|
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,
|
repositoryName: String,
|
||||||
labelId: Int,
|
labelId: Int,
|
||||||
labelName: String,
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -65,3 +65,41 @@ trait IssuesService {
|
|||||||
} firstOption
|
} 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"))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
@(issues: List[model.Issue], labels: List[model.Label], milestones: List[model.Milestone], repository: service.RepositoryService.RepositoryInfo, isWrite: Boolean)(implicit context: app.Context)
|
@(issues: List[model.Issue], labels: List[model.Label], milestones: List[model.Milestone], condition: service.IssuesService.IssueSearchCondition, repository: service.RepositoryService.RepositoryInfo, isWrite: Boolean)(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@html.main("Issues - " + repository.owner + "/" + repository.name){
|
@html.main("Issues - " + repository.owner + "/" + repository.name){
|
||||||
@@ -29,7 +29,11 @@
|
|||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
@if(condition.milestoneId.isEmpty){
|
||||||
No milestone selected
|
No milestone selected
|
||||||
|
} else {
|
||||||
|
<span class="description">Milestone:</span> @milestones.find(_.milestoneId == condition.milestoneId.get).map(_.title)
|
||||||
|
}
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button class="btn dropdown-toggle" data-toggle="dropdown">
|
<button class="btn dropdown-toggle" data-toggle="dropdown">
|
||||||
<i class="icon-cog"></i>
|
<i class="icon-cog"></i>
|
||||||
@@ -37,7 +41,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
@milestones.map { milestone =>
|
@milestones.map { milestone =>
|
||||||
<li><a href="#">@milestone.title</a></li>
|
<li><a href="@condition.copy(milestoneId = Some(milestone.milestoneId)).toURL(repository)">@milestone.title</a></li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -48,7 +52,8 @@
|
|||||||
<ul class="label-list nav nav-pills nav-stacked">
|
<ul class="label-list nav nav-pills nav-stacked">
|
||||||
@labels.map { label =>
|
@labels.map { label =>
|
||||||
<li>
|
<li>
|
||||||
<a href="#">
|
<a href="@condition.copy(labels = (if(condition.labels.contains(label.labelName)) condition.labels - label.labelName else condition.labels + label.labelName)).toURL(repository)"
|
||||||
|
@if(condition.labels.contains(label.labelName)){style="background-color: #@label.color; color: #@label.fontColor;"}>
|
||||||
<span class="count-right">0</span>
|
<span class="count-right">0</span>
|
||||||
<span style="background-color: #@label.color;" class="label-color"> </span>
|
<span style="background-color: #@label.color;" class="label-color"> </span>
|
||||||
@label.labelName
|
@label.labelName
|
||||||
@@ -79,8 +84,8 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<a class="btn active" href="#">1 Open</a>
|
<a class="btn@if(condition.state == Some("open")){ active}" href="@condition.copy(state = Some("open")).toURL(repository)">1 Open</a>
|
||||||
<a class="btn" href="#">1 Closed</a>
|
<a class="btn@if(condition.state == Some("closed")){ active}" href="@condition.copy(state = Some("closed")).toURL(repository)">1 Closed</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button class="btn dropdown-toggle" data-toggle="dropdown">
|
<button class="btn dropdown-toggle" data-toggle="dropdown">
|
||||||
|
|||||||
Reference in New Issue
Block a user