Initial ui components for pull request review

This commit is contained in:
Lauris Bukšis-Haberkorns 2018-04-03 00:27:23 +03:00
parent 8685b315a2
commit 85e1ad593a
13 changed files with 293 additions and 43 deletions

View File

@ -59,6 +59,10 @@ issues = Issues
cancel = Cancel cancel = Cancel
write = Write
preview = Preview
loading = Loading…
[install] [install]
install = Installation install = Installation
title = Initial Configuration title = Initial Configuration
@ -1072,6 +1076,17 @@ diff.bin = BIN
diff.view_file = View File diff.view_file = View File
diff.file_suppressed = File diff suppressed because it is too large diff.file_suppressed = File diff suppressed because it is too large
diff.too_many_files = Some files were not shown because too many files changed in this diff diff.too_many_files = Some files were not shown because too many files changed in this diff
diff.comment.placeholder = Leave a comment
diff.comment.markdown_info = Styling with markdown is supported.
diff.comment.add_single_comment = Add single comment
diff.comment.add_review_comment = Add comment
diff.comment.start_review = Start review
diff.review = Review
diff.review.header = Submit review
diff.review.placeholder = Review comment
diff.review.comment = Comment
diff.review.approve = Approve
diff.review.reject = Reject
releases.desc = Track project versions and downloads. releases.desc = Track project versions and downloads.
release.releases = Releases release.releases = Releases
@ -1089,9 +1104,6 @@ release.target = Target
release.tag_helper = Choose an existing tag or create a new tag. release.tag_helper = Choose an existing tag or create a new tag.
release.title = Title release.title = Title
release.content = Content release.content = Content
release.write = Write
release.preview = Preview
release.loading = Loading…
release.prerelease_desc = Mark as Pre-Release release.prerelease_desc = Mark as Pre-Release
release.prerelease_helper = Mark this release unsuitable for production use. release.prerelease_helper = Mark this release unsuitable for production use.
release.cancel = Cancel release.cancel = Cancel

File diff suppressed because one or more lines are too long

View File

