diff --git a/models/issue.go b/models/issue.go index 41f94c346..615f54686 100644 --- a/models/issue.go +++ b/models/issue.go @@ -940,6 +940,17 @@ func CreateComment(userId, repoId, issueId int64, commitId, line string, cmtType return comment, sess.Commit() } +// UpdateComment update comment +func UpdateComment(comment *Comment) error { + _, err := x.Id(comment.Id).AllCols().Update(comment) + + if err != nil { + return err + } + + return err +} + // GetCommentById returns the comment with the given id func GetCommentById(commentId int64) (*Comment, error) { c := &Comment{Id: commentId} diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 9e02a8136..c2c759025 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -1696,6 +1696,9 @@ The register and sign-in page style background-color: #FFF8D2 !important; border-color: #F0DB88 !important; } +.diff-file-box .code-diff tbody tr.add-comment td { + padding: 10px; +} .diff-file-box .code-diff tbody tr.add-comment:hover td, .diff-file-box .code-diff tbody tr.comment:hover td, .diff-file-box .code-diff tbody tr.add-comment:hover pre, diff --git a/public/ng/js/gogs.js b/public/ng/js/gogs.js index c8bded524..3a68a79cd 100644 --- a/public/ng/js/gogs.js +++ b/public/ng/js/gogs.js @@ -240,7 +240,7 @@ var Gogs = {}; function prepareToForm() { $('.add-comment').hide('fast', function(){ $(this).remove(); }); - $('button.answer').show(); + $('button.answer').hide(); } $(document).on('click', '.code-diff .lines-num span', function (e) { @@ -270,38 +270,73 @@ var Gogs = {}; var elem = (commentTr.length > 0) ? commentTr : $(this).parents('tr'); var url = commit[1] + '/commit/comment/' + commit[2]; elem.after( - $('').load(url + '?line=' + lineNum, function () { - $('.menu-line.add-nav').tabs(); - $('#pull-commit-preview').markdown_preview(".commit-add-comment"); - $('body').animate({ - scrollTop: $(this).offset().top - 33 // height of button - }, 1000); - }) + $('').append( + $('').load(url + '?line=' + lineNum, function () { + $('.menu-line.add-nav').tabs(); + $('#pull-commit-preview').markdown_preview(".commit-add-comment"); + $('body').animate({ + scrollTop: $(this).offset().top - 33 // height of button + }, 1000); + }) + ) ); } }); $('.code-diff').on('click', '#cancel-commit-conversation', function () { prepareToForm(); + $('button.answer').show(); return false; }); - $('.remove-comment').click(function () { + + $('.code-diff').on('click', '#cancel-edit-commit-conversation', function () { + prepareToForm(); + $(this).parents('.commit-comment').children().show(); + $(this).parents('#commit-conversation').parent().remove(); + $('button.answer').show(); + return false; + }); + + $('.edit-comment').click(function () { + prepareToForm(); + var text = $(this).parents('div.panel:first').find('.markdown').text(); + var id = $(this).parents('.commit-comment').attr('id'); + id = id.substr(15); 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); + var url = commit[1] + '/commit/comment/' + commit[2]; + $(this).parents('.commit-comment').children().hide(); + $(this).parents('.commit-comment').append( + $('
').load(url + '?id='+id, function () { + $('.menu-line.add-nav').tabs(); + $('#pull-commit-preview').markdown_preview(".commit-add-comment"); + $('#commit-add-content').text(text.trim()); + $('body').animate({ + scrollTop: $(this).offset().top - 33 // height of button + }, 1000); + }) + ) + return false; + }); + + $('.remove-comment').click(function () { + if (confirm('Are you sure?')) { + 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; }); diff --git a/public/ng/less/gogs/repository.less b/public/ng/less/gogs/repository.less index cc9acd3a9..69bc02beb 100644 --- a/public/ng/less/gogs/repository.less +++ b/public/ng/less/gogs/repository.less @@ -727,6 +727,11 @@ border-color: #F0DB88 !important; } } + &.add-comment { + td { + padding: 10px; + } + } &.add-comment:hover, &.comment:hover { td, pre { background-color: #FFFFFF !important; diff --git a/routers/repo/commit.go b/routers/repo/commit.go index fded732a0..73ff2b0c5 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -362,6 +362,7 @@ func CompareDiff(ctx *middleware.Context) { func GetCommentForm(ctx *middleware.Context) { ctx.Data["Repo"] = ctx.Repo ctx.Data["Line"] = ctx.Query("line") + ctx.Data["CommentId"] = ctx.Query("id") ctx.HTML(200, COMMENT_FORM) } @@ -385,19 +386,39 @@ func CreateCommitComment(ctx *middleware.Context) { } } var comment *models.Comment + var err error commitId := ctx.ParamsEscape(":commitId") content := ctx.Query("content") - line := ctx.Query("line") - lineRe, err := regexp.Compile("[0-9]+L[0-9]+") - if len(content) > 0 && lineRe.MatchString(line) { + if len(content) > 0 { switch ctx.Params(":action") { case "new": + line := ctx.Query("line") + lineRe, err := regexp.Compile("[0-9]+L[0-9]+") + if len(line) > 0 && !lineRe.MatchString(line) { + err := errors.New("Something went wrong") + send(200, err.Error(), err) + return + } if comment, err = models.CreateComment(ctx.User.Id, ctx.Repo.Repository.Id, 0, commitId, line, models.COMMENT_TYPE_COMMENT, content, nil); err != nil { send(500, nil, err) return } log.Trace("%s Comment created: %s", ctx.Req.RequestURI, commitId) + case "edit": + commentId := com.StrTo(ctx.Query("id")).MustInt64() + comment, err = models.GetCommentById(commentId) + if err != nil { + send(500, nil, err) + return + } + + comment.Content = content + if err = models.UpdateComment(comment); err != nil { + send(500, nil, err) + return + } + log.Trace("%s Comment updated: %v", ctx.Req.RequestURI, comment.Id) default: ctx.Handle(404, "commit.Comment", err) return diff --git a/templates/repo/comment_form.tmpl b/templates/repo/comment_form.tmpl index d34f45bcf..d610cce8d 100644 --- a/templates/repo/comment_form.tmpl +++ b/templates/repo/comment_form.tmpl @@ -1,6 +1,6 @@ - + {{if .SignedUser}} -
+
@@ -16,12 +16,16 @@
-
+ {{.CsrfTokenHtml}} + {{if .CommentId}} + + {{else}} + {{end}}

-    +   

@@ -34,4 +38,4 @@
{{else}}
Sign up for free to join this conversation. Already have an account? Sign in to comment
{{end}} - + diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 2893f9a66..aaf76386b 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -134,17 +134,17 @@

{{.Poster.Name}} {{TimeSince .Created $.Lang}} - - {{if eq $.Repository.Owner.Id .Poster.Id}} - {{$.i18n.Tr "repo.owner"}} - {{end}} - {{if $.SignedUser}} - {{if eq $.SignedUser.Id .Poster.Id}} - - - {{end}} - {{end}} - + + {{if eq $.Repository.Owner.Id .Poster.Id}} + {{$.i18n.Tr "repo.owner"}} + {{end}} + {{if $.SignedUser}} + {{if eq $.SignedUser.Id .Poster.Id}} + + + {{end}} + {{end}} +