comments: fixed compare view comments.

This commit is contained in:
Marcin Kuzminski 2017-01-11 14:03:18 +01:00
parent caee47148f
commit a24ca60752
4 changed files with 90 additions and 57 deletions

View file

@ -342,11 +342,14 @@ class ChangesetController(BaseRepoController):
% {'transition_icon': '>',
'status': ChangesetStatus.get_status_lbl(status)})
multi_commit_ids = filter(
lambda s: s not in ['', None],
request.POST.get('commit_ids', '').split(','),)
multi_commit_ids = []
for _commit_id in request.POST.get('commit_ids', '').split(','):
if _commit_id not in ['', None, EmptyCommit.raw_id]:
if _commit_id not in multi_commit_ids:
multi_commit_ids.append(_commit_id)
commit_ids = multi_commit_ids or [commit_id]
comment = None
for current_id in filter(None, commit_ids):
c.co = comment = CommentsModel().create(

View file

@ -43,12 +43,16 @@ var bindToggleButtons = function() {
};
/* Comment form for main and inline comments */
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
module.exports = mod();
else // Plain browser env
(this || window).CommentForm = mod();
if (typeof exports == "object" && typeof module == "object") {
// CommonJS
module.exports = mod();
}
else {
// Plain browser env
(this || window).CommentForm = mod();
}
})(function() {
"use strict";
@ -236,6 +240,8 @@ var bindToggleButtons = function() {
$(this.statusChange).select2('readonly', false);
};
this.globalSubmitSuccessCallback = function(){};
this.submitAjaxPOST = function(url, postData, successHandler, failHandler) {
failHandler = failHandler || function() {};
var postData = toQueryString(postData);
@ -262,6 +268,11 @@ var bindToggleButtons = function() {
this.handleFormSubmit = callback;
};
// overwrite a submitSuccessHandler
this.setGlobalSubmitSuccessCallback = function(callback) {
this.globalSubmitSuccessCallback = callback;
};
// default handler for for submit for main comments
this.handleFormSubmit = function() {
var text = self.cm.getValue();
@ -287,6 +298,7 @@ var bindToggleButtons = function() {
if (resolvesCommentId){
postData['resolves_comment_id'] = resolvesCommentId;
}
var submitSuccessCallback = function(o) {
if (status) {
location.reload(true);
@ -300,6 +312,10 @@ var bindToggleButtons = function() {
self.markCommentResolved(resolvesCommentId);
}
}
// run global callback on submit
self.globalSubmitSuccessCallback();
};
var submitFailCallback = function(){
self.resetCommentFormState(text);
@ -585,22 +601,25 @@ var CommentsController = function() {
return commentForm;
};
this.createGeneralComment = function(lineNo, placeholderText, resolvesCommentId){
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');
var $formPlaceholder = $('#cb-comment-general-form-placeholder');
var curForm = $formPlaceholder.find('form');
if (curForm){
curForm.remove();
}
$('#cb-comment-general-form-placeholder').append($form);
$formPlaceholder.append($form);
var _form = $($form[0]);
var commentForm = this.createCommentForm(
_form, lineNo, placeholderText, true, resolvesCommentId);
commentForm.initStatusChangeSelector();
return commentForm;
};
this.createComment = function(node, resolutionComment) {
@ -690,6 +709,9 @@ var CommentsController = function() {
commentForm.markCommentResolved(resolvesCommentId);
}
// run global callback on submit
commentForm.globalSubmitSuccessCallback();
} catch (e) {
console.error(e);
}

View file

@ -190,7 +190,7 @@
if is_pull_request:
placeholder = _('Leave a comment on this Pull Request.')
elif is_compare:
placeholder = _('Leave a comment on all commits in this range.')
placeholder = _('Leave a comment on {} commits in this range.').format(len(form_extras))
else:
placeholder = _('Leave a comment on this Commit.')
%>
@ -207,7 +207,59 @@
<script type="text/javascript">
var lineNo = 'general';
var resolvesCommentId = null;
Rhodecode.comments.createGeneralComment(lineNo, "${placeholder}", resolvesCommentId)
var generalCommentForm = Rhodecode.comments.createGeneralComment(
lineNo, "${placeholder}", resolvesCommentId);
// set custom success callback on rangeCommit
% if is_compare:
generalCommentForm.setHandleFormSubmit(function(o) {
var self = generalCommentForm;
var text = self.cm.getValue();
var status = self.getCommentStatus();
var commentType = self.getCommentType();
if (text === "" && !status) {
return;
}
// we can pick which commits we want to make the comment by
// selecting them via click on preview pane, this will alter the hidden inputs
var cherryPicked = $('#changeset_compare_view_content .compare_select.hl').length > 0;
var commitIds = [];
$('#changeset_compare_view_content .compare_select').each(function(el) {
var commitId = this.id.replace('row-', '');
if ($(this).hasClass('hl') || !cherryPicked) {
$("input[data-commit-id='{0}']".format(commitId)).val(commitId);
commitIds.push(commitId);
} else {
$("input[data-commit-id='{0}']".format(commitId)).val('')
}
});
self.setActionButtonsDisabled(true);
self.cm.setOption("readOnly", true);
var postData = {
'text': text,
'changeset_status': status,
'comment_type': commentType,
'commit_ids': commitIds,
'csrf_token': CSRF_TOKEN
};
var submitSuccessCallback = function(o) {
location.reload(true);
};
var submitFailCallback = function(){
self.resetCommentFormState(text)
};
self.submitAjaxPOST(
self.submitUrl, postData, submitSuccessCallback, submitFailCallback);
});
% endif
</script>
% else:
## form state when not logged in

View file

@ -171,50 +171,6 @@
%>
<div>
${comment.comments(h.url('changeset_comment', repo_name=c.repo_name, revision='0'*16), None, is_compare=True, form_extras=revs(c.commit_ranges))}
<script type="text/javascript">
mainCommentForm.setHandleFormSubmit(function(o) {
var text = mainCommentForm.cm.getValue();
var status = mainCommentForm.getCommentStatus();
if (text === "" && !status) {
return;
}
// we can pick which commits we want to make the comment by
// selecting them via click on preview pane, this will alter the hidden inputs
var cherryPicked = $('#changeset_compare_view_content .compare_select.hl').length > 0;
var commitIds = [];
$('#changeset_compare_view_content .compare_select').each(function(el) {
var commitId = this.id.replace('row-', '');
if ($(this).hasClass('hl') || !cherryPicked) {
$("input[data-commit-id='{0}']".format(commitId)).val(commitId)
commitIds.push(commitId);
} else {
$("input[data-commit-id='{0}']".format(commitId)).val('')
}
});
mainCommentForm.setActionButtonsDisabled(true);
mainCommentForm.cm.setOption("readOnly", true);
var postData = {
'text': text,
'changeset_status': status,
'commit_ids': commitIds,
'csrf_token': CSRF_TOKEN
};
var submitSuccessCallback = function(o) {
location.reload(true);
};
var submitFailCallback = function(){
mainCommentForm.resetCommentFormState(text)
};
mainCommentForm.submitAjaxPOST(
mainCommentForm.submitUrl, postData, submitSuccessCallback, submitFailCallback);
});
</script>
</div>
</div>
</div>