Show More
@@ -336,6 +336,7 b' class CommentsModel(BaseModel):' | |||||
336 | comment.author = user |
|
336 | comment.author = user | |
337 | resolved_comment = self.__get_commit_comment( |
|
337 | resolved_comment = self.__get_commit_comment( | |
338 | validated_kwargs['resolves_comment_id']) |
|
338 | validated_kwargs['resolves_comment_id']) | |
|
339 | ||||
339 | # check if the comment actually belongs to this PR |
|
340 | # check if the comment actually belongs to this PR | |
340 | if resolved_comment and resolved_comment.pull_request and \ |
|
341 | if resolved_comment and resolved_comment.pull_request and \ | |
341 | resolved_comment.pull_request != pull_request: |
|
342 | resolved_comment.pull_request != pull_request: | |
@@ -351,6 +352,10 b' class CommentsModel(BaseModel):' | |||||
351 | # comment not bound to this repo, forbid |
|
352 | # comment not bound to this repo, forbid | |
352 | resolved_comment = None |
|
353 | resolved_comment = None | |
353 |
|
354 | |||
|
355 | if resolved_comment and resolved_comment.resolved_by: | |||
|
356 | # if this comment is already resolved, don't mark it again! | |||
|
357 | resolved_comment = None | |||
|
358 | ||||
354 | comment.resolved_comment = resolved_comment |
|
359 | comment.resolved_comment = resolved_comment | |
355 |
|
360 | |||
356 | pull_request_id = pull_request |
|
361 | pull_request_id = pull_request |
@@ -25,6 +25,7 b' var firefoxAnchorFix = function() {' | |||||
25 | } |
|
25 | } | |
26 | }; |
|
26 | }; | |
27 |
|
27 | |||
|
28 | ||||
28 | var linkifyComments = function(comments) { |
|
29 | var linkifyComments = function(comments) { | |
29 | var firstCommentId = null; |
|
30 | var firstCommentId = null; | |
30 | if (comments) { |
|
31 | if (comments) { | |
@@ -36,6 +37,7 b' var linkifyComments = function(comments)' | |||||
36 | } |
|
37 | } | |
37 | }; |
|
38 | }; | |
38 |
|
39 | |||
|
40 | ||||
39 | var bindToggleButtons = function() { |
|
41 | var bindToggleButtons = function() { | |
40 | $('.comment-toggle').on('click', function() { |
|
42 | $('.comment-toggle').on('click', function() { | |
41 | $(this).parent().nextUntil('tr.line').toggle('inline-comments'); |
|
43 | $(this).parent().nextUntil('tr.line').toggle('inline-comments'); | |
@@ -43,7 +45,6 b' var bindToggleButtons = function() {' | |||||
43 | }; |
|
45 | }; | |
44 |
|
46 | |||
45 |
|
47 | |||
46 |
|
||||
47 | var _submitAjaxPOST = function(url, postData, successHandler, failHandler) { |
|
48 | var _submitAjaxPOST = function(url, postData, successHandler, failHandler) { | |
48 | failHandler = failHandler || function() {}; |
|
49 | failHandler = failHandler || function() {}; | |
49 | postData = toQueryString(postData); |
|
50 | postData = toQueryString(postData); | |
@@ -63,8 +64,6 b' var _submitAjaxPOST = function(url, post' | |||||
63 | }; |
|
64 | }; | |
64 |
|
65 | |||
65 |
|
66 | |||
66 |
|
||||
67 |
|
||||
68 | /* Comment form for main and inline comments */ |
|
67 | /* Comment form for main and inline comments */ | |
69 | (function(mod) { |
|
68 | (function(mod) { | |
70 |
|
69 | |||
@@ -239,8 +238,7 b' var _submitAjaxPOST = function(url, post' | |||||
239 | }; |
|
238 | }; | |
240 |
|
239 | |||
241 | this.markCommentResolved = function(resolvedCommentId){ |
|
240 | this.markCommentResolved = function(resolvedCommentId){ | |
242 | $('#comment-label-{0}'.format(resolvedCommentId)).find('.resolved').show(); |
|
241 | Rhodecode.comments.markCommentResolved(resolvedCommentId) | |
243 | $('#comment-label-{0}'.format(resolvedCommentId)).find('.resolve').hide(); |
|
|||
244 | }; |
|
242 | }; | |
245 |
|
243 | |||
246 | this.isAllowedToSubmit = function() { |
|
244 | this.isAllowedToSubmit = function() { | |
@@ -1308,6 +1306,11 b' var CommentsController = function() {' | |||||
1308 | return $(tmpl); |
|
1306 | return $(tmpl); | |
1309 | } |
|
1307 | } | |
1310 |
|
1308 | |||
|
1309 | this.markCommentResolved = function(commentId) { | |||
|
1310 | $('#comment-label-{0}'.format(commentId)).find('.resolved').show(); | |||
|
1311 | $('#comment-label-{0}'.format(commentId)).find('.resolve').hide(); | |||
|
1312 | }; | |||
|
1313 | ||||
1311 | this.createComment = function(node, f_path, line_no, resolutionComment) { |
|
1314 | this.createComment = function(node, f_path, line_no, resolutionComment) { | |
1312 | self.edit = false; |
|
1315 | self.edit = false; | |
1313 | var $node = $(node); |
|
1316 | var $node = $(node); | |
@@ -1403,7 +1406,7 b' var CommentsController = function() {' | |||||
1403 |
|
1406 | |||
1404 | //mark visually which comment was resolved |
|
1407 | //mark visually which comment was resolved | |
1405 | if (resolvesCommentId) { |
|
1408 | if (resolvesCommentId) { | |
1406 |
|
|
1409 | self.markCommentResolved(resolvesCommentId); | |
1407 | } |
|
1410 | } | |
1408 |
|
1411 | |||
1409 | // run global callback on submit |
|
1412 | // run global callback on submit | |
@@ -1493,9 +1496,144 b' var CommentsController = function() {' | |||||
1493 | return false; |
|
1496 | return false; | |
1494 | }; |
|
1497 | }; | |
1495 |
|
1498 | |||
|
1499 | this.resolveTodo = function (elem, todoId) { | |||
|
1500 | var commentId = todoId; | |||
|
1501 | ||||
|
1502 | SwalNoAnimation.fire({ | |||
|
1503 | title: 'Resolve TODO {0}'.format(todoId), | |||
|
1504 | showCancelButton: true, | |||
|
1505 | confirmButtonText: _gettext('Yes'), | |||
|
1506 | showLoaderOnConfirm: true, | |||
|
1507 | ||||
|
1508 | allowOutsideClick: function () { | |||
|
1509 | !Swal.isLoading() | |||
|
1510 | }, | |||
|
1511 | preConfirm: function () { | |||
|
1512 | var comment = $('#comment-' + commentId); | |||
|
1513 | var commentData = comment.data(); | |||
|
1514 | ||||
|
1515 | var f_path = null | |||
|
1516 | var line_no = null | |||
|
1517 | if (commentData.commentInline) { | |||
|
1518 | f_path = commentData.commentFPath; | |||
|
1519 | line_no = commentData.commentLineNo; | |||
|
1520 | } | |||
|
1521 | ||||
|
1522 | var renderer = templateContext.visual.default_renderer; | |||
|
1523 | var commentBoxUrl = '{1}#comment-{0}'.format(commentId); | |||
|
1524 | ||||
|
1525 | // Pull request case | |||
|
1526 | if (templateContext.pull_request_data.pull_request_id !== null) { | |||
|
1527 | var commentUrl = pyroutes.url('pullrequest_comment_create', | |||
|
1528 | { | |||
|
1529 | 'repo_name': templateContext.repo_name, | |||
|
1530 | 'pull_request_id': templateContext.pull_request_data.pull_request_id, | |||
|
1531 | 'comment_id': commentId | |||
|
1532 | }); | |||
|
1533 | } else { | |||
|
1534 | var commentUrl = pyroutes.url('repo_commit_comment_create', | |||
|
1535 | { | |||
|
1536 | 'repo_name': templateContext.repo_name, | |||
|
1537 | 'commit_id': templateContext.commit_data.commit_id, | |||
|
1538 | 'comment_id': commentId | |||
|
1539 | }); | |||
|
1540 | } | |||
|
1541 | ||||
|
1542 | if (renderer === 'rst') { | |||
|
1543 | commentBoxUrl = '`#{0} <{1}#comment-{0}>`_'.format(commentId, commentUrl); | |||
|
1544 | } else if (renderer === 'markdown') { | |||
|
1545 | commentBoxUrl = '[#{0}]({1}#comment-{0})'.format(commentId, commentUrl); | |||
|
1546 | } | |||
|
1547 | var resolveText = _gettext('TODO from comment {0} was fixed.').format(commentBoxUrl); | |||
|
1548 | ||||
|
1549 | var postData = { | |||
|
1550 | text: resolveText, | |||
|
1551 | comment_type: 'note', | |||
|
1552 | draft: false, | |||
|
1553 | csrf_token: CSRF_TOKEN, | |||
|
1554 | resolves_comment_id: commentId | |||
|
1555 | } | |||
|
1556 | if (commentData.commentInline) { | |||
|
1557 | postData['f_path'] = f_path; | |||
|
1558 | postData['line'] = line_no; | |||
|
1559 | } | |||
|
1560 | ||||
|
1561 | return new Promise(function (resolve, reject) { | |||
|
1562 | $.ajax({ | |||
|
1563 | type: 'POST', | |||
|
1564 | data: postData, | |||
|
1565 | url: commentUrl, | |||
|
1566 | headers: {'X-PARTIAL-XHR': true} | |||
|
1567 | }) | |||
|
1568 | .done(function (data) { | |||
|
1569 | resolve(data); | |||
|
1570 | }) | |||
|
1571 | .fail(function (jqXHR, textStatus, errorThrown) { | |||
|
1572 | var prefix = "Error while resolving TODO.\n" | |||
|
1573 | var message = formatErrorMessage(jqXHR, textStatus, errorThrown, prefix); | |||
|
1574 | ajaxErrorSwal(message); | |||
|
1575 | }); | |||
|
1576 | }) | |||
|
1577 | } | |||
|
1578 | ||||
|
1579 | }) | |||
|
1580 | .then(function (result) { | |||
|
1581 | var success = function (json_data) { | |||
|
1582 | resolvesCommentId = commentId; | |||
|
1583 | var commentResolved = json_data[Object.keys(json_data)[0]] | |||
|
1584 | ||||
|
1585 | try { | |||
|
1586 | ||||
|
1587 | if (commentResolved.f_path) { | |||
|
1588 | // inject newly created comments, json_data is {<comment_id>: {}} | |||
|
1589 | self.attachInlineComment(json_data) | |||
|
1590 | } else { | |||
|
1591 | self.attachGeneralComment(json_data) | |||
|
1592 | } | |||
|
1593 | ||||
|
1594 | //mark visually which comment was resolved | |||
|
1595 | if (resolvesCommentId) { | |||
|
1596 | self.markCommentResolved(resolvesCommentId); | |||
|
1597 | } | |||
|
1598 | ||||
|
1599 | // run global callback on submit | |||
|
1600 | if (window.commentFormGlobalSubmitSuccessCallback !== undefined) { | |||
|
1601 | commentFormGlobalSubmitSuccessCallback({ | |||
|
1602 | draft: false, | |||
|
1603 | comment_id: commentId | |||
|
1604 | }); | |||
|
1605 | } | |||
|
1606 | ||||
|
1607 | } catch (e) { | |||
|
1608 | console.error(e); | |||
|
1609 | } | |||
|
1610 | ||||
|
1611 | if (window.updateSticky !== undefined) { | |||
|
1612 | // potentially our comments change the active window size, so we | |||
|
1613 | // notify sticky elements | |||
|
1614 | updateSticky() | |||
|
1615 | } | |||
|
1616 | ||||
|
1617 | if (window.refreshAllComments !== undefined) { | |||
|
1618 | // if we have this handler, run it, and refresh all comments boxes | |||
|
1619 | refreshAllComments() | |||
|
1620 | } | |||
|
1621 | // re trigger the linkification of next/prev navigation | |||
|
1622 | linkifyComments($('.inline-comment-injected')); | |||
|
1623 | timeagoActivate(); | |||
|
1624 | tooltipActivate(); | |||
|
1625 | }; | |||
|
1626 | ||||
|
1627 | if (result.value) { | |||
|
1628 | $(elem).remove(); | |||
|
1629 | success(result.value) | |||
|
1630 | } | |||
|
1631 | }) | |||
|
1632 | }; | |||
|
1633 | ||||
1496 | }; |
|
1634 | }; | |
1497 |
|
1635 | |||
1498 | window.commentHelp = function(renderer) { |
|
1636 | window.commentHelp = function(renderer) { | |
1499 | var funcData = {'renderer': renderer} |
|
1637 | var funcData = {'renderer': renderer} | |
1500 | return renderTemplate('commentHelpHovercard', funcData) |
|
1638 | return renderTemplate('commentHelpHovercard', funcData) | |
1501 | } No newline at end of file |
|
1639 | } |
@@ -236,6 +236,14 b' if (show_disabled) {' | |||||
236 | Created: |
|
236 | Created: | |
237 | <time class="timeago" title="<%= created_on %>" datetime="<%= datetime %>"><%= $.timeago(datetime) %></time> |
|
237 | <time class="timeago" title="<%= created_on %>" datetime="<%= datetime %>"><%= $.timeago(datetime) %></time> | |
238 |
|
238 | |||
|
239 | <% if (is_todo) { %> | |||
|
240 | <div style="text-align: center; padding-top: 5px"> | |||
|
241 | <a class="btn btn-sm" href="#resolveTodo<%- comment_id -%>" onclick="Rhodecode.comments.resolveTodo(this, '<%- comment_id -%>'); return false"> | |||
|
242 | <strong>Resolve TODO</strong> | |||
|
243 | </a> | |||
|
244 | </div> | |||
|
245 | <% } %> | |||
|
246 | ||||
239 | </div> |
|
247 | </div> | |
240 |
|
248 | |||
241 | </script> |
|
249 | </script> |
General Comments 0
You need to be logged in to leave comments.
Login now