mirror of
https://github.com/go-gitea/gitea
synced 2025-01-11 06:05:57 +01:00
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 {
|
||||
p, file := c.getPathAndFile(repo.Path)
|
||||
// FIXME differentiate between previous and proposed line
|
||||
var line = c.Line
|
||||
if line < 0 {
|
||||
line *= -1
|
||||
}
|
||||
commit, err := repo.LineBlame(branch, p, file, uint(line))
|
||||
commit, err := repo.LineBlame(branch, p, file, uint(c.UnsignedLine()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -366,6 +362,22 @@ func (c *Comment) CheckInvalidation(repo *git.Repository, branch string) error {
|
||||
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) {
|
||||
var LabelID int64
|
||||
if opts.Label != nil {
|
||||
|
@ -789,6 +789,7 @@ function initPullRequestReview() {
|
||||
var isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
|
||||
var side = $(this).data('side');
|
||||
var idx = $(this).data('idx');
|
||||
var path = $(this).data('path');
|
||||
var form = $('#pull_review_add_comment').html();
|
||||
var tr = $(this).closest('tr');
|
||||
var ntr = tr.next();
|
||||
@ -815,12 +816,12 @@ function initPullRequestReview() {
|
||||
commentCloud.find('.tab.segment').each(function(i, item) {
|
||||
$(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'));
|
||||
}
|
||||
commentCloud.find('textarea').focus();
|
||||
|
||||
|
||||
//alert($(this).data('side') + $(this).data('idx'));
|
||||
});
|
||||
}
|
||||
|
||||
@ -2265,7 +2266,7 @@ function initTopicbar() {
|
||||
return
|
||||
}
|
||||
var topicArray = topics.split(",");
|
||||
|
||||
|
||||
var last = viewDiv.children("a").last();
|
||||
for (var i=0;i < topicArray.length; i++) {
|
||||
$('<div class="ui green basic label topic" style="cursor:pointer;">'+topicArray[i]+'</div>').insertBefore(last)
|
||||
|
@ -102,7 +102,7 @@
|
||||
<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>
|
||||
{{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}}
|
||||
</td>
|
||||
<td class="lines-code lines-code-old halfwidth">
|
||||
@ -111,7 +111,7 @@
|
||||
<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>
|
||||
{{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}}
|
||||
</td>
|
||||
|
||||
@ -128,7 +128,7 @@
|
||||
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
|
||||
</ui>
|
||||
</div>
|
||||
{{template "repo/diff/comment_form" $}}
|
||||
{{template "repo/diff/comment_form_datahandler" dict "root" $ "comment" (index $line.Comments 0)}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@ -158,7 +158,7 @@
|
||||
{{end}}
|
||||
|
||||
<div id="pull_review_add_comment" class="hide">
|
||||
{{template "repo/diff/new_comment" .}}
|
||||
{{template "repo/diff/new_comment" dict "root" .}}
|
||||
</div>
|
||||
|
||||
{{if .IsSplitStyle}}
|
||||
|
@ -1,37 +1,36 @@
|
||||
<form class="ui form" action="{{.Link}}/reviews/comments" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<input type="hidden" name="side" value="previous">
|
||||
<input type="hidden" name="line" value="2">
|
||||
<input type="hidden" name="path" value="README.md">
|
||||
<input type="hidden" name="commit_id" value="e324f1688f063d6fd9268fb8f02149c9eb1a867c">
|
||||
<form class="ui form" action="{{$.root.Link}}/reviews/comments" method="post">
|
||||
{{$.root.CsrfTokenHtml}}
|
||||
<input type="hidden" name="side" value="{{if $.Side}}{{$.Side}}{{end}}">
|
||||
<input type="hidden" name="line" value="{{if $.Line}}{{$.Line}}{{end}}">
|
||||
<input type="hidden" name="path" value="{{if $.File}}{{$.File}}{{end}}">
|
||||
<input type="hidden" name="diff_start_cid">
|
||||
<input type="hidden" name="diff_end_cid">
|
||||
<input type="hidden" name="diff_base_cid">
|
||||
<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="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}">{{.i18n.Tr "preview"}}</a>
|
||||
<a class="active item" data-tab="write">{{$.root.i18n.Tr "write"}}</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 class="ui bottom attached active tab segment" data-tab="write">
|
||||
<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 class="ui bottom attached tab segment markdown" data-tab="preview">
|
||||
{{.i18n.Tr "loading"}}
|
||||
</div>
|
||||
<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">
|
||||
{{if $.CurrentReview}}
|
||||
{{if $.root.CurrentReview}}
|
||||
<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}}
|
||||
<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}}
|
||||
<button type="submit"
|
||||
class="ui submit tiny basic button btn-add-single">{{$.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
|
||||
<button type="button" class="ui submit tiny basic button btn-cancel">{{$.i18n.Tr "cancel"}}</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">{{$.root.i18n.Tr "cancel"}}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
7
templates/repo/diff/comment_form_datahandler.tmpl
Normal file
7
templates/repo/diff/comment_form_datahandler.tmpl
Normal file
@ -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">
|
||||
{{ template "repo/diff/comment_form" .}}
|
||||
{{template "repo/diff/comment_form_datahandler" .}}
|
||||
</div>
|
||||
|
@ -13,7 +13,7 @@
|
||||
</td>
|
||||
<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>
|
||||
<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>
|
||||
{{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}}
|
||||
</ui>
|
||||
</div>
|
||||
{{template "repo/diff/comment_form" $.root }}
|
||||
{{template "repo/diff/comment_form_datahandler" dict "root" $.root "comment" (index $line.Comments 0)}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user