mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-06-25 01:10:06 +02:00
(refs #1241) Update CompletionProposalProvider interface
This commit is contained in:
@@ -204,8 +204,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
getIssue(repository.owner, repository.name, params("id")) map { x =>
|
||||
if(isEditable(x.userName, x.repositoryName, x.openedUserName)){
|
||||
params.get("dataType") collect {
|
||||
case t if t == "html" => html.editissue(
|
||||
x.content, x.issueId, x.userName, x.repositoryName)
|
||||
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
||||
} getOrElse {
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
@@ -232,8 +231,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
getComment(repository.owner, repository.name, params("id")) map { x =>
|
||||
if(isEditable(x.userName, x.repositoryName, x.commentedUserName)){
|
||||
params.get("dataType") collect {
|
||||
case t if t == "html" => html.editcomment(
|
||||
x.content, x.commentId, x.userName, x.repositoryName)
|
||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||
} getOrElse {
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
|
||||
@@ -376,8 +376,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
getCommitComment(repository.owner, repository.name, params("id")) map { x =>
|
||||
if(isEditable(x.userName, x.repositoryName, x.commentedUserName)){
|
||||
params.get("dataType") collect {
|
||||
case t if t == "html" => html.editcomment(
|
||||
x.content, x.commentId, x.userName, x.repositoryName)
|
||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||
} getOrElse {
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gitbucket.core.plugin
|
||||
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util.EmojiUtil
|
||||
|
||||
trait CompletionProposalProvider {
|
||||
@@ -8,28 +9,29 @@ trait CompletionProposalProvider {
|
||||
val id: String
|
||||
val prefix: String
|
||||
val suffix: String = " "
|
||||
val values: Seq[String]
|
||||
val context: Seq[String]
|
||||
|
||||
def values(repository: RepositoryInfo): Seq[String]
|
||||
def template(implicit context: Context): String = "value"
|
||||
def additionalScript(implicit context: Context): String = ""
|
||||
|
||||
}
|
||||
|
||||
class EmojiCompletionProposalProvider extends CompletionProposalProvider {
|
||||
override val id: String = "emoji"
|
||||
override val values: Seq[String] = EmojiUtil.emojis.toSeq
|
||||
override val prefix: String = ":"
|
||||
override val suffix: String = ": "
|
||||
override val context: Seq[String] = Seq("wiki", "issues")
|
||||
override def values(repository: RepositoryInfo): Seq[String] = EmojiUtil.emojis.toSeq
|
||||
override def template(implicit context: Context): String =
|
||||
s"""'<img src=\"${context.path}/assets/common/images/emojis/' + value + '.png\" class=\"emoji\"></img>' + value"""
|
||||
}
|
||||
|
||||
class UserCompletionProposalProvider extends CompletionProposalProvider {
|
||||
override val id: String = "user"
|
||||
override val values: Seq[String] = Nil
|
||||
override val prefix: String = "@"
|
||||
override val context: Seq[String] = Seq("issues")
|
||||
override def values(repository: RepositoryInfo): Seq[String] = Nil
|
||||
override def template(implicit context: Context): String = "'@' + value"
|
||||
override def additionalScript(implicit context: Context): String =
|
||||
s"""$$.get('${context.path}/_user/proposals', { query: '' }, function (data) { user = data.options; });"""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@(owner: String, repository: String, completionContext: String, generateScript: Boolean = true)(textarea: Html)(implicit context: gitbucket.core.controller.Context)
|
||||
@(repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||
completionContext: String, generateScript: Boolean = true)(textarea: Html)(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.util.{FileUtil, EmojiUtil}
|
||||
@import gitbucket.core.view.helpers
|
||||
<div class="muted attachable">
|
||||
@@ -10,7 +11,7 @@
|
||||
$(function(){
|
||||
@gitbucket.core.plugin.PluginRegistry().getCompletionProposalProviders.map { provider =>
|
||||
@if(provider.context.contains(completionContext)){
|
||||
var @provider.id = @Html(helpers.json(provider.values));
|
||||
var @provider.id = @Html(helpers.json(provider.values(repository)));
|
||||
@Html(provider.additionalScript)
|
||||
}
|
||||
}
|
||||
@@ -46,14 +47,14 @@ $(function(){
|
||||
@if(generateScript){
|
||||
try {
|
||||
$([$('#@textareaId').closest('div')[0], $('#@textareaId').next('div')[0]]).dropzone({
|
||||
url: '@context.path/upload/file/@owner/@repository',
|
||||
url: '@context.path/upload/file/@repository.owner/@repository.name',
|
||||
maxFilesize: 10,
|
||||
acceptedFiles: @Html(FileUtil.mimeTypeWhiteList.mkString("'", ",", "'")),
|
||||
dictInvalidFileType: 'Unfortunately, we don\'t support that file type. Try again with a PNG, GIF, JPG, DOCX, PPTX, XLSX, TXT, or PDF.',
|
||||
previewTemplate: "<div class=\"dz-preview\">\n <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress>Uploading your files...</span></div>\n <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n</div>",
|
||||
success: function(file, id) {
|
||||
var attachFile = (file.type.match(/image\/.*/) ? '\n![' + file.name.split('.')[0] : '\n[' + file.name) +
|
||||
'](@context.baseUrl/@owner/@repository/_attached/' + id + ')';
|
||||
'](@context.baseUrl/@repository.owner/@repository.name/_attached/' + id + ')';
|
||||
$('#@textareaId').val($('#@textareaId').val() + attachFile);
|
||||
$(file.previewElement).prevAll('div.dz-preview').addBack().remove();
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@
|
||||
@if(styleClass.nonEmpty){ class="@styleClass" }>@content</textarea>
|
||||
}
|
||||
@gitbucket.core.helper.html.attached(
|
||||
owner = repository.owner,
|
||||
repository = repository.name,
|
||||
repository = repository,
|
||||
completionContext = completionContext,
|
||||
generateScript = enableWikiLink
|
||||
)(textarea)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@(content: String, commentId: Int, owner: String, repository: String)(implicit context: gitbucket.core.controller.Context)
|
||||
@(content: String, commentId: Int,
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||
<span id="error-edit-content-@commentId" class="error"></span>
|
||||
@gitbucket.core.helper.html.attached(owner, repository, "issues"){
|
||||
@gitbucket.core.helper.html.attached(repository, "issues"){
|
||||
<textarea id="edit-content-@commentId" class="form-control">@content</textarea>
|
||||
}
|
||||
<div>
|
||||
@@ -18,7 +19,7 @@ $(function(){
|
||||
$('#update-comment-@commentId').click(function(){
|
||||
$('#update-comment-@commentId, #cancel-comment-@commentId').attr('disabled', 'disabled');
|
||||
$.ajax({
|
||||
url: '@context.path/@owner/@repository/issue_comments/edit/@commentId',
|
||||
url: '@context.path/@repository.owner/@repository.name/issue_comments/edit/@commentId',
|
||||
type: 'POST',
|
||||
data: {
|
||||
issueId : 0, // TODO
|
||||
@@ -34,7 +35,7 @@ $(function(){
|
||||
|
||||
$('#cancel-comment-@commentId').click(function(){
|
||||
$('#update-comment-@commentId, #cancel-comment-@commentId').attr('disabled', 'disabled');
|
||||
$.get('@context.path/@owner/@repository/issue_comments/_data/@commentId', callback);
|
||||
$.get('@context.path/@repository.owner/@repository.name/issue_comments/_data/@commentId', callback);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
@(content: Option[String], issueId: Int, owner: String, repository: String)(implicit context: gitbucket.core.controller.Context)
|
||||
@gitbucket.core.helper.html.attached(owner, repository, "issues"){
|
||||
@(content: Option[String], issueId: Int,
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||
@gitbucket.core.helper.html.attached(repository, "issues"){
|
||||
<textarea id="edit-content" class="form-control">@content.getOrElse("")</textarea>
|
||||
}
|
||||
<div>
|
||||
@@ -16,7 +17,7 @@ $(function(){
|
||||
$('#update-issue').click(function(){
|
||||
$('#update, #cancel').attr('disabled', 'disabled');
|
||||
$.ajax({
|
||||
url: '@context.path/@owner/@repository/issues/edit/@issueId',
|
||||
url: '@context.path/@repository.owner/@repository.name/issues/edit/@issueId',
|
||||
type: 'POST',
|
||||
data: {
|
||||
content : $('#edit-content').val()
|
||||
@@ -30,7 +31,7 @@ $(function(){
|
||||
|
||||
$('#cancel-issue').click(function(){
|
||||
$('#update, #cancel').attr('disabled', 'disabled');
|
||||
$.get('@context.path/@owner/@repository/issues/_data/@issueId', callback);
|
||||
$.get('@context.path/@repository.owner/@repository.name/issues/_data/@issueId', callback);
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
@(content: String, commentId: Int, owner: String, repository: String)(implicit context: gitbucket.core.controller.Context)
|
||||
@(content: String, commentId: Int,
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
|
||||
<span class="error-edit-content-@commentId error"></span>
|
||||
@gitbucket.core.helper.html.attached(owner, repository, "issues"){
|
||||
@gitbucket.core.helper.html.attached(repository, "issues"){
|
||||
<textarea style="height: 100px;" id="edit-content-@commentId" class="form-control">@content</textarea>
|
||||
}
|
||||
<div>
|
||||
@@ -21,7 +22,7 @@ $(function(){
|
||||
$box = $(this).closest('.commit-comment-box');
|
||||
$('.update-comment-@commentId, .cancel-comment-@commentId', $box).attr('disabled', 'disabled');
|
||||
$.ajax({
|
||||
url: '@context.path/@owner/@repository/commit_comments/edit/@commentId',
|
||||
url: '@context.path/@repository.owner/@repository.name/commit_comments/edit/@commentId',
|
||||
type: 'POST',
|
||||
data: {
|
||||
content : $('#edit-content-@commentId', $box).val()
|
||||
@@ -37,7 +38,7 @@ $(function(){
|
||||
$(document).on('click', '.cancel-comment-@commentId', function(){
|
||||
$box = $(this).closest('.box');
|
||||
$('.update-comment-@commentId, .cancel-comment-@commentId', $box).attr('disabled', 'disabled');
|
||||
$.get('@context.path/@owner/@repository/commit_comments/_data/@commentId', curriedCallback($box));
|
||||
$.get('@context.path/@repository.owner/@repository.name/commit_comments/_data/@commentId', curriedCallback($box));
|
||||
return false;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user