Skip to content

Commit 85e1ad5

Browse files
committed
Initial ui components for pull request review
1 parent 8685b31 commit 85e1ad5

File tree

13 files changed

+293
-43
lines changed

13 files changed

+293
-43
lines changed

options/locale/locale_en-US.ini

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ issues = Issues
5959

6060
cancel = Cancel
6161

62+
write = Write
63+
preview = Preview
64+
loading = Loading…
65+
6266
[install]
6367
install = Installation
6468
title = Initial Configuration
@@ -1072,6 +1076,17 @@ diff.bin = BIN
10721076
diff.view_file = View File
10731077
diff.file_suppressed = File diff suppressed because it is too large
10741078
diff.too_many_files = Some files were not shown because too many files changed in this diff
1079+
diff.comment.placeholder = Leave a comment
1080+
diff.comment.markdown_info = Styling with markdown is supported.
1081+
diff.comment.add_single_comment = Add single comment
1082+
diff.comment.add_review_comment = Add comment
1083+
diff.comment.start_review = Start review
1084+
diff.review = Review
1085+
diff.review.header = Submit review
1086+
diff.review.placeholder = Review comment
1087+
diff.review.comment = Comment
1088+
diff.review.approve = Approve
1089+
diff.review.reject = Reject
10751090
10761091
releases.desc = Track project versions and downloads.
10771092
release.releases = Releases
@@ -1089,9 +1104,6 @@ release.target = Target
10891104
release.tag_helper = Choose an existing tag or create a new tag.
10901105
release.title = Title
10911106
release.content = Content
1092-
release.write = Write
1093-
release.preview = Preview
1094-
release.loading = Loading…
10951107
release.prerelease_desc = Mark as Pre-Release
10961108
release.prerelease_helper = Mark this release unsuitable for production use.
10971109
release.cancel = Cancel

public/css/index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/index.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,70 @@ function initRepository() {
727727
}
728728
}
729729

730+
function initPullRequestReview() {
731+
if ($('.repository.pull.diff').length == 0) {
732+
return;
733+
}
734+
735+
$('.diff-detail-box.ui.sticky').sticky();
736+
737+
$('.btn-review').on('click', function(e) {
738+
e.preventDefault();
739+
$(this).closest('.dropdown').find('.menu').toggle('visible');
740+
});
741+
742+
$('.code-view .lines-code,.code-view .lines-num')
743+
.on('mouseenter', function() {
744+
var parent = $(this).closest('td');
745+
$(this).closest('tr').addClass(
746+
parent.hasClass('lines-num-old') || parent.hasClass('lines-code-old')
747+
? 'focus-lines-old' : 'focus-lines-new'
748+
);
749+
})
750+
.on('mouseleave', function() {
751+
$(this).closest('tr').removeClass('focus-lines-new focus-lines-old');
752+
});
753+
$('.add-code-comment').on('click', function(e) {
754+
e.preventDefault();
755+
var isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
756+
var side = $(this).data('side');
757+
var idx = $(this).data('idx');
758+
var form = $('#pull_review_add_comment').html();
759+
var tr = $(this).closest('tr');
760+
var ntr = tr.next();
761+
if (!ntr.hasClass('add-comment')) {
762+
ntr = $('<tr class="add-comment">'
763+
+ (isSplit ? '<td class="lines-num"></td><td class="add-comment-left"></td><td class="lines-num"></td><td class="add-comment-right"></td>'
764+
: '<td class="lines-num"></td><td class="lines-num"></td><td class="add-comment-left add-comment-right"></td>')
765+
+ '</tr>');
766+
tr.after(ntr);
767+
}
768+
var td = ntr.find('.add-comment-' + side);
769+
var commentCloud = td.find('.comment-code-cloud');
770+
if (commentCloud.length === 0) {
771+
td.html(form);
772+
commentCloud = td.find('.comment-code-cloud');
773+
774+
var id = Math.floor(Math.random() * Math.floor(1000000));
775+
var menu = commentCloud.find('.menu');
776+
menu.attr('data-write', menu.attr('data-write') + id);
777+
menu.attr('data-preview', menu.attr('data-preview') + id);
778+
menu.find('.item').each(function(i, item) {
779+
$(item).attr('data-tab', $(item).attr('data-tab') + id);
780+
});
781+
commentCloud.find('.tab.segment').each(function(i, item) {
782+
$(item).attr('data-tab', $(item).attr('data-tab') + id);
783+
});
784+
785+
initCommentPreviewTab(commentCloud.find('.form'));
786+
}
787+
commentCloud.find('textarea').focus();
788+
789+
790+
//alert($(this).data('side') + $(this).data('idx'));
791+
});
792+
}
793+
730794
function initRepositoryCollaboration() {
731795
console.log('initRepositoryCollaboration');
732796

@@ -1609,6 +1673,7 @@ $(document).ready(function () {
16091673
initCtrlEnterSubmit();
16101674
initNavbarContentToggle();
16111675
initTopicbar();
1676+
initPullRequestReview();
16121677

16131678
// Repo clone url.
16141679
if ($('#repo-clone-url').length > 0) {

public/less/_repository.less

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -862,38 +862,44 @@
862862
width: 140px;
863863
}
864864
}
865-
td.sha .sha.label {
866-
margin: 0;
867-
}
865+
td.sha .sha.label {
866+
margin: 0;
867+
}
868868
&.ui.basic.striped.table tbody tr:nth-child(2n) {
869869
background-color: rgba(0, 0, 0, .02)!important;
870870
}
871871
}
872872

873-
#commits-table td.sha .sha.label, #repo-files-table .sha.label{
874-
&.isSigned{
875-
border: 1px solid #BBB;
876-
.detail.icon{
877-
background: #FAFAFA;
878-
margin: -6px -10px -4px 0px;
879-
padding: 5px 3px 5px 6px;
880-
border-left: 1px solid #BBB;
881-
border-top-left-radius: 0;
882-
border-bottom-left-radius: 0;
883-
}
884-
}
885-
&.isSigned.isVerified{
886-
border: 1px solid #21BA45;
887-
background: #21BA4518;
888-
.detail.icon{
889-
border-left: 1px solid #21BA4580;
890-
}
891-
}
873+
#commits-table td.sha .sha.label, #repo-files-table .sha.label{
874+
&.isSigned{
875+
border: 1px solid #BBB;
876+
.detail.icon{
877+
background: #FAFAFA;
878+
margin: -6px -10px -4px 0px;
879+
padding: 5px 3px 5px 6px;
880+
border-left: 1px solid #BBB;
881+
border-top-left-radius: 0;
882+
border-bottom-left-radius: 0;
883+
}
884+
}
885+
&.isSigned.isVerified{
886+
border: 1px solid #21BA45;
887+
background: #21BA4518;
888+
.detail.icon{
889+
border-left: 1px solid #21BA4580;
890+
}
892891
}
892+
}
893893

