##// END OF EJS Templates
comments: enabled resolution for general comments, and finalized how general comment is build
marcink -
r1326:e70e0f00 default
parent child Browse files
Show More
@@ -335,6 +335,7 b' class ChangesetController(BaseRepoContro'
335 status = request.POST.get('changeset_status', None)
335 status = request.POST.get('changeset_status', None)
336 text = request.POST.get('text')
336 text = request.POST.get('text')
337 comment_type = request.POST.get('comment_type')
337 comment_type = request.POST.get('comment_type')
338 resolves_comment_id = request.POST.get('resolves_comment_id', None)
338
339
339 if status:
340 if status:
340 text = text or (_('Status change %(transition_icon)s %(status)s')
341 text = text or (_('Status change %(transition_icon)s %(status)s')
@@ -358,7 +359,8 b' class ChangesetController(BaseRepoContro'
358 status_change=(ChangesetStatus.get_status_lbl(status)
359 status_change=(ChangesetStatus.get_status_lbl(status)
359 if status else None),
360 if status else None),
360 status_change_type=status,
361 status_change_type=status,
361 comment_type=comment_type
362 comment_type=comment_type,
363 resolves_comment_id=resolves_comment_id
362 )
364 )
363 c.inline_comment = True if comment.line_no else False
365 c.inline_comment = True if comment.line_no else False
364
366
@@ -904,7 +904,7 b' class PullrequestsController(BaseRepoCon'
904 status = request.POST.get('changeset_status', None)
904 status = request.POST.get('changeset_status', None)
905 text = request.POST.get('text')
905 text = request.POST.get('text')
906 comment_type = request.POST.get('comment_type')
906 comment_type = request.POST.get('comment_type')
907 resolves_comment_id = request.POST.get('resolves_comment_id')
907 resolves_comment_id = request.POST.get('resolves_comment_id', None)
908
908
909 if status and '_closed' in status:
909 if status and '_closed' in status:
910 close_pr = True
910 close_pr = True
@@ -72,6 +72,26 b' tr.inline-comments div {'
72 color: @color5;
72 color: @color5;
73 font-family: @text-bold-italic;
73 font-family: @text-bold-italic;
74 }
74 }
75
76 .resolve {
77 cursor: pointer;
78 text-decoration: underline;
79 }
80
81 .resolved {
82 text-decoration: line-through;
83 color: @color1;
84 }
85 .resolved a {
86 text-decoration: line-through;
87 color: @color1;
88 }
89 .resolve-text {
90 color: @color1;
91 margin: 2px 8px;
92 font-family: @text-italic;
93 }
94
75 }
95 }
76
96
77
97
@@ -195,7 +215,6 b' tr.inline-comments div {'
195 }
215 }
196 }
216 }
197
217
198
199 .text {
218 .text {
200 clear: both;
219 clear: both;
201 .border-radius(@border-radius);
220 .border-radius(@border-radius);
@@ -370,7 +370,7 b' var initCommentBoxCodeMirror = function('
370 hint: function(CodeMirror, data, completion) {
370 hint: function(CodeMirror, data, completion) {
371 CodeMirror.replaceRange("", completion.from || data.from,
371 CodeMirror.replaceRange("", completion.from || data.from,
372 completion.to || data.to, "complete");
372 completion.to || data.to, "complete");
373 $('#change_status').select2("val", 'approved').trigger('change');
373 $('#change_status_general').select2("val", 'approved').trigger('change');
374 },
374 },
375 render: function(elt, data, completion) {
375 render: function(elt, data, completion) {
376 var el = document.createElement('div');
376 var el = document.createElement('div');
@@ -388,7 +388,7 b' var initCommentBoxCodeMirror = function('
388 hint: function(CodeMirror, data, completion) {
388 hint: function(CodeMirror, data, completion) {
389 CodeMirror.replaceRange("", completion.from || data.from,
389 CodeMirror.replaceRange("", completion.from || data.from,
390 completion.to || data.to, "complete");
390 completion.to || data.to, "complete");
391 $('#change_status').select2("val", 'rejected').trigger('change');
391 $('#change_status_general').select2("val", 'rejected').trigger('change');
392 },
392 },
393 render: function(elt, data, completion) {
393 render: function(elt, data, completion) {
394 var el = document.createElement('div');
394 var el = document.createElement('div');
@@ -106,6 +106,11 b' var linkifyComments = function(comments)'
106
106
107 };
107 };
108
108
109 var bindToggleButtons = function() {
110 $('.comment-toggle').on('click', function() {
111 $(this).parent().nextUntil('tr.line').toggle('inline-comments');
112 });
113 };
109
114
110 /* Comment form for main and inline comments */
115 /* Comment form for main and inline comments */
111
116
@@ -156,7 +161,7 b' var linkifyComments = function(comments)'
156 this.cmBox = this.withLineNo('#text');
161 this.cmBox = this.withLineNo('#text');
157 this.cm = initCommentBoxCodeMirror(this.cmBox, this.initAutocompleteActions);
162 this.cm = initCommentBoxCodeMirror(this.cmBox, this.initAutocompleteActions);
158
163
159 this.statusChange = '#change_status';
164 this.statusChange = this.withLineNo('#change_status');
160
165
161 this.submitForm = formElement;
166 this.submitForm = formElement;
162 this.submitButton = $(this.submitForm).find('input[type="submit"]');
167 this.submitButton = $(this.submitForm).find('input[type="submit"]');
@@ -171,6 +176,12 b' var linkifyComments = function(comments)'
171 $(this.commentType).prop('disabled', true);
176 $(this.commentType).prop('disabled', true);
172 $(this.commentType).addClass('disabled');
177 $(this.commentType).addClass('disabled');
173
178
179 // disable select
180 setTimeout(function() {
181 $(self.statusChange).select2('readonly', true);
182 }, 10);
183
184
174 var resolvedInfo = (
185 var resolvedInfo = (
175 '<li class="">' +
186 '<li class="">' +
176 '<input type="hidden" id="resolve_comment_{0}" name="resolve_comment_{0}" value="{0}">' +
187 '<input type="hidden" id="resolve_comment_{0}" name="resolve_comment_{0}" value="{0}">' +
@@ -203,6 +214,13 b' var linkifyComments = function(comments)'
203 'CommentForm requires pullRequestId, or commitId to be specified.')
214 'CommentForm requires pullRequestId, or commitId to be specified.')
204 }
215 }
205
216
217 // FUNCTIONS and helpers
218 var self = this;
219
220 this.isInline = function(){
221 return this.lineNo && this.lineNo != 'general';
222 };
223
206 this.getCmInstance = function(){
224 this.getCmInstance = function(){
207 return this.cm
225 return this.cm
208 };
226 };
@@ -214,8 +232,6 b' var linkifyComments = function(comments)'
214 }
232 }
215 };
233 };
216
234
217 var self = this;
218
219 this.getCommentStatus = function() {
235 this.getCommentStatus = function() {
220 return $(this.submitForm).find(this.statusChange).val();
236 return $(this.submitForm).find(this.statusChange).val();
221 };
237 };
@@ -260,7 +276,7 b' var linkifyComments = function(comments)'
260 });
276 });
261 $(this.submitForm).find(this.statusChange).on('change', function() {
277 $(this.submitForm).find(this.statusChange).on('change', function() {
262 var status = self.getCommentStatus();
278 var status = self.getCommentStatus();
263 if (status && self.lineNo == 'general') {
279 if (status && !self.isInline()) {
264 $(self.submitButton).prop('disabled', false);
280 $(self.submitButton).prop('disabled', false);
265 }
281 }
266
282
@@ -325,6 +341,7 b' var linkifyComments = function(comments)'
325 var submitEvent = true;
341 var submitEvent = true;
326 self.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
342 self.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
327 self.cm.setOption("readOnly", true);
343 self.cm.setOption("readOnly", true);
344
328 var postData = {
345 var postData = {
329 'text': text,
346 'text': text,
330 'changeset_status': status,
347 'changeset_status': status,
@@ -343,9 +360,9 b' var linkifyComments = function(comments)'
343 bindDeleteCommentButtons();
360 bindDeleteCommentButtons();
344 timeagoActivate();
361 timeagoActivate();
345
362
346 //mark visually which comment was resolved
363 // mark visually which comment was resolved
347 if (resolvesCommentId) {
364 if (resolvesCommentId) {
348 this.markCommentResolved(resolvesCommentId);
365 self.markCommentResolved(resolvesCommentId);
349 }
366 }
350 }
367 }
351 };
368 };
@@ -595,6 +612,62 b' var CommentsController = function() {'
595 $node.closest('tr').toggleClass('hide-line-comments');
612 $node.closest('tr').toggleClass('hide-line-comments');
596 };
613 };
597
614
615 this.createCommentForm = function(formElement, lineno, placeholderText, initAutocompleteActions, resolvesCommentId){
616 var pullRequestId = templateContext.pull_request_data.pull_request_id;
617 var commitId = templateContext.commit_data.commit_id;
618
619 var commentForm = new CommentForm(
620 formElement, commitId, pullRequestId, lineno, initAutocompleteActions, resolvesCommentId);
621 var cm = commentForm.getCmInstance();
622
623 if (resolvesCommentId){
624 var placeholderText = _gettext('Leave a comment, or click resolve button to resolve TODO comment #{0}').format(resolvesCommentId);
625 }
626
627 setTimeout(function() {
628 // callbacks
629 if (cm !== undefined) {
630 commentForm.setPlaceholder(placeholderText);
631 if (commentForm.isInline()) {
632 cm.focus();
633 cm.refresh();
634 }
635 }
636 }, 10);
637
638 // trigger scrolldown to the resolve comment, since it might be away
639 // from the clicked
640 if (resolvesCommentId){
641 var actionNode = $(commentForm.resolvesActionId).offset();
642
643 setTimeout(function() {
644 if (actionNode) {
645 $('body, html').animate({scrollTop: actionNode.top}, 10);
646 }
647 }, 100);
648 }
649
650 return commentForm;
651 };
652
653 this.createGeneralComment = function(lineNo, placeholderText, resolvesCommentId){
654
655 var tmpl = $('#cb-comment-general-form-template').html();
656 tmpl = tmpl.format(null, 'general');
657 var $form = $(tmpl);
658
659 var curForm = $('#cb-comment-general-form-placeholder').find('form');
660 if (curForm){
661 curForm.remove();
662 }
663 $('#cb-comment-general-form-placeholder').append($form);
664
665 var _form = $($form[0]);
666 var commentForm = this.createCommentForm(
667 _form, lineNo, placeholderText, true, resolvesCommentId);
668 commentForm.initStatusChangeSelector();
669 };
670
598 this.createComment = function(node, resolutionComment) {
671 this.createComment = function(node, resolutionComment) {
599 var resolvesCommentId = resolutionComment || null;
672 var resolvesCommentId = resolutionComment || null;
600 var $node = $(node);
673 var $node = $(node);
@@ -602,12 +675,13 b' var CommentsController = function() {'
602 var $form = $td.find('.comment-inline-form');
675 var $form = $td.find('.comment-inline-form');
603
676
604 if (!$form.length) {
677 if (!$form.length) {
605 var tmpl = $('#cb-comment-inline-form-template').html();
678
606 var $filediff = $node.closest('.filediff');
679 var $filediff = $node.closest('.filediff');
607 $filediff.removeClass('hide-comments');
680 $filediff.removeClass('hide-comments');
608 var f_path = $filediff.attr('data-f-path');
681 var f_path = $filediff.attr('data-f-path');
609 var lineno = self.getLineNumber(node);
682 var lineno = self.getLineNumber(node);
610
683 // create a new HTML from template
684 var tmpl = $('#cb-comment-inline-form-template').html();
611 tmpl = tmpl.format(f_path, lineno);
685 tmpl = tmpl.format(f_path, lineno);
612 $form = $(tmpl);
686 $form = $(tmpl);
613
687
@@ -620,12 +694,18 b' var CommentsController = function() {'
620
694
621 $td.find('.cb-comment-add-button').before($form);
695 $td.find('.cb-comment-add-button').before($form);
622
696
623 var pullRequestId = templateContext.pull_request_data.pull_request_id;
697 var placeholderText = _gettext('Leave a comment on line {0}.').format(lineno);
624 var commitId = templateContext.commit_data.commit_id;
625 var _form = $($form[0]).find('form');
698 var _form = $($form[0]).find('form');
626
699
627 var commentForm = new CommentForm(_form, commitId, pullRequestId, lineno, false, resolvesCommentId);
700 var commentForm = this.createCommentForm(
628 var cm = commentForm.getCmInstance();
701 _form, lineno, placeholderText, false, resolvesCommentId);
702
703 $.Topic('/ui/plugins/code/comment_form_built').prepareOrPublish({
704 form: _form,
705 parent: $td[0],
706 lineno: lineno,
707 f_path: f_path}
708 );
629
709
630 // set a CUSTOM submit handler for inline comments.
710 // set a CUSTOM submit handler for inline comments.
631 commentForm.setHandleFormSubmit(function(o) {
711 commentForm.setHandleFormSubmit(function(o) {
@@ -693,36 +773,6 b' var CommentsController = function() {'
693 commentForm.submitUrl, postData, submitSuccessCallback, submitFailCallback);
773 commentForm.submitUrl, postData, submitSuccessCallback, submitFailCallback);
694 });
774 });
695
775
696 if (resolvesCommentId){
697 var placeholderText = _gettext('Leave a comment, or click resolve button to resolve TODO comment #{0}').format(resolvesCommentId);
698
699 } else {
700 var placeholderText = _gettext('Leave a comment on line {0}.').format(lineno);
701 }
702
703 setTimeout(function() {
704 // callbacks
705 if (cm !== undefined) {
706 commentForm.setPlaceholder(placeholderText);
707 cm.focus();
708 cm.refresh();
709 }
710 }, 10);
711
712 $.Topic('/ui/plugins/code/comment_form_built').prepareOrPublish({
713 form: _form,
714 parent: $td[0],
715 lineno: lineno,
716 f_path: f_path}
717 );
718
719 // trigger hash
720 if (resolvesCommentId){
721 var resolveAction = $(commentForm.resolvesActionId);
722 setTimeout(function() {
723 $('body, html').animate({ scrollTop: resolveAction.offset().top }, 10);
724 }, 100);
725 }
726 }
776 }
727
777
728 $form.addClass('comment-inline-form-open');
778 $form.addClass('comment-inline-form-open');
@@ -734,16 +784,10 b' var CommentsController = function() {'
734
784
735 var comment = $('#comment-'+commentId);
785 var comment = $('#comment-'+commentId);
736 var commentData = comment.data();
786 var commentData = comment.data();
737
738 if (commentData.commentInline) {
787 if (commentData.commentInline) {
739 var resolutionComment = true;
740 this.createComment(comment, commentId)
788 this.createComment(comment, commentId)
741 } else {
789 } else {
742
790 Rhodecode.comments.createGeneralComment('general', "$placeholder", commentId)
743 this.createComment(comment, commentId)
744
745 console.log('TODO')
746 console.log(commentId)
747 }
791 }
748
792
749 return false;
793 return false;
@@ -196,24 +196,19 b''
196 %>
196 %>
197
197
198 % if c.rhodecode_user.username != h.DEFAULT_USER:
198 % if c.rhodecode_user.username != h.DEFAULT_USER:
199 <div class="comment-form ac">
199 <div class="js-template" id="cb-comment-general-form-template">
200 ## template generated for injection
201 ${comment_form(form_type='general', review_statuses=c.commit_statuses, form_extras=form_extras)}
202 </div>
203
204 <div id="cb-comment-general-form-placeholder" class="comment-form ac">
200 ## inject form here
205 ## inject form here
201 ${comment_form(form_type='general', form_id='general_comment', lineno_id='general', review_statuses=c.commit_statuses, form_extras=form_extras)}
202 </div>
206 </div>
203 <script type="text/javascript">
207 <script type="text/javascript">
204 // init active elements of commentForm
205 var commitId = templateContext.commit_data.commit_id;
206 var pullRequestId = templateContext.pull_request_data.pull_request_id;
207 var lineNo = 'general';
208 var lineNo = 'general';
208 var resolvesCommitId = null;
209 var resolvesCommentId = null;
209
210 Rhodecode.comments.createGeneralComment(lineNo, "${placeholder}", resolvesCommentId)
210 var mainCommentForm = new CommentForm(
211 "#general_comment", commitId, pullRequestId, lineNo, true, resolvesCommitId);
212 mainCommentForm.setPlaceholder("${placeholder}");
213 mainCommentForm.initStatusChangeSelector();
214 </script>
211 </script>
215
216
217 % else:
212 % else:
218 ## form state when not logged in
213 ## form state when not logged in
219 <div class="comment-form ac">
214 <div class="comment-form ac">
@@ -313,7 +308,7 b''
313
308
314 % if review_statuses:
309 % if review_statuses:
315 <div class="status_box">
310 <div class="status_box">
316 <select id="change_status" name="changeset_status">
311 <select id="change_status_${lineno_id}" name="changeset_status">
317 <option></option> ## Placeholder
312 <option></option> ## Placeholder
318 % for status, lbl in review_statuses:
313 % for status, lbl in review_statuses:
319 <option value="${status}" data-status="${status}">${lbl}</option>
314 <option value="${status}" data-status="${status}">${lbl}</option>
@@ -868,7 +868,7 b''
868 return formatChangeStatus(data, escapeMarkup);
868 return formatChangeStatus(data, escapeMarkup);
869 };
869 };
870
870
871 $('#change_status').select2({
871 $('#change_status_general').select2({
872 placeholder: "Status Review",
872 placeholder: "Status Review",
873 formatResult: formatResult,
873 formatResult: formatResult,
874 formatSelection: formatSelection,
874 formatSelection: formatSelection,
General Comments 0
You need to be logged in to leave comments. Login now