mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-07 03:37:01 +02:00
Add issue completion (#2513)
This commit is contained in:
@@ -417,6 +417,28 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
}) getOrElse NotFound()
|
||||
})
|
||||
|
||||
/**
|
||||
* JSON API for issue and PR completion.
|
||||
*/
|
||||
ajaxGet("/:owner/:repository/_issue/proposals")(writableUsersOnly { repository =>
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
Map(
|
||||
"options" -> (
|
||||
getOpenIssues(repository.owner, repository.name)
|
||||
.map { t =>
|
||||
Map(
|
||||
"label" -> s"""${if (t.isPullRequest) "<i class='octicon octicon-git-pull-request'></i>"
|
||||
else "<i class='octicon octicon-issue-opened'></i>"}<b> #${StringUtil
|
||||
.escapeHtml(t.issueId.toString)} ${StringUtil.escapeHtml(t.title)}</b>""",
|
||||
"value" -> t.issueId.toString
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
||||
val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||
val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||
|
||||
@@ -57,6 +57,7 @@ class PluginRegistry {
|
||||
private val textDecorators = new ConcurrentLinkedQueue[TextDecorator]
|
||||
private val suggestionProviders = new ConcurrentLinkedQueue[SuggestionProvider]
|
||||
suggestionProviders.add(new UserNameSuggestionProvider())
|
||||
suggestionProviders.add(new IssueSuggestionProvider())
|
||||
private val sshCommandProviders = new ConcurrentLinkedQueue[PartialFunction[String, Command]]()
|
||||
|
||||
def addPlugin(pluginInfo: PluginInfo): Unit = plugins.add(pluginInfo)
|
||||
|
||||
@@ -91,7 +91,7 @@ trait SuggestionProvider {
|
||||
* If this suggestion provider needs some additional process to assemble the proposal list (e.g. It need to use Ajax
|
||||
* to get a proposal list from the server), then override this method and return any JavaScript code.
|
||||
*/
|
||||
def additionalScript(implicit context: Context): String = ""
|
||||
def additionalScript(repository: RepositoryInfo)(implicit context: Context): String = ""
|
||||
|
||||
}
|
||||
|
||||
@@ -99,6 +99,14 @@ class UserNameSuggestionProvider extends SuggestionProvider {
|
||||
override val id: String = "user"
|
||||
override val prefix: String = "@"
|
||||
override val context: Seq[String] = Seq("issues")
|
||||
override def additionalScript(implicit context: Context): String =
|
||||
override def additionalScript(repository: RepositoryInfo)(implicit context: Context): String =
|
||||
s"""$$.get('${context.path}/_user/proposals', { query: '', user: true, group: false }, function (data) { user = data.options; });"""
|
||||
}
|
||||
|
||||
class IssueSuggestionProvider extends SuggestionProvider {
|
||||
override val id: String = "issue"
|
||||
override val prefix: String = "#"
|
||||
override val context: Seq[String] = Seq("issues")
|
||||
override def additionalScript(repository: RepositoryInfo)(implicit context: Context): String =
|
||||
s"""$$.get('${context.path}/${repository.owner}/${repository.name}/_issue/proposals', function (data) { issue = data.options; });"""
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ trait IssuesService {
|
||||
Issues filter (_.byPrimaryKey(owner, repository, issueId.toInt)) firstOption
|
||||
else None
|
||||
|
||||
def getOpenIssues(owner: String, repository: String)(implicit s: Session): List[Issue] =
|
||||
Issues filter (_.byRepository(owner, repository)) filterNot (_.closed) sortBy (_.issueId desc) list
|
||||
|
||||
def getComments(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
||||
IssueComments filter (_.byIssue(owner, repository, issueId)) sortBy (_.commentId asc) list
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ $(function(){
|
||||
var @provider.id = @Html(helpers.json(provider.options(repository).map { case (value, label) =>
|
||||
Map("value" -> value, "label" -> label)
|
||||
}));
|
||||
@Html(provider.additionalScript)
|
||||
@Html(provider.additionalScript(repository))
|
||||
}
|
||||
}
|
||||
$('#@textareaId').textcomplete([
|
||||
|
||||
Reference in New Issue
Block a user