@ -727,6 +727,70 @@ function initRepository() {
} }
} }
function initPullRequestReview() {
if ($('.repository.pull.diff').length == 0) {
return;
}
$('.diff-detail-box.ui.sticky').sticky();
$('.btn-review').on('click', function(e) {
e.preventDefault();
$(this).closest('.dropdown').find('.menu').toggle('visible');
});
$('.code-view .lines-code,.code-view .lines-num')
.on('mouseenter', function() {
var parent = $(this).closest('td');
$(this).closest('tr').addClass(
parent.hasClass('lines-num-old') || parent.hasClass('lines-code-old')
? 'focus-lines-old' : 'focus-lines-new'
);
})
.on('mouseleave', function() {
$(this).closest('tr').removeClass('focus-lines-new focus-lines-old');
});
$('.add-code-comment').on('click', function(e) {
e.preventDefault();
var isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
var side = $(this).data('side');
var idx = $(this).data('idx');
var form = $('#pull_review_add_comment').html();
var tr = $(this).closest('tr');
var ntr = tr.next();
if (!ntr.hasClass('add-comment')) {
ntr = $('<tr class="add-comment">'
+ (isSplit ? '<td class="lines-num"></td><td class="add-comment-left"></td><td class="lines-num"></td><td class="add-comment-right"></td>'
: '<td class="lines-num"></td><td class="lines-num"></td><td class="add-comment-left add-comment-right"></td>')
+ '</tr>');
tr.after(ntr);
}
var td = ntr.find('.add-comment-' + side);
var commentCloud = td.find('.comment-code-cloud');
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);
});
commentCloud.find('.tab.segment').each(function(i, item) {
$(item).attr('data-tab', $(item).attr('data-tab') + id);
});
initCommentPreviewTab(commentCloud.find('.form'));
}
commentCloud.find('textarea').focus();
//alert($(this).data('side') + $(this).data('idx'));
});
}
function initRepositoryCollaboration() { function initRepositoryCollaboration() {
console.log('initRepositoryCollaboration'); console.log('initRepositoryCollaboration');
@ -1609,6 +1673,7 @@ $(document).ready(function () {
initCtrlEnterSubmit(); initCtrlEnterSubmit();
initNavbarContentToggle(); initNavbarContentToggle();
initTopicbar(); initTopicbar();
initPullRequestReview();
// Repo clone url. // Repo clone url.
if ($('#repo-clone-url').length > 0) { if ($('#repo-clone-url').length > 0) {

View File

@ -892,8 +892,14 @@
} }
.diff-detail-box { .diff-detail-box {
margin: 15px 0; padding: 7px 0;
background: #fff;
line-height: 30px; line-height: 30px;
>div:after{
clear: both;
content: "";
display: block;
}
ol { ol {
clear: both; clear: both;
padding-left: 0; padding-left: 0;
@ -926,8 +932,9 @@
background-color: #dad8ff; background-color: #dad8ff;
} }
} }
.ui.right { .detail-files {
margin-bottom: 15px; background: #fff;
margin: 0px;
} }
} }
.diff-box .header { .diff-box .header {

94
public/less/_review.less Normal file
View File

@ -0,0 +1,94 @@
.ui.button.add-code-comment {
font-size: 14px;
height: 16px;
padding: 0;
padding-top: 2px;
position: absolute;
width: 16px;
display: none;
&:hover {
font-size:16px;
margin-top: -2px;
margin-left: -2px;
height: 20px;
width: 20px;
}
}
.focus-lines-new .ui.button.add-code-comment.add-code-comment-right,
.focus-lines-old .ui.button.add-code-comment.add-code-comment-left {
display: inline-block;
}
.comment-code-cloud {
padding: 4px;
margin: 0 auto;
position: relative;
border: 1px solid #f1f1f1;
margin-top: 13px;
margin-right: 10px;
margin-bottom: 5px;
&:before {
content: " ";
width: 0;
height: 0;
border-left: 13px solid transparent;
border-right: 13px solid transparent;
border-bottom: 13px solid #f1f1f1;
left: 20px;
position: absolute;
top: -13px;
}
.attached.tab {
border: none;
padding: 0;
margin: 0;
&.markdown {
padding: 1em;
min-height: 168px;
}
}
.right.menu.options .item {
padding: 0.85714286em 0.442857em;
cursor: pointer;
}
.ui.form textarea {
border: 0px;
}
.ui.attached.tabular.menu {
background: #f7f7f7;
border: 1px solid #d4d4d5;
padding-top: 5px;
padding-left: 5px;
margin-top: 0px;
}
.footer {
border-top: 1px solid #f1f1f1;
margin-top: 10px;
.markdown-info {
display: inline-block;
margin: 5px 0;
font-size: 12px;
color: rgba(0,0,0,.6)
}
.ui.right.floated {
padding-top: 6px;
}
&:after{
clear: both;
content: "";
display: block;
}
}
}

View File

@ -12,3 +12,4 @@
@import "_dashboard"; @import "_dashboard";
@import "_admin"; @import "_admin";
@import "_explore"; @import "_explore";
@import "_review";

View File

@ -1,13 +1,14 @@
{{if .DiffNotAvailable}} {{if .DiffNotAvailable}}
<h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4> <h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
{{else}} {{else}}
<div class="diff-detail-box diff-box"> <div class="diff-detail-box diff-box ui sticky">
<div> <div>
<i class="fa fa-retweet"></i> <i class="fa fa-retweet"></i>
{{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}} {{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
<div class="ui right"> <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" 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> <a class="ui tiny basic toggle button" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a>
{{template "repo/diff/new_review" .}}
</div> </div>
</div> </div>
<ol class="detail-files hide" id="diff-files"> <ol class="detail-files hide" id="diff-files">
@ -100,14 +101,20 @@
<tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}"> <tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
<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}}
<a class="ui green button add-code-comment add-code-comment-left" data-side="left" data-idx="{{$line.LeftIdx}}">+</a>
{{end}}
</td> </td>
<td class="lines-code halfwidth"> <td class="lines-code lines-code-old halfwidth">
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre> <pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
</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>
{{if $line.RightIdx}}
<a class="ui green button add-code-comment add-code-comment-right" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
{{end}}
</td> </td>
<td class="lines-code halfwidth"> <td class="lines-code lines-code-new halfwidth">
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre> <pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
</td> </td>
</tr> </tr>
@ -135,6 +142,10 @@
</div> </div>
{{end}} {{end}}
<div id="pull_review_add_comment" class="hide">
{{template "repo/diff/new_comment" .}}
</div>
{{if .IsSplitStyle}} {{if .IsSplitStyle}}
<script> <script>
(function() { (function() {

View File

@ -0,0 +1,33 @@
<div class="field comment-code-cloud">
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<input type="hidden" name="side">
<input type="hidden" name="line">
<input type="hidden" name="path">
<input type="hidden" name="commit_id">
<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>
</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>
</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>
<div class="ui right floated">
<div class="ui submit tiny basic button btn-cancel">{{$.i18n.Tr "cancel"}}</div>
<div class="ui submit tiny basic button btn-add-single">{{$.i18n.Tr "repo.diff.comment.add_single_comment"}}</div>
<div class="ui submit green tiny button btn-add-comment">{{$.i18n.Tr "repo.diff.comment.add_review_comment"}}</div>
<div class="ui submit green tiny button btn-start-review">{{$.i18n.Tr "repo.diff.comment.start_review"}}</div>
</div>
</div>
</form>
</div>

View File

@ -0,0 +1,26 @@
<div class="ui top right pointing dropdown custom">
<div class="ui tiny green button btn-review">
<span class="text">{{.i18n.Tr "repo.diff.review"}}</span>
<i class="dropdown icon"></i>
</div>
<div class="menu">
<div class="ui clearing segment">
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<div class="ui right floated">
<a href="#" class="close"><i class="icon close"></i></a>
</div>
<div class="header">
{{$.i18n.Tr "repo.diff.review.header"}}
</div>
<div class="ui field">
<textarea name="comment" tabindex="0" rows="2" placeholder="{{$.i18n.Tr "repo.diff.review.placeholder"}}"></textarea>
</div>
<div class="ui divider"></div>
<div class="ui submit green tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.approve"}}</div>
<div class="ui submit tiny basic button btn-submit">{{$.i18n.Tr "repo.diff.review.comment"}}</div>
<div class="ui submit red tiny button btn-submit">{{$.i18n.Tr "repo.diff.review.reject"}}</div>
</form>
</div>
</div>
</div>

View File

@ -13,9 +13,10 @@
</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>
</td> </td>
{{end}} {{end}}
<td class="lines-code"> <td class="lines-code {{if (not $line.RightIdx)}}lines-code-old{{end}}">
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre> <pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{$section.GetComputedInlineDiffFor $line}}</code></pre>
</td> </td>
</tr> </tr>

View File

@ -30,7 +30,7 @@
<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff"> <div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
<a class="active item" data-tab="write"><i class="octicon octicon-code"></i> {{if .IsNewFile}}{{.i18n.Tr "repo.editor.new_file"}}{{else}}{{.i18n.Tr "repo.editor.edit_file"}}{{end}}</a> <a class="active item" data-tab="write"><i class="octicon octicon-code"></i> {{if .IsNewFile}}{{.i18n.Tr "repo.editor.new_file"}}{{else}}{{.i18n.Tr "repo.editor.edit_file"}}{{end}}</a>
{{if not .IsNewFile}} {{if not .IsNewFile}}
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-preview-file-modes="{{.PreviewableFileModes}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "repo.release.preview"}}</a> <a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-preview-file-modes="{{.PreviewableFileModes}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "preview"}}</a>
<a class="item" data-tab="diff" data-url="{{.RepoLink}}/_preview/{{.BranchName}}/{{.TreePath}}" data-context="{{.BranchLink}}"><i class="octicon octicon-diff"></i> {{.i18n.Tr "repo.editor.preview_changes"}}</a> <a class="item" data-tab="diff" data-url="{{.RepoLink}}/_preview/{{.BranchName}}/{{.TreePath}}" data-context="{{.BranchLink}}"><i class="octicon octicon-diff"></i> {{.i18n.Tr "repo.editor.preview_changes"}}</a>
{{end}} {{end}}
</div> </div>
@ -44,10 +44,10 @@
{{.FileContent}}</textarea> {{.FileContent}}</textarea>
</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 "repo.release.loading"}} {{.i18n.Tr "loading"}}
</div> </div>
<div class="ui bottom attached tab segment diff" data-tab="diff"> <div class="ui bottom attached tab segment diff" data-tab="diff">
{{.i18n.Tr "repo.release.loading"}} {{.i18n.Tr "loading"}}
</div> </div>
</div> </div>
{{template "repo/editor/commit_form" .}} {{template "repo/editor/commit_form" .}}

View File

@ -1,14 +1,14 @@
<div class="field"> <div class="field">
<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 "repo.release.write"}}</a> <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 "repo.release.preview"}}</a> <a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}">{{.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">
<textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.Repo.RepoLink}}"> <textarea id="content" class="edit_area js-quick-submit" name="content" tabindex="4" data-id="issue-{{.RepoName}}" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.Repo.RepoLink}}">
{{if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end}}</textarea> {{if .IssueTemplate}}{{.IssueTemplate}}{{else if .PullRequestTemplate}}{{.PullRequestTemplate}}{{else}}{{.content}}{{end}}</textarea>
</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 "repo.release.loading"}} {{.i18n.Tr "loading"}}
</div> </div>
</div> </div>
{{if .IsAttachmentEnabled}} {{if .IsAttachmentEnabled}}

