Add reply form to comment list

Show forms only to signed in users

Signed-off-by: Jonas Franz <info@jonasfranz.software>
This commit is contained in:
Jonas Franz 2018-05-31 13:23:44 +02:00 committed by Jonas Franz
parent 39fcc99583
commit 9a0c3947e0
No known key found for this signature in database
GPG Key ID: 506AEEBE80BEDECD
8 changed files with 92 additions and 52 deletions

File diff suppressed because one or more lines are too long

View File

@ -779,6 +779,15 @@ function initPullRequestReview() {
$("#code-preview-" + id).addClass('hide');
$("#show-outdated-" + id).removeClass('hide');
});
$('.comment-form-reply').on('click', function (e) {
e.preventDefault();
$(this).hide();
var form = $(this).parent().find('.comment-form')
form.removeClass('hide');
assingMenuAttributes(form.find('.menu'));
});
// The following part is only for diff views
if ($('.repository.pull.diff').length == 0) {
return;
}
@ -825,26 +834,28 @@ function initPullRequestReview() {
if (commentCloud.length === 0) {
td.html(form);
commentCloud = td.find('.comment-code-cloud');
var id = Math.floor(Math.random() * Math.floor(1000000));
var menu = commentCloud.find('.menu');
menu.attr('data-write', menu.attr('data-write') + id);
menu.attr('data-preview', menu.attr('data-preview') + id);
menu.find('.item').each(function(i, item) {
$(item).attr('data-tab', $(item).attr('data-tab') + id);
});
assingMenuAttributes(commentCloud.find('.menu'));
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();
});
}
function assingMenuAttributes(menu) {
var id = Math.floor(Math.random() * Math.floor(1000000));
menu.attr('data-write', menu.attr('data-write') + id);
menu.attr('data-preview', menu.attr('data-preview') + id);
menu.find('.item').each(function(i, item) {
$(item).attr('data-tab', $(item).attr('data-tab') + id);
});
initCommentPreviewTab(menu.parent(".form"))
}
function initRepositoryCollaboration() {
console.log('initRepositoryCollaboration');
@ -2470,3 +2481,13 @@ function deleteDueDate(url) {
window.location.reload();
});
}
function cancelCodeComment(btn) {
var form = $(btn).closest("form");
if(form.length > 0 && form.hasClass('comment-form')) {
form.addClass('hide');
form.parent().find('.comment-form-reply').show();
}else {
console.log("Hey");
form.closest('.comment-code-cloud').remove()
}
}

View File

@ -91,4 +91,13 @@
display: block;
}
}
.comment-form-reply {
margin: 0.5em !important;
}
}
.file-comment {
font: 12px Consolas,"Liberation Mono",Menlo,Courier,monospace;
color: rgba(0,0,0,.87);
}

View File

@ -8,7 +8,9 @@
<div class="ui right">
<a class="ui tiny basic toggle button" href="?style={{if .IsSplitStyle}}unified{{else}}split{{end}}">{{ if .IsSplitStyle }}{{.i18n.Tr "repo.diff.show_unified_view"}}{{else}}{{.i18n.Tr "repo.diff.show_split_view"}}{{end}}</a>
<a class="ui tiny basic toggle button" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a>
{{template "repo/diff/new_review" .}}
{{if $.SignedUserID}}
{{template "repo/diff/new_review" .}}
{{end}}
</div>
</div>
<ol class="detail-files hide" id="diff-files">
@ -104,7 +106,7 @@
</td>
<td class="lines-code lines-code-old halfwidth">
{{if not (len $line.Comments)}}
{{if and $.SignedUserID (not (len $line.Comments))}}
<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}}
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
@ -114,7 +116,7 @@
</td>
<td class="lines-code lines-code-new halfwidth">
{{if not (len $line.Comments)}}
{{if and $.SignedUserID (not (len $line.Comments))}}
<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}}
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
@ -129,7 +131,7 @@
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
</ui>
</div>
{{template "repo/diff/comment_form_datahandler" dict "root" $ "comment" (index $line.Comments 0)}}
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "root" $ "comment" (index $line.Comments 0)}}
</div>
</td>
</tr>

View File

@ -1,38 +1,45 @@
<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">{{$.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="{{$.root.i18n.Tr "repo.diff.comment.placeholder"}}"></textarea>
{{if $.root.SignedUserID}}
{{if $.hidden}}
<button class="comment-form-reply ui green labeled icon tiny button"><i class="reply icon"></i> Reply</button>
{{end}}
<form class="ui form {{if $.hidden}}hide comment-form{{end}}" action="{{$.root.Issue.HTMLURL}}/files/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" {{if not $.hidden}}onload="assingMenuAttributes(this)" {{end}}data-write="write" data-preview="preview">
<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>
<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> {{$.root.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
<div class="ui right floated">
{{if $.root.CurrentReview}}
<button name="is_review" value="true" type="submit"
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">{{$.root.i18n.Tr "repo.diff.comment.start_review"}}</button>
<div class="ui bottom attached active tab segment" data-tab="write">
<div class="field">
<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> {{$.root.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
<div class="ui right floated">
{{if not $.reply}}
{{if $.root.CurrentReview}}
<button name="is_review" value="true" type="submit"
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">{{$.root.i18n.Tr "repo.diff.comment.start_review"}}</button>
{{end}}
{{end}}
<button type="submit"
class="ui submit tiny basic button btn-add-single">{{$.root.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
{{end}}
{{if not $.HasComments}}
<button type="button" class="ui submit tiny basic button btn-cancel" onclick="$(this).closest('.comment-code-cloud').remove()">{{$.root.i18n.Tr "cancel"}}</button>
{{end}}
class="ui submit tiny basic button btn-add-single">{{$.root.i18n.Tr "repo.diff.comment.add_single_comment"}}</button>
{{if or (not $.HasComments) $.hidden}}
<button type="button" class="ui submit tiny basic button btn-cancel" onclick="cancelCodeComment(this);">{{$.root.i18n.Tr "cancel"}}</button>
{{end}}
</div>
</div>
</div>
</form>
</form>
{{end}}

View File

@ -1,5 +1,5 @@
{{if $.comment}}
{{ template "repo/diff/comment_form" dict "root" $.root "Line" $.comment.UnsignedLine "File" $.comment.TreePath "Side" $.comment.DiffSide "HasComments" true}}
{{ template "repo/diff/comment_form" dict "root" $.root "hidden" $.hidden "reply" $.reply "Line" $.comment.UnsignedLine "File" $.comment.TreePath "Side" $.comment.DiffSide "HasComments" true}}
{{else if $.root}}
{{ template "repo/diff/comment_form" $}}
{{else}}

View File

@ -16,7 +16,7 @@
</td>
{{end}}
<td class="lines-code {{if (not $line.RightIdx)}}lines-code-old{{end}}">
{{if not (len $line.Comments)}}
{{if and $.SignedUserID (not (len $line.Comments))}}
<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>
{{end}}
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
@ -31,7 +31,7 @@
{{ template "repo/diff/comments" dict "root" $.root "comments" $line.Comments}}
</ui>
</div>
{{template "repo/diff/comment_form_datahandler" dict "root" $.root "comment" (index $line.Comments 0)}}
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "root" $.root "comment" (index $line.Comments 0)}}
</div>
</td>
</tr>

View File

@ -315,6 +315,7 @@
</div>
{{end}}
</div>
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" true "root" $ "comment" (index $comms 0)}}
</div>
</div>
{{end}}