Browse Source

allow to remove comments

pull/946/head
Alexey Makhov 10 years ago
parent
commit
56dfb7ef1e
  1. 1
      cmd/web.go
  2. 6
      models/issue.go
  3. 19
      public/ng/js/gogs.js
  4. 17
      routers/repo/commit.go
  5. 4
      templates/repo/diff.tmpl

1
cmd/web.go

@ -446,6 +446,7 @@ func runWeb(ctx *cli.Context) {
m.Get("/commits/*", repo.RefCommits)
m.Get("/commit/comment/*", repo.GetCommentForm)
m.Get("/commit/*", repo.Diff)
m.Post("/commit/comment/delete/", repo.DeleteCommitComment)
m.Post("/commit/comment/:action/:commitId", repo.CreateCommitComment)
}, middleware.RepoRef())

6
models/issue.go

@ -1089,3 +1089,9 @@ func DeleteAttachmentsByComment(commentId int64, remove bool) (int, error) {
return DeleteAttachments(attachments, remove)
}
func DeleteComment(commentId, userId int64) error {
_, err := x.Delete(&Comment{Id: commentId, PosterId: userId})
return err
}

19
public/ng/js/gogs.js

@ -286,6 +286,25 @@ var Gogs = {};
return false;
});
$('.remove-comment').click(function () {
var commit = document.location.href.match(/([a-zA-Z0-9:\/\/]+)\/commit\/([a-z0-9]+)/);
var url = commit[1] + '/commit/comment/delete/';
$.ajax({
url: url,
data: {comment: $(this).data('id')},
dataType: 'json',
method: 'post',
success: function (json) {
if (json.ok) {
location.reload();
} else {
alert(json.error);
}
}
});
return false;
});
$('.code-diff').on('submit', '#commit-add-comment-form', function () {
var url = $(this).attr('action');
$.ajax({

17
routers/repo/commit.go

@ -457,3 +457,20 @@ func CreateCommitComment(ctx *middleware.Context) {
send(200, fmt.Sprintf("%s/commit/%s#comment-%d", ctx.Repo.RepoLink, commitId, comment.Id), nil)
}
func DeleteCommitComment(ctx *middleware.Context) {
commentId := com.StrTo(ctx.Query("comment")).MustInt64()
if err := models.DeleteComment(int64(commentId), ctx.User.Id); err != nil {
ctx.JSON(200, map[string]interface{}{
"ok": false,
"error": err.Error(),
})
return
}
ctx.JSON(200, map[string]interface{}{
"ok": true,
"data": "ok",
})
}

4
templates/repo/diff.tmpl

@ -140,8 +140,8 @@
{{end}}
{{if $.SignedUser}}
{{if eq $.SignedUser.Id .Poster.Id}}
<a href="#"><i class="octicon octicon-pencil"></i></a>
<a href="#"><i class="octicon octicon-x"></i></a>
<!--<a href="#" class="edit-comment"><i class="octicon octicon-pencil"></i></a>-->
<a href="#" data-id="{{.Id}}" class="remove-comment"><i class="octicon octicon-x"></i></a>
{{end}}
{{end}}
</span>

Loading…
Cancel
Save