View File

@ -111,14 +111,14 @@
<div class="hide" id="edit-content-form"> <div class="hide" id="edit-content-form">
<div class="ui comment form"> <div class="ui comment form">
<div class="ui top attached tabular menu"> <div class="ui top attached tabular menu">
<a class="active write item">{{$.i18n.Tr "repo.release.write"}}</a> <a class="active write item">{{$.i18n.Tr "write"}}</a>
<a class="preview item" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{$.RepoLink}}">{{$.i18n.Tr "repo.release.preview"}}</a> <a class="preview item" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{$.RepoLink}}">{{$.i18n.Tr "preview"}}</a>
</div> </div>
<div class="ui bottom attached active write tab segment"> <div class="ui bottom attached active write tab segment">
<textarea tabindex="1" id="content" name="content"></textarea> <textarea tabindex="1" id="content" name="content"></textarea>
</div> </div>
<div class="ui bottom attached tab preview segment markdown"> <div class="ui bottom attached tab preview segment markdown">
{{$.i18n.Tr "repo.release.loading"}} {{$.i18n.Tr "loading"}}
</div> </div>
<div class="text right edit buttons"> <div class="text right edit buttons">
<div class="ui basic blue cancel button" tabindex="3">{{.i18n.Tr "repo.issues.cancel"}}</div> <div class="ui basic blue cancel button" tabindex="3">{{.i18n.Tr "repo.issues.cancel"}}</div>