comments: enabled resolution for general comments, and finalized how general comment is build
This commit is contained in:
parent
8f1db17117
commit
6ccb2377c3
7 changed files with 129 additions and 69 deletions
|
|
@ -335,6 +335,7 @@ class ChangesetController(BaseRepoController):
|
|||
status = request.POST.get('changeset_status', None)
|
||||
text = request.POST.get('text')
|
||||
comment_type = request.POST.get('comment_type')
|
||||
resolves_comment_id = request.POST.get('resolves_comment_id', None)
|
||||
|
||||
if status:
|
||||
text = text or (_('Status change %(transition_icon)s %(status)s')
|
||||
|
|
@ -358,7 +359,8 @@ class ChangesetController(BaseRepoController):
|
|||
status_change=(ChangesetStatus.get_status_lbl(status)
|
||||
if status else None),
|
||||
status_change_type=status,
|
||||
comment_type=comment_type
|
||||
comment_type=comment_type,
|
||||
resolves_comment_id=resolves_comment_id
|
||||
)
|
||||
c.inline_comment = True if comment.line_no else False
|
||||
|
||||
|
|
|
|||
|
|
@ -904,7 +904,7 @@ class PullrequestsController(BaseRepoController):
|
|||
status = request.POST.get('changeset_status', None)
|
||||
text = request.POST.get('text')
|
||||
comment_type = request.POST.get('comment_type')
|
||||
resolves_comment_id = request.POST.get('resolves_comment_id')
|
||||
resolves_comment_id = request.POST.get('resolves_comment_id', None)
|
||||
|
||||
if status and '_closed' in status:
|
||||
close_pr = True
|
||||
|
|
|
|||
|
|
@ -72,6 +72,26 @@ tr.inline-comments div {
|
|||
color: @color5;
|
||||
font-family: @text-bold-italic;
|
||||
}
|
||||
|
||||
.resolve {
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.resolved {
|
||||
text-decoration: line-through;
|
||||
color: @color1;
|
||||
}
|
||||
.resolved a {
|
||||
text-decoration: line-through;
|
||||
color: @color1;
|
||||
}
|
||||
.resolve-text {
|
||||
color: @color1;
|
||||
margin: 2px 8px;
|
||||
font-family: @text-italic;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -195,7 +215,6 @@ tr.inline-comments div {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
.text {
|
||||
clear: both;
|
||||
.border-radius(@border-radius);
|
||||
|
|
|
|||
|
|
@ -370,7 +370,7 @@ var initCommentBoxCodeMirror = function(textAreaId, triggerActions){
|
|||
hint: function(CodeMirror, data, completion) {
|
||||
CodeMirror.replaceRange("", completion.from || data.from,
|
||||
completion.to || data.to, "complete");
|
||||
$('#change_status').select2("val", 'approved').trigger('change');
|
||||
$('#change_status_general').select2("val", 'approved').trigger('change');
|
||||
},
|
||||
render: function(elt, data, completion) {
|
||||
var el = document.createElement('div');
|
||||
|
|
@ -388,7 +388,7 @@ var initCommentBoxCodeMirror = function(textAreaId, triggerActions){
|
|||
hint: function(CodeMirror, data, completion) {
|
||||
CodeMirror.replaceRange("", completion.from || data.from,
|
||||
completion.to || data.to, "complete");
|
||||
$('#change_status').select2("val", 'rejected').trigger('change');
|
||||
$('#change_status_general').select2("val", 'rejected').trigger('change');
|
||||
},
|
||||
render: function(elt, data, completion) {
|
||||
var el = document.createElement('div');
|
||||
|
|
|
|||
|
|
@ -106,6 +106,11 @@ var linkifyComments = function(comments) {
|
|||
|
||||
};
|
||||
|
||||
var bindToggleButtons = function() {
|
||||
$('.comment-toggle').on('click', function() {
|
||||
$(this).parent().nextUntil('tr.line').toggle('inline-comments');
|
||||
});
|
||||
};
|
||||
|
||||
/* Comment form for main and inline comments */
|
||||
|
||||
|
|
@ -156,7 +161,7 @@ var linkifyComments = function(comments) {
|
|||
this.cmBox = this.withLineNo('#text');
|
||||
this.cm = initCommentBoxCodeMirror(this.cmBox, this.initAutocompleteActions);
|
||||
|
||||
this.statusChange = '#change_status';
|
||||
this.statusChange = this.withLineNo('#change_status');
|
||||
|
||||
this.submitForm = formElement;
|
||||
this.submitButton = $(this.submitForm).find('input[type="submit"]');
|
||||
|
|
@ -171,6 +176,12 @@ var linkifyComments = function(comments) {
|
|||
$(this.commentType).prop('disabled', true);
|
||||
$(this.commentType).addClass('disabled');
|
||||
|
||||
// disable select
|
||||
setTimeout(function() {
|
||||
$(self.statusChange).select2('readonly', true);
|
||||
}, 10);
|
||||
|
||||
|
||||
var resolvedInfo = (
|
||||
'<li class="">' +
|
||||
'<input type="hidden" id="resolve_comment_{0}" name="resolve_comment_{0}" value="{0}">' +
|
||||
|
|
@ -203,6 +214,13 @@ var linkifyComments = function(comments) {
|
|||
'CommentForm requires pullRequestId, or commitId to be specified.')
|
||||
}
|
||||
|
||||
// FUNCTIONS and helpers
|
||||
var self = this;
|
||||
|
||||
this.isInline = function(){
|
||||
return this.lineNo && this.lineNo != 'general';
|
||||
};
|
||||
|
||||
this.getCmInstance = function(){
|
||||
return this.cm
|
||||
};
|
||||
|
|
@ -214,8 +232,6 @@ var linkifyComments = function(comments) {
|
|||
}
|
||||
};
|
||||
|
||||
var self = this;
|
||||
|
||||
this.getCommentStatus = function() {
|
||||
return $(this.submitForm).find(this.statusChange).val();
|
||||
};
|
||||
|
|
@ -260,7 +276,7 @@ var linkifyComments = function(comments) {
|
|||
});
|
||||
$(this.submitForm).find(this.statusChange).on('change', function() {
|
||||
var status = self.getCommentStatus();
|
||||
if (status && self.lineNo == 'general') {
|
||||
if (status && !self.isInline()) {
|
||||
$(self.submitButton).prop('disabled', false);
|
||||
}
|
||||
|
||||
|
|
@ -325,6 +341,7 @@ var linkifyComments = function(comments) {
|
|||
var submitEvent = true;
|
||||
self.setActionButtonsDisabled(true, excludeCancelBtn, submitEvent);
|
||||
self.cm.setOption("readOnly", true);
|
||||
|
||||
var postData = {
|
||||
'text': text,
|
||||
'changeset_status': status,
|
||||
|
|
@ -343,9 +360,9 @@ var linkifyComments = function(comments) {
|
|||
bindDeleteCommentButtons();
|
||||
timeagoActivate();
|
||||
|
||||
//mark visually which comment was resolved
|
||||
// mark visually which comment was resolved
|
||||
if (resolvesCommentId) {
|
||||
this.markCommentResolved(resolvesCommentId);
|
||||
self.markCommentResolved(resolvesCommentId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -595,6 +612,62 @@ var CommentsController = function() {
|
|||
$node.closest('tr').toggleClass('hide-line-comments');
|
||||
};
|
||||
|
||||
this.createCommentForm = function(formElement, lineno, placeholderText, initAutocompleteActions, resolvesCommentId){
|
||||
var pullRequestId = templateContext.pull_request_data.pull_request_id;
|
||||
var commitId = templateContext.commit_data.commit_id;
|
||||
|
||||
var commentForm = new CommentForm(
|
||||
formElement, commitId, pullRequestId, lineno, initAutocompleteActions, resolvesCommentId);
|
||||
var cm = commentForm.getCmInstance();
|
||||
|
||||
if (resolvesCommentId){
|
||||
var placeholderText = _gettext('Leave a comment, or click resolve button to resolve TODO comment #{0}').format(resolvesCommentId);
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
// callbacks
|
||||
if (cm !== undefined) {
|
||||
commentForm.setPlaceholder(placeholderText);
|
||||
if (commentForm.isInline()) {
|
||||
cm.focus();
|
||||
cm.refresh();
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
|
||||
// trigger scrolldown to the resolve comment, since it might be away
|
||||
// from the clicked
|
||||
if (resolvesCommentId){
|
||||
var actionNode = $(commentForm.resolvesActionId).offset();
|
||||
|
||||
setTimeout(function() {
|
||||
if (actionNode) {
|
||||
$('body, html').animate({scrollTop: actionNode.top}, 10);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
return commentForm;
|
||||
};
|
||||
|
||||
this.createGeneralComment = function(lineNo, placeholderText, resolvesCommentId){
|
||||
|
||||
var tmpl = $('#cb-comment-general-form-template').html();
|
||||
tmpl = tmpl.format(null, 'general');
|
||||
var $form = $(tmpl);
|
||||
|
||||
var curForm = $('#cb-comment-general-form-placeholder').find('form');
|
||||
if (curForm){
|
||||
curForm.remove();
|
||||
}
|
||||
$('#cb-comment-general-form-placeholder').append($form);
|
||||
|
||||
var _form = $($form[0]);
|
||||
var commentForm = this.createCommentForm(
|
||||
_form, lineNo, placeholderText, true, resolvesCommentId);
|
||||
commentForm.initStatusChangeSelector();
|
||||
};
|
||||
|
||||
this.createComment = function(node, resolutionComment) {
|
||||
var resolvesCommentId = resolutionComment || null;
|
||||
var $node = $(node);
|
||||
|
|
@ -602,12 +675,13 @@ var CommentsController = function() {
|
|||
var $form = $td.find('.comment-inline-form');
|
||||
|
||||
if (!$form.length) {
|
||||
var tmpl = $('#cb-comment-inline-form-template').html();
|
||||
|
||||
var $filediff = $node.closest('.filediff');
|
||||
$filediff.removeClass('hide-comments');
|
||||
var f_path = $filediff.attr('data-f-path');
|
||||
var lineno = self.getLineNumber(node);
|
||||
|
||||
// create a new HTML from template
|
||||
var tmpl = $('#cb-comment-inline-form-template').html();
|
||||
tmpl = tmpl.format(f_path, lineno);
|
||||
$form = $(tmpl);
|
||||
|
||||
|
|
@ -620,12 +694,18 @@ var CommentsController = function() {
|
|||
|
||||
$td.find('.cb-comment-add-button').before($form);
|
||||
|
||||
var pullRequestId = templateContext.pull_request_data.pull_request_id;
|
||||
var commitId = templateContext.commit_data.commit_id;
|
||||
var placeholderText = _gettext('Leave a comment on line {0}.').format(lineno);
|
||||
var _form = $($form[0]).find('form');
|
||||
|
||||
var commentForm = new CommentForm(_form, commitId, pullRequestId, lineno, false, resolvesCommentId);
|
||||
var cm = commentForm.getCmInstance();
|
||||
var commentForm = this.createCommentForm(
|
||||
_form, lineno, placeholderText, false, resolvesCommentId);
|
||||
|
||||
$.Topic('/ui/plugins/code/comment_form_built').prepareOrPublish({
|
||||
form: _form,
|
||||
parent: $td[0],
|
||||
lineno: lineno,
|
||||
f_path: f_path}
|
||||
);
|
||||
|
||||
// set a CUSTOM submit handler for inline comments.
|
||||
commentForm.setHandleFormSubmit(function(o) {
|
||||
|
|
@ -693,36 +773,6 @@ var CommentsController = function() {
|
|||
commentForm.submitUrl, postData, submitSuccessCallback, submitFailCallback);
|
||||
});
|
||||
|
||||
if (resolvesCommentId){
|
||||
var placeholderText = _gettext('Leave a comment, or click resolve button to resolve TODO comment #{0}').format(resolvesCommentId);
|
||||
|
||||
} else {
|
||||
var placeholderText = _gettext('Leave a comment on line {0}.').format(lineno);
|
||||
}
|
||||
|
||||
setTimeout(function() {
|
||||
// callbacks
|
||||
if (cm !== undefined) {
|
||||
commentForm.setPlaceholder(placeholderText);
|
||||
cm.focus();
|
||||
cm.refresh();
|
||||
}
|
||||
}, 10);
|
||||
|
||||
$.Topic('/ui/plugins/code/comment_form_built').prepareOrPublish({
|
||||
form: _form,
|
||||
parent: $td[0],
|
||||
lineno: lineno,
|
||||
f_path: f_path}
|
||||
);
|
||||
|
||||
// trigger hash
|
||||
if (resolvesCommentId){
|
||||
var resolveAction = $(commentForm.resolvesActionId);
|
||||
setTimeout(function() {
|
||||
$('body, html').animate({ scrollTop: resolveAction.offset().top }, 10);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
$form.addClass('comment-inline-form-open');
|
||||
|
|
@ -734,16 +784,10 @@ var CommentsController = function() {
|
|||
|
||||
var comment = $('#comment-'+commentId);
|
||||
var commentData = comment.data();
|
||||
|
||||
if (commentData.commentInline) {
|
||||
var resolutionComment = true;
|
||||
this.createComment(comment, commentId)
|
||||
} else {
|
||||
|
||||
this.createComment(comment, commentId)
|
||||
|
||||
console.log('TODO')
|
||||
console.log(commentId)
|
||||
Rhodecode.comments.createGeneralComment('general', "$placeholder", commentId)
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -196,24 +196,19 @@
|
|||
%>
|
||||
|
||||
% if c.rhodecode_user.username != h.DEFAULT_USER:
|
||||
<div class="comment-form ac">
|
||||
<div class="js-template" id="cb-comment-general-form-template">
|
||||
## template generated for injection
|
||||
${comment_form(form_type='general', review_statuses=c.commit_statuses, form_extras=form_extras)}
|
||||
</div>
|
||||
|
||||
<div id="cb-comment-general-form-placeholder" class="comment-form ac">
|
||||
## inject form here
|
||||
${comment_form(form_type='general', form_id='general_comment', lineno_id='general', review_statuses=c.commit_statuses, form_extras=form_extras)}
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
// init active elements of commentForm
|
||||
var commitId = templateContext.commit_data.commit_id;
|
||||
var pullRequestId = templateContext.pull_request_data.pull_request_id;
|
||||
var lineNo = 'general';
|
||||
var resolvesCommitId = null;
|
||||
|
||||
var mainCommentForm = new CommentForm(
|
||||
"#general_comment", commitId, pullRequestId, lineNo, true, resolvesCommitId);
|
||||
mainCommentForm.setPlaceholder("${placeholder}");
|
||||
mainCommentForm.initStatusChangeSelector();
|
||||
var resolvesCommentId = null;
|
||||
Rhodecode.comments.createGeneralComment(lineNo, "${placeholder}", resolvesCommentId)
|
||||
</script>
|
||||
|
||||
|
||||
% else:
|
||||
## form state when not logged in
|
||||
<div class="comment-form ac">
|
||||
|
|
@ -313,7 +308,7 @@
|
|||
|
||||
% if review_statuses:
|
||||
<div class="status_box">
|
||||
<select id="change_status" name="changeset_status">
|
||||
<select id="change_status_${lineno_id}" name="changeset_status">
|
||||
<option></option> ## Placeholder
|
||||
% for status, lbl in review_statuses:
|
||||
<option value="${status}" data-status="${status}">${lbl}</option>
|
||||
|
|
|
|||
|
|
@ -868,7 +868,7 @@ $(document).ready(function() {
|
|||
return formatChangeStatus(data, escapeMarkup);
|
||||
};
|
||||
|
||||
$('#change_status').select2({
|
||||
$('#change_status_general').select2({
|
||||
placeholder: "Status Review",
|
||||
formatResult: formatResult,
|
||||
formatSelection: formatSelection,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue