mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
(refs #488) Fixed the action for issue and comment content change.
This commit is contained in:
@@ -21,7 +21,6 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
|
||||
case class IssueCreateForm(title: String, content: Option[String],
|
||||
assignedUserName: Option[String], milestoneId: Option[Int], labelNames: Option[String])
|
||||
// case class IssueEditForm(title: String, content: Option[String])
|
||||
case class CommentForm(issueId: Int, content: String)
|
||||
case class IssueStateForm(issueId: Int, content: Option[String])
|
||||
|
||||
@@ -36,10 +35,9 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
val issueTitleEditForm = mapping(
|
||||
"title" -> trim(label("Title", text(required)))
|
||||
)(x => x)
|
||||
// val issueEditForm = mapping(
|
||||
// "title" -> trim(label("Title", text(required))),
|
||||
// "content" -> trim(optional(text()))
|
||||
// )(IssueEditForm.apply)
|
||||
val issueEditForm = mapping(
|
||||
"content" -> trim(optional(text()))
|
||||
)(x => x)
|
||||
|
||||
val commentForm = mapping(
|
||||
"issueId" -> label("Issue Id", number()),
|
||||
@@ -126,7 +124,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
getIssue(owner, name, params("id")).map { issue =>
|
||||
if(isEditable(owner, name, issue.openedUserName)){
|
||||
// update issue
|
||||
updateIssueTitle(owner, name, issue.issueId, title)
|
||||
updateIssue(owner, name, issue.issueId, title, issue.content)
|
||||
// extract references and create refer comment
|
||||
// TODO Confirmation(about "issue" parameter)
|
||||
createReferComment(owner, name, issue, title)
|
||||
@@ -137,20 +135,20 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
}
|
||||
})
|
||||
|
||||
// ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (form, repository) =>
|
||||
// defining(repository.owner, repository.name){ case (owner, name) =>
|
||||
// getIssue(owner, name, params("id")).map { issue =>
|
||||
// if(isEditable(owner, name, issue.openedUserName)){
|
||||
// // update issue
|
||||
// updateIssue(owner, name, issue.issueId, form.title, form.content)
|
||||
// // extract references and create refer comment
|
||||
// createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse(""))
|
||||
//
|
||||
// redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||
// } else Unauthorized
|
||||
// } getOrElse NotFound
|
||||
// }
|
||||
// })
|
||||
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
||||
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||
getIssue(owner, name, params("id")).map { issue =>
|
||||
if(isEditable(owner, name, issue.openedUserName)){
|
||||
// update issue
|
||||
updateIssue(owner, name, issue.issueId, issue.title, content)
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue, content.getOrElse(""))
|
||||
|
||||
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||
} else Unauthorized
|
||||
} getOrElse NotFound
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||
handleComment(form.issueId, Some(form.content), repository)() map { case (issue, id) =>
|
||||
@@ -192,7 +190,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
if(isEditable(x.userName, x.repositoryName, x.openedUserName)){
|
||||
params.get("dataType") collect {
|
||||
case t if t == "html" => issues.html.editissue(
|
||||
x.title, x.content, x.issueId, x.userName, x.repositoryName)
|
||||
x.content, x.issueId, x.userName, x.repositoryName)
|
||||
} getOrElse {
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
|
||||
@@ -225,22 +225,14 @@ trait IssuesService {
|
||||
registeredDate = currentDate,
|
||||
updatedDate = currentDate)
|
||||
|
||||
def updateIssueTitle(owner: String, repository: String, issueId: Int, title: String)(implicit s: Session) =
|
||||
def updateIssue(owner: String, repository: String, issueId: Int,
|
||||
title: String, content: Option[String])(implicit s: Session) =
|
||||
Issues
|
||||
.filter (_.byPrimaryKey(owner, repository, issueId))
|
||||
.map { t =>
|
||||
(t.title, t.updatedDate)
|
||||
(t.title, t.content.?, t.updatedDate)
|
||||
}
|
||||
.update (title, currentDate)
|
||||
|
||||
// def updateIssue(owner: String, repository: String, issueId: Int,
|
||||
// title: String, content: Option[String])(implicit s: Session) =
|
||||
// Issues
|
||||
// .filter (_.byPrimaryKey(owner, repository, issueId))
|
||||
// .map { t =>
|
||||
// (t.title, t.content.?, t.updatedDate)
|
||||
// }
|
||||
// .update (title, content, currentDate)
|
||||
.update (title, content, currentDate)
|
||||
|
||||
def updateAssignedUserName(owner: String, repository: String, issueId: Int,
|
||||
assignedUserName: Option[String])(implicit s: Session) =
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
@user(issue.openedUserName, styleClass="username strong") <span class="muted">commented on @datetime(issue.registeredDate)</span>
|
||||
<span class="pull-right">
|
||||
@if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){
|
||||
<a href="#"><i class="icon-pencil"></i></a>
|
||||
<a href="#" data-issue-id="@issue.issueId"><i class="icon-pencil"></i></a>
|
||||
}
|
||||
</span>
|
||||
</div>
|
||||
<div class="box-content issue-content">
|
||||
<div class="box-content issue-content" id="issueContent">
|
||||
@markdown(issue.content getOrElse "No description provided.", repository, false, true)
|
||||
</div>
|
||||
</div>
|
||||
@@ -103,12 +103,21 @@
|
||||
$(function(){
|
||||
$('i.icon-pencil').click(function(){
|
||||
var id = $(this).closest('a').data('comment-id');
|
||||
$.get('@url(repository)/issue_comments/_data/' + id,
|
||||
var url = '@url(repository)/issue_comments/_data/' + id;
|
||||
var $content = $('#commentContent-' + id);
|
||||
|
||||
if(!id){
|
||||
id = $(this).closest('a').data('issue-id');
|
||||
url = '@url(repository)/issues/_data/' + id;
|
||||
$content = $('#issueContent');
|
||||
}
|
||||
|
||||
$.get(url,
|
||||
{
|
||||
dataType : 'html'
|
||||
},
|
||||
function(data){
|
||||
$('#commentContent-' + id).empty().html(data);
|
||||
$content.empty().html(data);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<textarea style="width: 635px; height: 100px;" id="edit-content-@commentId">@content</textarea>
|
||||
}
|
||||
<div>
|
||||
<input type="button" id="update-comment-@commentId" class="btn btn-small" value="Update Comment"/>
|
||||
<input type="button" id="cancel-comment-@commentId" class="btn btn-small btn-danger pull-right" value="Cancel"/>
|
||||
<input type="button" id="cancel-comment-@commentId" class="btn btn-small btn-danger" value="Cancel"/>
|
||||
<input type="button" id="update-comment-@commentId" class="btn btn-small pull-right" value="Update comment"/>
|
||||
</div>
|
||||
<script>
|
||||
$(function(){
|
||||
|
||||
@@ -1,42 +1,35 @@
|
||||
@(title: String, content: Option[String], issueId: Int, owner: String, repository: String)(implicit context: app.Context)
|
||||
@(content: Option[String], issueId: Int, owner: String, repository: String)(implicit context: app.Context)
|
||||
@import context._
|
||||
<span id="error-edit-title" class="error"></span>
|
||||
<input type="text" style="width: 635px;" id="edit-title" value="@title"/>
|
||||
@helper.html.attached(owner, repository){
|
||||
<textarea style="width: 635px; height: 100px; max-height: 300px;" id="edit-content">@content.getOrElse("")</textarea>
|
||||
}
|
||||
<div>
|
||||
<input type="button" id="update" class="btn btn-small" value="Update Issue"/>
|
||||
<input type="button" id="cancel" class="btn btn-small btn-danger pull-right" value="Cancel"/>
|
||||
<input type="button" id="cancel-issue" class="btn btn-small btn-danger" value="Cancel"/>
|
||||
<input type="button" id="update-issue" class="btn btn-small pull-right" value="Update comment"/>
|
||||
</div>
|
||||
<script>
|
||||
$(function(){
|
||||
$('#edit-content').elastic();
|
||||
|
||||
var callback = function(data){
|
||||
$('#update, #cancel').removeAttr('disabled');
|
||||
$('#issueTitle').empty().text(data.title);
|
||||
$('#issueContent').empty().html(data.content);
|
||||
};
|
||||
|
||||
$('#update').click(function(){
|
||||
$('#update-issue').click(function(){
|
||||
$('#update, #cancel').attr('disabled', 'disabled');
|
||||
$.ajax({
|
||||
url: '@path/@owner/@repository/issues/edit/@issueId',
|
||||
type: 'POST',
|
||||
data: {
|
||||
title : $('#edit-title').val(),
|
||||
content : $('#edit-content').val()
|
||||
}
|
||||
}).done(
|
||||
callback
|
||||
).fail(function(req) {
|
||||
$('#update, #cancel').removeAttr('disabled');
|
||||
$('#error-edit-title').text($.parseJSON(req.responseText).title);
|
||||
});
|
||||
});
|
||||
|
||||
$('#cancel').click(function(){
|
||||
$('#cancel-issue').click(function(){
|
||||
$('#update, #cancel').attr('disabled', 'disabled');
|
||||
$.get('@path/@owner/@repository/issues/_data/@issueId', callback);
|
||||
return false;
|
||||
|
||||
@@ -64,6 +64,7 @@ $(function(){
|
||||
$('#edit').click(function(){
|
||||
$('.edit-title').show();
|
||||
$('.show-title').hide();
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#update').click(function(){
|
||||
@@ -82,11 +83,13 @@ $(function(){
|
||||
$(this).removeAttr('disabled');
|
||||
$('#error-edit-title').text($.parseJSON(req.responseText).title);
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#cancel').click(function(){
|
||||
$('.edit-title').hide();
|
||||
$('.show-title').show();
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
Reference in New Issue
Block a user