forked from gitea/gitea
Comments will be shown at the right place now
Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
parent
ed695c1bf9
commit
de7081c2ab
|
@ -345,11 +345,7 @@ func (c *Comment) getPathAndFile(repoPath string) (string, string) {
|
||||||
func (c *Comment) checkInvalidation(e Engine, repo *git.Repository, branch string) error {
|
func (c *Comment) checkInvalidation(e Engine, repo *git.Repository, branch string) error {
|
||||||
p, file := c.getPathAndFile(repo.Path)
|
p, file := c.getPathAndFile(repo.Path)
|
||||||
// FIXME differentiate between previous and proposed line
|
// FIXME differentiate between previous and proposed line
|
||||||
var line = c.Line
|
commit, err := repo.LineBlame(branch, p, file, uint(c.UnsignedLine()))
|
||||||
if line < 0 {
|
|
||||||
line *= -1
|
|
||||||
}
|
|
||||||
commit, err := repo.LineBlame(branch, p, file, uint(line))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -366,6 +362,22 @@ func (c *Comment) CheckInvalidation(repo *git.Repository, branch string) error {
|
||||||
return c.checkInvalidation(x, repo, branch)
|
return c.checkInvalidation(x, repo, branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiffSide returns "previous" if Comment.Line is a LOC of the previous changes and "proposed" if it is a LOC of the proposed changes.
|
||||||
|
func (c *Comment) DiffSide() string {
|
||||||
|
if c.Line < 0 {
|
||||||
|
return "previous"
|
||||||
|
}
|
||||||
|
return "proposed"
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnsignedLine returns the LOC of the code comment without + or -
|
||||||
|
func (c *Comment) UnsignedLine() uint64 {
|
||||||
|
if c.Line < 0 {
|
||||||
|
return uint64(c.Line * -1)
|
||||||
|
}
|
||||||
|
return uint64(c.Line)
|
||||||
|
}
|
||||||
|
|
||||||
func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) {
|
func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) {
|
||||||
var LabelID int64
|
var LabelID int64
|
||||||
if opts.Label != nil {
|
if opts.Label != nil {
|
||||||
|
|
|
@ -789,6 +789,7 @@ function initPullRequestReview() {
|
||||||
var isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
|
var isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
|
||||||
var side = $(this).data('side');
|
var side = $(this).data('side');
|
||||||
var idx = $(this).data('idx');
|
var idx = $(this).data('idx');
|
||||||
|
var path = $(this).data('path');
|
||||||
var form = $('#pull_review_add_comment').html();
|
var form = $('#pull_review_add_comment').html();
|
||||||
var tr = $(this).closest('tr');
|
var tr = $(this).closest('tr');
|
||||||
var ntr = tr.next();
|
var ntr = tr.next();
|
||||||
|
@ -815,12 +816,12 @@ function initPullRequestReview() {
|
||||||
commentCloud.find('.tab.segment').each(function(i, item) {
|
commentCloud.find('.tab.segment').each(function(i, item) {
|
||||||
$(item).attr('data-tab', $(item).attr('data-tab') + id);
|
$(item).attr('data-tab', $(item).attr('data-tab') + id);
|
||||||
});
|
});
|
||||||
|
td.find("input[name='line']").val(idx);
|
||||||
|
td.find("input[name='side']").val(side === "left" ? "previous":"proposed");
|
||||||
|
td.find("input[name='path']").val(path);
|
||||||
initCommentPreviewTab(commentCloud.find('.form'));
|
initCommentPreviewTab(commentCloud.find('.form'));
|
||||||
}
|
}
|
||||||
commentCloud.find('textarea').focus();
|
commentCloud.find('textarea').focus();
|
||||||
|
|
||||||
|
|
||||||
//alert($(this).data('side') + $(this).data('idx'));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
<td class="lines-num lines-num-old">
|
<td class="lines-num lines-num-old">
|
||||||
<span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
|
<span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
|
||||||
{{if $line.LeftIdx}}
|
{{if $line.LeftIdx}}
|
||||||
<a class="ui green button add-code-comment add-code-comment-left" data-side="left" data-idx="{{$line.LeftIdx}}">+</a>
|
<a class="ui green button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}">+</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
<td class="lines-code lines-code-old halfwidth">
|
<td class="lines-code lines-code-old halfwidth">
|
||||||
|
@ -111,7 +111,7 @@
|
||||||
<td class="lines-num lines-num-new">
|
<td class="lines-num lines-num-new">
|
||||||
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
||||||
{{if $line.RightIdx}}
|
{{if $line.RightIdx}}
|
||||||
<a class="ui green button add-code-comment add-code-comment-right" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
|
<a class="ui green button add-code-comment add-code-comment-right" data-path="{{$file.Name}}" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@
|
||||||
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
|
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
|
||||||
</ui>
|
</ui>
|
||||||
</div>
|
</div>
|
||||||
{{template "repo/diff/comment_form" $}}
|
{{template "repo/diff/comment_form_datahandler" dict "root" $ "comment" (index $line.Comments 0)}}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -158,7 +158,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
<div id="pull_review_add_comment" class="hide">
|
<div id="pull_review_add_comment" class="hide">
|
||||||
{{template "repo/diff/new_comment" .}}
|
{{template "repo/diff/new_comment" dict "root" .}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if .IsSplitStyle}}
|
{{if .IsSplitStyle}}
|
||||||
|
|
|
@ -1,37 +1,36 @@
|
||||||
<form class="ui form" action="{{.Link}}/reviews/comments" method="post">
|
<form class="ui form" action="{{$.root.Link}}/reviews/comments" method="post">
|
||||||
{{.CsrfTokenHtml}}
|
{{$.root.CsrfTokenHtml}}
|
||||||
<input type="hidden" name="side" value="previous">
|
<input type="hidden" name="side" value="{{if $.Side}}{{$.Side}}{{end}}">
|
||||||
<input type="hidden" name="line" value="2">
|
<input type="hidden" name="line" value="{{if $.Line}}{{$.Line}}{{end}}">
|
||||||
<input type="hidden" name="path" value="README.md">
|
<input type="hidden" name="path" value="{{if $.File}}{{$.File}}{{end}}">
|
||||||
<input type="hidden" name="commit_id" value="e324f1688f063d6fd9268fb8f02149c9eb1a867c">
|
|
||||||
<input type="hidden" name="diff_start_cid">
|
<input type="hidden" name="diff_start_cid">
|
||||||
<input type="hidden" name="diff_end_cid">
|
<input type="hidden" name="diff_end_cid">
|
||||||
<input type="hidden" name="diff_base_cid">
|
<input type="hidden" name="diff_base_cid">
|
||||||
<div class="ui top attached tabular menu" data-write="write" data-preview="preview">
|
<div class="ui top attached tabular menu" data-write="write" data-preview="preview">
|
||||||
<a class="active item" data-tab="write">{{.i18n.Tr "write"}}</a>
|
<a class="active item" data-tab="write">{{$.root.i18n.Tr "write"}}</a>
|
||||||
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}">{{.i18n.Tr "preview"}}</a>
|
<a class="item" data-tab="preview" data-url="{{$.root.AppSubUrl}}/api/v1/markdown" data-context="{{$.root.RepoLink}}">{{$.root.i18n.Tr "preview"}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui bottom attached active tab segment" data-tab="write">
|
<div class="ui bottom attached active tab segment" data-tab="write">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<textarea name="content" placeholder="{{$.i18n.Tr "repo.diff.comment.placeholder"}}"></textarea>
|
<textarea name="content" placeholder="{{$.root.i18n.Tr "repo.diff.comment.placeholder"}}"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui bottom attached tab segment markdown" data-tab="preview">
|
<div class="ui bottom attached tab segment markdown" data-tab="preview">
|
||||||
{{.i18n.Tr "loading"}}
|
{{.i18n.Tr "loading"}}
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<span class="markdown-info"><i class="octicon octicon-markdown"></i> {{$.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
|
<span class="markdown-info"><i class="octicon octicon-markdown"></i> {{$.root.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
|
||||||
<div class="ui right floated">
|
<div class="ui right floated">
|
||||||
{{if $.CurrentReview}}
|
{{if $.root.CurrentReview}}
|
||||||
<button name="is_review" value="true" type="submit"
|
<button name="is_review" value="true" type="submit"
|
||||||
class="ui submit green tiny button btn-add-comment">{{$.i18n.Tr "repo.diff.comment.add_review_comment"}}</button>
|
class="ui submit green tiny button btn-add-comment">{{$.root.i18n.Tr "repo.diff.comment.add_review_comment"}}</button>
|
||||||
{{else}}
|
{{else}}
|
||||||
<button name="is_review" value="true" type="submit"
|
<button name="is_review" value="true" type="submit"
|
||||||
class="ui submit green tiny button btn-start-review">{{$.i18n.Tr "repo.diff.comment.start_review"}}</button>
|
class="ui submit green tiny button btn-start-review">{{$.root.i18n.Tr "repo.diff.comment.start_review"}}</button>
|
||||||
{{end}}
|
{{end}}
|
||||||
<button type="submit"
|
<button type="submit"
|
||||||
class="ui submit tiny basic button btn-add-single">{{$.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
|
class="ui submit tiny basic button btn-add-single">{{$.root.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
|
||||||
<button type="button" class="ui submit tiny basic button btn-cancel">{{$.i18n.Tr "cancel"}}</button>
|
<button type="button" class="ui submit tiny basic button btn-cancel">{{$.root.i18n.Tr "cancel"}}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{{if $.comment}}
|
||||||
|
{{ template "repo/diff/comment_form" dict "root" $.root "Line" $.comment.UnsignedLine "File" $.comment.TreePath "Side" $.comment.DiffSide}}
|
||||||
|
{{else if $.root}}
|
||||||
|
{{ template "repo/diff/comment_form" $}}
|
||||||
|
{{else}}
|
||||||
|
{{ template "repo/diff/comment_form" dict "root" $}}
|
||||||
|
{{end}}
|
|
@ -1,3 +1,3 @@
|
||||||
<div class="field comment-code-cloud">
|
<div class="field comment-code-cloud">
|
||||||
{{ template "repo/diff/comment_form" .}}
|
{{template "repo/diff/comment_form_datahandler" .}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td class="lines-num lines-num-new">
|
<td class="lines-num lines-num-new">
|
||||||
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
|
||||||
<a class="ui green button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">+</a>
|
<a class="ui green button add-code-comment add-code-comment-{{if $line.RightIdx}}right{{else}}left{{end}}" data-path="{{$file.Name}}" data-side="{{if $line.RightIdx}}right{{else}}left{{end}}" data-idx="{{if $line.RightIdx}}{{$line.RightIdx}}{{else}}{{$line.LeftIdx}}{{end}}">+</a>
|
||||||
</td>
|
</td>
|
||||||
{{end}}
|
{{end}}
|
||||||
<td class="lines-code {{if (not $line.RightIdx)}}lines-code-old{{end}}">
|
<td class="lines-code {{if (not $line.RightIdx)}}lines-code-old{{end}}">
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
{{ template "repo/diff/comments" dict "root" $.root "comments" $line.Comments}}
|
{{ template "repo/diff/comments" dict "root" $.root "comments" $line.Comments}}
|
||||||
</ui>
|
</ui>
|
||||||
</div>
|
</div>
|
||||||
{{template "repo/diff/comment_form" $.root }}
|
{{template "repo/diff/comment_form_datahandler" dict "root" $.root "comment" (index $line.Comments 0)}}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Reference in New Issue