(refs #488) Fixed the action for issue and comment content change.

This commit is contained in:
shimamoto
2014-10-05 17:13:58 +09:00
parent fc806b8813
commit b1017140aa
6 changed files with 47 additions and 52 deletions

View File

@@ -21,7 +21,6 @@ trait IssuesControllerBase extends ControllerBase {
case class IssueCreateForm(title: String, content: Option[String], case class IssueCreateForm(title: String, content: Option[String],
assignedUserName: Option[String], milestoneId: Option[Int], labelNames: 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 CommentForm(issueId: Int, content: String)
case class IssueStateForm(issueId: Int, content: Option[String]) case class IssueStateForm(issueId: Int, content: Option[String])
@@ -36,10 +35,9 @@ trait IssuesControllerBase extends ControllerBase {
val issueTitleEditForm = mapping( val issueTitleEditForm = mapping(
"title" -> trim(label("Title", text(required))) "title" -> trim(label("Title", text(required)))
)(x => x) )(x => x)
// val issueEditForm = mapping( val issueEditForm = mapping(
// "title" -> trim(label("Title", text(required))), "content" -> trim(optional(text()))
// "content" -> trim(optional(text())) )(x => x)
// )(IssueEditForm.apply)
val commentForm = mapping( val commentForm = mapping(
"issueId" -> label("Issue Id", number()), "issueId" -> label("Issue Id", number()),
@@ -126,7 +124,7 @@ trait IssuesControllerBase extends ControllerBase {
getIssue(owner, name, params("id")).map { issue => getIssue(owner, name, params("id")).map { issue =>
if(isEditable(owner, name, issue.openedUserName)){ if(isEditable(owner, name, issue.openedUserName)){
// update issue // update issue
updateIssueTitle(owner, name, issue.issueId, title) updateIssue(owner, name, issue.issueId, title, issue.content)
// extract references and create refer comment // extract references and create refer comment
// TODO Confirmation(about "issue" parameter) // TODO Confirmation(about "issue" parameter)
createReferComment(owner, name, issue, title) createReferComment(owner, name, issue, title)
@@ -137,20 +135,20 @@ trait IssuesControllerBase extends ControllerBase {
} }
}) })
// ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (form, repository) => ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
// defining(repository.owner, repository.name){ case (owner, name) => defining(repository.owner, repository.name){ case (owner, name) =>
// getIssue(owner, name, params("id")).map { issue => getIssue(owner, name, params("id")).map { issue =>
// if(isEditable(owner, name, issue.openedUserName)){ if(isEditable(owner, name, issue.openedUserName)){
// // update issue // update issue
// updateIssue(owner, name, issue.issueId, form.title, form.content) updateIssue(owner, name, issue.issueId, issue.title, content)
// // extract references and create refer comment // extract references and create refer comment
// createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse("")) createReferComment(owner, name, issue, content.getOrElse(""))
//
// redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}") redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
// } else Unauthorized } else Unauthorized
// } getOrElse NotFound } getOrElse NotFound
// } }
// }) })
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) => post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
handleComment(form.issueId, Some(form.content), repository)() map { case (issue, id) => 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)){ if(isEditable(x.userName, x.repositoryName, x.openedUserName)){
params.get("dataType") collect { params.get("dataType") collect {
case t if t == "html" => issues.html.editissue( 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 { } getOrElse {
contentType = formats("json") contentType = formats("json")
org.json4s.jackson.Serialization.write( org.json4s.jackson.Serialization.write(

View File

@@ -225,22 +225,14 @@ trait IssuesService {
registeredDate = currentDate, registeredDate = currentDate,
updatedDate = 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 Issues
.filter (_.byPrimaryKey(owner, repository, issueId)) .filter (_.byPrimaryKey(owner, repository, issueId))
.map { t => .map { t =>
(t.title, t.updatedDate) (t.title, t.content.?, t.updatedDate)
} }
.update (title, currentDate) .update (title, content, 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)
def updateAssignedUserName(owner: String, repository: String, issueId: Int, def updateAssignedUserName(owner: String, repository: String, issueId: Int,
assignedUserName: Option[String])(implicit s: Session) = assignedUserName: Option[String])(implicit s: Session) =

View File

@@ -11,11 +11,11 @@
@user(issue.openedUserName, styleClass="username strong") <span class="muted">commented on @datetime(issue.registeredDate)</span> @user(issue.openedUserName, styleClass="username strong") <span class="muted">commented on @datetime(issue.registeredDate)</span>
<span class="pull-right"> <span class="pull-right">
@if(hasWritePermission || loginAccount.map(_.userName == issue.openedUserName).getOrElse(false)){ @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> </span>
</div> </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) @markdown(issue.content getOrElse "No description provided.", repository, false, true)
</div> </div>
</div> </div>
@@ -103,12 +103,21 @@
$(function(){ $(function(){
$('i.icon-pencil').click(function(){ $('i.icon-pencil').click(function(){
var id = $(this).closest('a').data('comment-id'); 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' dataType : 'html'
}, },
function(data){ function(data){
$('#commentContent-' + id).empty().html(data); $content.empty().html(data);
}); });
return false; return false;
}); });

View File

@@ -5,8 +5,8 @@
<textarea style="width: 635px; height: 100px;" id="edit-content-@commentId">@content</textarea> <textarea style="width: 635px; height: 100px;" id="edit-content-@commentId">@content</textarea>
} }
<div> <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" value="Cancel"/>
<input type="button" id="cancel-comment-@commentId" class="btn btn-small btn-danger pull-right" value="Cancel"/> <input type="button" id="update-comment-@commentId" class="btn btn-small pull-right" value="Update comment"/>
</div> </div>
<script> <script>
$(function(){ $(function(){

View File

@@ -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._ @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){ @helper.html.attached(owner, repository){
<textarea style="width: 635px; height: 100px; max-height: 300px;" id="edit-content">@content.getOrElse("")</textarea> <textarea style="width: 635px; height: 100px; max-height: 300px;" id="edit-content">@content.getOrElse("")</textarea>
} }
<div> <div>
<input type="button" id="update" class="btn btn-small" value="Update Issue"/> <input type="button" id="cancel-issue" class="btn btn-small btn-danger" value="Cancel"/>
<input type="button" id="cancel" class="btn btn-small btn-danger pull-right" value="Cancel"/> <input type="button" id="update-issue" class="btn btn-small pull-right" value="Update comment"/>
</div> </div>
<script> <script>
$(function(){ $(function(){
$('#edit-content').elastic();
var callback = function(data){ var callback = function(data){
$('#update, #cancel').removeAttr('disabled'); $('#update, #cancel').removeAttr('disabled');
$('#issueTitle').empty().text(data.title);
$('#issueContent').empty().html(data.content); $('#issueContent').empty().html(data.content);
}; };
$('#update').click(function(){ $('#update-issue').click(function(){
$('#update, #cancel').attr('disabled', 'disabled'); $('#update, #cancel').attr('disabled', 'disabled');
$.ajax({ $.ajax({
url: '@path/@owner/@repository/issues/edit/@issueId', url: '@path/@owner/@repository/issues/edit/@issueId',
type: 'POST', type: 'POST',
data: { data: {
title : $('#edit-title').val(),
content : $('#edit-content').val() content : $('#edit-content').val()
} }
}).done( }).done(
callback callback
).fail(function(req) { ).fail(function(req) {
$('#update, #cancel').removeAttr('disabled'); $('#update, #cancel').removeAttr('disabled');
$('#error-edit-title').text($.parseJSON(req.responseText).title);
}); });
}); });
$('#cancel').click(function(){ $('#cancel-issue').click(function(){
$('#update, #cancel').attr('disabled', 'disabled'); $('#update, #cancel').attr('disabled', 'disabled');
$.get('@path/@owner/@repository/issues/_data/@issueId', callback); $.get('@path/@owner/@repository/issues/_data/@issueId', callback);
return false; return false;

View File

@@ -64,6 +64,7 @@ $(function(){
$('#edit').click(function(){ $('#edit').click(function(){
$('.edit-title').show(); $('.edit-title').show();
$('.show-title').hide(); $('.show-title').hide();
return false;
}); });
$('#update').click(function(){ $('#update').click(function(){
@@ -82,11 +83,13 @@ $(function(){
$(this).removeAttr('disabled'); $(this).removeAttr('disabled');
$('#error-edit-title').text($.parseJSON(req.responseText).title); $('#error-edit-title').text($.parseJSON(req.responseText).title);
}); });
return false;
}); });
$('#cancel').click(function(){ $('#cancel').click(function(){
$('.edit-title').hide(); $('.edit-title').hide();
$('.show-title').show(); $('.show-title').show();
return false;
}); });
}); });
</script> </script>