894894
.diff-detail-box {
895-
margin: 15px 0;
895+
padding: 7px 0;
896+
background: #fff;
896897
line-height: 30px;
898+
>div:after{
899+
clear: both;
900+
content: "";
901+
display: block;
902+
}
897903
ol {
898904
clear: both;
899905
padding-left: 0;
@@ -926,8 +932,9 @@
926932
background-color: #dad8ff;
927933
}
928934
}
929-
.ui.right {
930-
margin-bottom: 15px;
935+
.detail-files {
936+
background: #fff;
937+
margin: 0px;
931938
}
932939
}
933940
.diff-box .header {

public/less/_review.less

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
.ui.button.add-code-comment {
2+
font-size: 14px;
3+
height: 16px;
4+
padding: 0;
5+
padding-top: 2px;
6+
position: absolute;
7+
width: 16px;
8+
display: none;
9+
10+
&:hover {
11+
font-size:16px;
12+
margin-top: -2px;
13+
margin-left: -2px;
14+
height: 20px;
15+
width: 20px;
16+
}
17+
}
18+
19+
.focus-lines-new .ui.button.add-code-comment.add-code-comment-right,
20+
.focus-lines-old .ui.button.add-code-comment.add-code-comment-left {
21+
display: inline-block;
22+
}
23+
24+
.comment-code-cloud {
25+
padding: 4px;
26+
margin: 0 auto;
27+
position: relative;
28+
border: 1px solid #f1f1f1;
29+
margin-top: 13px;
30+
margin-right: 10px;
31+
margin-bottom: 5px;
32+
33+
&:before {
34+
content: " ";
35+
width: 0;
36+
height: 0;
37+
border-left: 13px solid transparent;
38+
border-right: 13px solid transparent;
39+
border-bottom: 13px solid #f1f1f1;
40+
left: 20px;
41+
position: absolute;
42+
top: -13px;
43+
}
44+
45+
.attached.tab {
46+
border: none;
47+
padding: 0;
48+
margin: 0;
49+
50+
&.markdown {
51+
padding: 1em;
52+
min-height: 168px;
53+
}
54+
}
55+
56+
.right.menu.options .item {
57+
padding: 0.85714286em 0.442857em;
58+
cursor: pointer;
59+
}
60+
61+
.ui.form textarea {
62+
border: 0px;
63+
}
64+
65+
.ui.attached.tabular.menu {
66+
background: #f7f7f7;
67+
border: 1px solid #d4d4d5;
68+
padding-top: 5px;
69+
padding-left: 5px;
70+
margin-top: 0px;
71+
}
72+
73+
.footer {
74+
border-top: 1px solid #f1f1f1;
75+
margin-top: 10px;
76+
77+
.markdown-info {
78+
display: inline-block;
79+
margin: 5px 0;
80+
font-size: 12px;
81+
color: rgba(0,0,0,.6)
82+
}
83+
84+
.ui.right.floated {
85+
padding-top: 6px;
86+
}
87+
88+
&:after{
89+
clear: both;
90+
content: "";
91+
display: block;
92+
}
93+
}
94+
}

public/less/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
@import "_dashboard";
1313
@import "_admin";
1414
@import "_explore";
15+
@import "_review";

templates/repo/diff/box.tmpl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{{if .DiffNotAvailable}}
22
<h4>{{.i18n.Tr "repo.diff.data_not_available"}}</h4>
33
{{else}}
4-
<div class="diff-detail-box diff-box">
4+
<div class="diff-detail-box diff-box ui sticky">
55
<div>
66
<i class="fa fa-retweet"></i>
77
{{.i18n.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
88
<div class="ui right">
99
<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>
1010
<a class="ui tiny basic toggle button" data-target="#diff-files">{{.i18n.Tr "repo.diff.show_diff_stats"}}</a>
11+
{{template "repo/diff/new_review" .}}
1112
</div>
1213
</div>
1314
<ol class="detail-files hide" id="diff-files">
@@ -100,14 +101,20 @@
100101
<tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
101102
<td class="lines-num lines-num-old">
102103
<span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}">{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}</span>
104+
{{if $line.LeftIdx}}
105+
<a class="ui green button add-code-comment add-code-comment-left" data-side="left" data-idx="{{$line.LeftIdx}}">+</a>
106+
{{end}}
103107
</td>
104-
<td class="lines-code halfwidth">
108+
<td class="lines-code lines-code-old halfwidth">
105109
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
106110
</td>
107111
<td class="lines-num lines-num-new">
108112
<span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}">{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}</span>
113+
{{if $line.RightIdx}}
114+
<a class="ui green button add-code-comment add-code-comment-right" data-side="right" data-idx="{{$line.RightIdx}}">+</a>
115+
{{end}}
109116
</td>
110-
<td class="lines-code halfwidth">
117+
<td class="lines-code lines-code-new halfwidth">
111118
<pre><code class="wrap {{if $highlightClass}}language-{{$highlightClass}}{{else}}nohighlight{{end}}">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</code></pre>
112119
</td>
113120
</tr>
@@ -135,6 +142,10 @@
135142
</div>
136143
{{end}}
137144

145+
<div id="pull_review_add_comment" class="hide">
146+
{{template "repo/diff/new_comment" .}}
147+
</div>
148+
138149
{{if .IsSplitStyle}}
139150
<script>
140151
(function() {

templates/repo/diff/new_comment.tmpl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div class="field comment-code-cloud">
2+
<form class="ui form" action="{{.Link}}" method="post">
3+
{{.CsrfTokenHtml}}
4+
<input type="hidden" name="side">
5+
<input type="hidden" name="line">
6+
<input type="hidden" name="path">
7+
<input type="hidden" name="commit_id">
8+
<input type="hidden" name="diff_start_cid">
9+
<input type="hidden" name="diff_end_cid">
10+
<input type="hidden" name="diff_base_cid">
11+
<div class="ui top attached tabular menu" data-write="write" data-preview="preview">
12+
<a class="active item" data-tab="write">{{.i18n.Tr "write"}}</a>
13+
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}">{{.i18n.Tr "preview"}}</a>
14+
</div>
15+
<div class="ui bottom attached active tab segment" data-tab="write">
16+
<div class="field">
17+
<textarea name="content" placeholder="{{$.i18n.Tr "repo.diff.comment.placeholder"}}"></textarea>
18+
</div>
19+
</div>
20+
<div class="ui bottom attached tab segment markdown" data-tab="preview">
21+
{{.i18n.Tr "loading"}}
22+
</div>
23+
<div class="footer">
24+
<span class="markdown-info"><i class="octicon octicon-markdown"></i> {{$.i18n.Tr "repo.diff.comment.markdown_info"}}</span>
25+
<div class="ui right floated">
26+
<div class="ui submit tiny basic button btn-cancel">{{$.i18n.Tr "cancel"}}</div>
27+
<div class="ui submit tiny basic button btn-add-single">{{$.i18n.Tr "repo.diff.comment.add_single_comment"}}</div>
28+
<div class="ui submit green tiny button btn-add-comment">{{$.i18n.Tr "repo.diff.comment.add_review_comment"}}</div>
29+
<div class="ui submit green tiny button btn-start-review">{{$.i18n.Tr "repo.diff.comment.start_review"}}</div>
30+
</div>
31+
</div>
32+
</form>
33+
</div>

0 commit comments

Comments
 (0)