##// 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 335 status = request.POST.get('changeset_status', None)
336 336 text = request.POST.get('text')
337 337 comment_type = request.POST.get('comment_type')
338 resolves_comment_id = request.POST.get('resolves_comment_id', None)
338 339
339 340 if status:
340 341 text = text or (_('Status change %(transition_icon)s %(status)s')
@@ -358,7 +359,8 b' class ChangesetController(BaseRepoContro'
358 359 status_change=(ChangesetStatus.get_status_lbl(status)
359 360 if status else None),
360 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 365 c.inline_comment = True if comment.line_no else False
364 366
@@ -904,7 +904,7 b' class PullrequestsController(BaseRepoCon'
904 904 status = request.POST.get('changeset_status', None)
905 905 text = request.POST.get('text')
906 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 909 if status and '_closed' in status:
910 910 close_pr = True
@@ -72,6 +72,26 b' tr.inline-comments div {'
72 72 color: @color5;
73 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 218 .text {
200 219 clear: both;
201 220 .border-radius(@border-radius);
@@ -370,7 +370,7 b' var initCommentBoxCodeMirror = function('
370 370 hint: function(CodeMirror, data, completion) {
371 371 CodeMirror.replaceRange("", completion.from || data.from,
372 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 375 render: function(elt, data, completion) {
376 376 var el = document.createElement('div');
@@ -388,7 +388,7 b' var initCommentBoxCodeMirror = function('
388 388 hint: function(CodeMirror, data, completion) {
389 389 CodeMirror.replaceRange("", completion.from || data.from,
390 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 393 render: function(elt, data, completion) {
394 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 115 /* Comment form for main and inline comments */
111 116
@@ -156,7 +161,7 b' var linkifyComments = function(comments)'
156 161 this.cmBox = this.withLineNo('#text');
157 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 166 this.submitForm = formElement;
162 167 this.submitButton = $(this.submitForm).find('input[type="submit"]');
@@ -171,6 +176,12 b' var linkifyComments = function(comments)'
171 176 $(this.commentType).prop('disabled', true);
172 177 $(this.commentType).addClass('disabled');
173 178
179 // disable select
180 setTimeout(function() {
181 $(self.statusChange).select2('readonly', true);
182 }, 10);
183
184
174 185 var resolvedInfo = (
175 186 '<li class="">' +
176 187 '<input type="hidden" id="resolve_comment_{0}" name="resolve_comment_{0}" value="{0}">' +
@@ -203,6 +214,13 b' var linkifyComments = function(comments)'
203 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 224 this.getCmInstance = function(){
207 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 235 this.getCommentStatus = function() {
220 236 return $(this.submitForm).find(this.statusChange).val();
221 237 };
@@ -260,7 +276,7 b' var linkifyComments = function(comments)'
260 276 });
261 277 $(this.submitForm).find(this.statusChange).on('change', function() {
262 278 var status = self.getCommentStatus();
263 if (status && self.lineNo == 'general') {
279 if (status && !self.isInline()) {
264 280 $(self.submitButton).prop('disabled', false);
265 281 }
266 282
@@ -325,6 +341,7 b' var linkifyComments = function(comments)'
325 341 var submitEvent = true;
326 342 self.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
327 343 self.cm.setOption("readOnly", true);
344
328 345 var postData = {
329 346 'text': text,
330 347 'changeset_status': status,
@@ -345,7 +362,7 b' var linkifyComments = function(comments)'
345 362
346 363 //mark visually which comment was resolved
347 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 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 671 this.createComment = function(node, resolutionComment) {
599 672 var resolvesCommentId = resolutionComment || null;
600 673 var $node = $(node);
@@ -602,12 +675,13 b' var CommentsController = function() {'
602 675 var $form = $td.find('.comment-inline-form');
603 676
604 677 if (!$form.length) {
605 var tmpl = $('#cb-comment-inline-form-template').html();
678
606 679 var $filediff = $node.closest('.filediff');
607 680 $filediff.removeClass('hide-comments');
608 681 var f_path = $filediff.attr('data-f-path');
609 682 var lineno = self.getLineNumber(node);
610
683 // create a new HTML from template
684 var tmpl = $('#cb-comment-inline-form-template').html();
611 685 tmpl = tmpl.format(f_path, lineno);
612 686 $form = $(tmpl);
613 687
@@ -620,12 +694,18 b' var CommentsController = function() {'
620 694
621 695 $td.find('.cb-comment-add-button').before($form);
622 696
623 var pullRequestId = templateContext.pull_request_data.pull_request_id;
624 var commitId = templateContext.commit_data.commit_id;
697 var placeholderText = _gettext('Leave a comment on line {0}.').format(lineno);
625 698 var _form = $($form[0]).find('form');
626 699
627 var commentForm = new CommentForm(_form, commitId, pullRequestId, lineno, false, resolvesCommentId);
628 var cm = commentForm.getCmInstance();
700 var commentForm = this.createCommentForm(
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 710 // set a CUSTOM submit handler for inline comments.
631 711 commentForm.setHandleFormSubmit(function(o) {
@@ -693,36 +773,6 b' var CommentsController = function() {'
693 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 778 $form.addClass('comment-inline-form-open');
@@ -734,16 +784,10 b' var CommentsController = function() {'
734 784
735 785 var comment = $('#comment-'+commentId);
736 786 var commentData = comment.data();
737
738 787 if (commentData.commentInline) {
739 var resolutionComment = true;
740 788 this.createComment(comment, commentId)
741 789 } else {
742
743 this.createComment(comment, commentId)
744
745 console.log('TODO')
746 console.log(commentId)
790 Rhodecode.comments.createGeneralComment('general', "$placeholder", commentId)
747 791 }
748 792
749 793 return false;
@@ -196,24 +196,19 b''
196 196 %>
197 197
198 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 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 206 </div>
203 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 208 var lineNo = 'general';
208 var resolvesCommitId = null;
209
210 var mainCommentForm = new CommentForm(
211 "#general_comment", commitId, pullRequestId, lineNo, true, resolvesCommitId);
212 mainCommentForm.setPlaceholder("${placeholder}");
213 mainCommentForm.initStatusChangeSelector();
209 var resolvesCommentId = null;
210 Rhodecode.comments.createGeneralComment(lineNo, "${placeholder}", resolvesCommentId)
214 211 </script>
215
216
217 212 % else:
218 213 ## form state when not logged in
219 214 <div class="comment-form ac">
@@ -313,7 +308,7 b''
313 308
314 309 % if review_statuses:
315 310 <div class="status_box">
316 <select id="change_status" name="changeset_status">
311 <select id="change_status_${lineno_id}" name="changeset_status">
317 312 <option></option> ## Placeholder
318 313 % for status, lbl in review_statuses:
319 314 <option value="${status}" data-status="${status}">${lbl}</option>
@@ -868,7 +868,7 b''
868 868 return formatChangeStatus(data, escapeMarkup);
869 869 };
870 870
871 $('#change_status').select2({
871 $('#change_status_general').select2({
872 872 placeholder: "Status Review",
873 873 formatResult: formatResult,
874 874 formatSelection: formatSelection,
General Comments 0
You need to be logged in to leave comments. Login now