##// END OF EJS Templates
comments: ensure we ALWAYS display unmatched comments.
marcink -
r3080:4caa8a84 default
parent child Browse files
Show More
@@ -368,19 +368,18 b' class DiffSet(object):'
368 adding highlighting, side by side/unified renderings and line diffs
368 adding highlighting, side by side/unified renderings and line diffs
369 """
369 """
370
370
371 HL_REAL = 'REAL' # highlights using original file, slow
371 HL_REAL = 'REAL' # highlights using original file, slow
372 HL_FAST = 'FAST' # highlights using just the line, fast but not correct
372 HL_FAST = 'FAST' # highlights using just the line, fast but not correct
373 # in the case of multiline code
373 # in the case of multiline code
374 HL_NONE = 'NONE' # no highlighting, fastest
374 HL_NONE = 'NONE' # no highlighting, fastest
375
375
376 def __init__(self, highlight_mode=HL_REAL, repo_name=None,
376 def __init__(self, highlight_mode=HL_REAL, repo_name=None,
377 source_repo_name=None,
377 source_repo_name=None,
378 source_node_getter=lambda filename: None,
378 source_node_getter=lambda filename: None,
379 target_node_getter=lambda filename: None,
379 target_node_getter=lambda filename: None,
380 source_nodes=None, target_nodes=None,
380 source_nodes=None, target_nodes=None,
381 max_file_size_limit=150 * 1024, # files over this size will
381 # files over this size will use fast highlighting
382 # use fast highlighting
382 max_file_size_limit=150 * 1024,
383 comments=None,
384 ):
383 ):
385
384
386 self.highlight_mode = highlight_mode
385 self.highlight_mode = highlight_mode
@@ -391,8 +390,6 b' class DiffSet(object):'
391 self.target_nodes = target_nodes or {}
390 self.target_nodes = target_nodes or {}
392 self.repo_name = repo_name
391 self.repo_name = repo_name
393 self.source_repo_name = source_repo_name or repo_name
392 self.source_repo_name = source_repo_name or repo_name
394 self.comments = comments or {}
395 self.comments_store = self.comments.copy()
396 self.max_file_size_limit = max_file_size_limit
393 self.max_file_size_limit = max_file_size_limit
397
394
398 def render_patchset(self, patchset, source_ref=None, target_ref=None):
395 def render_patchset(self, patchset, source_ref=None, target_ref=None):
@@ -518,20 +515,6 b' class DiffSet(object):'
518 hunkbit.target_file_path = target_file_path
515 hunkbit.target_file_path = target_file_path
519 filediff.hunks.append(hunkbit)
516 filediff.hunks.append(hunkbit)
520
517
521 left_comments = {}
522 if source_file_path in self.comments_store:
523 for lineno, comments in self.comments_store[source_file_path].items():
524 left_comments[lineno] = comments
525
526 if target_file_path in self.comments_store:
527 for lineno, comments in self.comments_store[target_file_path].items():
528 left_comments[lineno] = comments
529
530 # left comments are one that we couldn't place in diff lines.
531 # could be outdated, or the diff changed and this line is no
532 # longer available
533 filediff.left_comments = left_comments
534
535 return filediff
518 return filediff
536
519
537 def parse_hunk(self, hunk, source_file, target_file):
520 def parse_hunk(self, hunk, source_file, target_file):
@@ -28,7 +28,7 b''
28
28
29 <div class="meta">
29 <div class="meta">
30 <div class="comment-type-label">
30 <div class="comment-type-label">
31 <div class="comment-label ${comment.comment_type or 'note'}" id="comment-label-${comment.comment_id}">
31 <div class="comment-label ${comment.comment_type or 'note'}" id="comment-label-${comment.comment_id}" title="line: ${comment.line_no}">
32 % if comment.comment_type == 'todo':
32 % if comment.comment_type == 'todo':
33 % if comment.resolved:
33 % if comment.resolved:
34 <div class="resolved tooltip" title="${_('Resolved by comment #{}').format(comment.resolved.comment_id)}">
34 <div class="resolved tooltip" title="${_('Resolved by comment #{}').format(comment.resolved.comment_id)}">
@@ -223,37 +223,59 b' collapse_all = len(diffset.files) > coll'
223 %endif
223 %endif
224 %endfor
224 %endfor
225
225
226 <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %>
227
226 ## outdated comments that do not fit into currently displayed lines
228 ## outdated comments that do not fit into currently displayed lines
227 % for lineno, comments in filediff.left_comments.items():
229 % for lineno, comments in unmatched_comments.items():
228
230
229 %if c.diffmode == 'unified':
231 %if c.diffmode == 'unified':
230 <tr class="cb-line">
232 % if loop.index == 0:
231 <td class="cb-data cb-context"></td>
233 <tr class="cb-hunk">
232 <td class="cb-lineno cb-context"></td>
234 <td colspan="3"></td>
233 <td class="cb-lineno cb-context"></td>
235 <td>
234 <td class="cb-content cb-context">
236 <div>
235 ${inline_comments_container(comments, inline_comments)}
237 ${_('Unmatched inline comments below')}
236 </td>
238 </div>
237 </tr>
239 </td>
238 %elif c.diffmode == 'sideside':
240 </tr>
239 <tr class="cb-line">
241 % endif
240 <td class="cb-data cb-context"></td>
242 <tr class="cb-line">
241 <td class="cb-lineno cb-context"></td>
243 <td class="cb-data cb-context"></td>
242 <td class="cb-content cb-context">
244 <td class="cb-lineno cb-context"></td>
243 % if lineno.startswith('o'):
245 <td class="cb-lineno cb-context"></td>
246 <td class="cb-content cb-context">
244 ${inline_comments_container(comments, inline_comments)}
247 ${inline_comments_container(comments, inline_comments)}
245 % endif
248 </td>
246 </td>
249 </tr>
250 %elif c.diffmode == 'sideside':
251 % if loop.index == 0:
252 <tr class="cb-hunk">
253 <td colspan="2"></td>
254 <td class="cb-line" colspan="6">
255 <div>
256 ${_('Unmatched comments below')}
257 </div>
258 </td>
259 </tr>
260 % endif
261 <tr class="cb-line">
262 <td class="cb-data cb-context"></td>
263 <td class="cb-lineno cb-context"></td>
264 <td class="cb-content cb-context">
265 % if lineno.startswith('o'):
266 ${inline_comments_container(comments, inline_comments)}
267 % endif
268 </td>
247
269
248 <td class="cb-data cb-context"></td>
270 <td class="cb-data cb-context"></td>
249 <td class="cb-lineno cb-context"></td>
271 <td class="cb-lineno cb-context"></td>
250 <td class="cb-content cb-context">
272 <td class="cb-content cb-context">
251 % if lineno.startswith('n'):
273 % if lineno.startswith('n'):
252 ${inline_comments_container(comments, inline_comments)}
274 ${inline_comments_container(comments, inline_comments)}
253 % endif
275 % endif
254 </td>
276 </td>
255 </tr>
277 </tr>
256 %endif
278 %endif
257
279
258 % endfor
280 % endfor
259
281
@@ -512,18 +534,20 b' from rhodecode.lib.diffs import NEW_FILE'
512 </%def>
534 </%def>
513
535
514 <%!
536 <%!
515 def get_comments_for(comments, filename, line_version, line_number):
537 def get_comments_for(diff_type, comments, filename, line_version, line_number):
516 if hasattr(filename, 'unicode_path'):
538 if hasattr(filename, 'unicode_path'):
517 filename = filename.unicode_path
539 filename = filename.unicode_path
518
540
519 if not isinstance(filename, basestring):
541 if not isinstance(filename, basestring):
520 return None
542 return None
521
543
522 line_key = '{}{}'.format(line_version, line_number)
544 line_key = '{}{}'.format(line_version, line_number) ## e.g o37, n12
545
523 if comments and filename in comments:
546 if comments and filename in comments:
524 file_comments = comments[filename]
547 file_comments = comments[filename]
525 if line_key in file_comments:
548 if line_key in file_comments:
526 return file_comments[line_key]
549 data = file_comments.pop(line_key)
550 return data
527 %>
551 %>
528
552
529 <%def name="render_hunk_lines_sideside(hunk, use_comments=False, inline_comments=None)">
553 <%def name="render_hunk_lines_sideside(hunk, use_comments=False, inline_comments=None)">
@@ -542,16 +566,17 b' def get_comments_for(comments, filename,'
542 data-line-no="${line.original.lineno}"
566 data-line-no="${line.original.lineno}"
543 >
567 >
544 <div>
568 <div>
545 <% loc = None %>
569
570 <% line_old_comments = None %>
546 %if line.original.get_comment_args:
571 %if line.original.get_comment_args:
547 <% loc = get_comments_for(inline_comments, *line.original.get_comment_args) %>
572 <% line_old_comments = get_comments_for('side-by-side', inline_comments, *line.original.get_comment_args) %>
548 %endif
573 %endif
549 %if loc:
574 %if line_old_comments:
550 <% has_outdated = any([x.outdated for x in loc]) %>
575 <% has_outdated = any([x.outdated for x in line_old_comments]) %>
551 % if has_outdated:
576 % if has_outdated:
552 <i title="${_('comments including outdated')}:${len(loc)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
577 <i title="${_('comments including outdated')}:${len(line_old_comments)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
553 % else:
578 % else:
554 <i title="${_('comments')}: ${len(loc)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
579 <i title="${_('comments')}: ${len(line_old_comments)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
555 % endif
580 % endif
556 %endif
581 %endif
557 </div>
582 </div>
@@ -574,8 +599,8 b' def get_comments_for(comments, filename,'
574 %endif
599 %endif
575 <span class="cb-code">${line.original.action} ${line.original.content or '' | n}</span>
600 <span class="cb-code">${line.original.action} ${line.original.content or '' | n}</span>
576
601
577 %if use_comments and line.original.lineno and loc:
602 %if use_comments and line.original.lineno and line_old_comments:
578 ${inline_comments_container(loc, inline_comments)}
603 ${inline_comments_container(line_old_comments, inline_comments)}
579 %endif
604 %endif
580
605
581 </td>
606 </td>
@@ -585,16 +610,16 b' def get_comments_for(comments, filename,'
585 <div>
610 <div>
586
611
587 %if line.modified.get_comment_args:
612 %if line.modified.get_comment_args:
588 <% lmc = get_comments_for(inline_comments, *line.modified.get_comment_args) %>
613 <% line_new_comments = get_comments_for('side-by-side', inline_comments, *line.modified.get_comment_args) %>
589 %else:
614 %else:
590 <% lmc = None%>
615 <% line_new_comments = None%>
591 %endif
616 %endif
592 %if lmc:
617 %if line_new_comments:
593 <% has_outdated = any([x.outdated for x in lmc]) %>
618 <% has_outdated = any([x.outdated for x in line_new_comments]) %>
594 % if has_outdated:
619 % if has_outdated:
595 <i title="${_('comments including outdated')}:${len(lmc)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
620 <i title="${_('comments including outdated')}:${len(line_new_comments)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
596 % else:
621 % else:
597 <i title="${_('comments')}: ${len(lmc)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
622 <i title="${_('comments')}: ${len(line_new_comments)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
598 % endif
623 % endif
599 %endif
624 %endif
600 </div>
625 </div>
@@ -616,8 +641,8 b' def get_comments_for(comments, filename,'
616 ${render_add_comment_button()}
641 ${render_add_comment_button()}
617 %endif
642 %endif
618 <span class="cb-code">${line.modified.action} ${line.modified.content or '' | n}</span>
643 <span class="cb-code">${line.modified.action} ${line.modified.content or '' | n}</span>
619 %if use_comments and line.modified.lineno and lmc:
644 %if use_comments and line.modified.lineno and line_new_comments:
620 ${inline_comments_container(lmc, inline_comments)}
645 ${inline_comments_container(line_new_comments, inline_comments)}
621 %endif
646 %endif
622 </td>
647 </td>
623 </tr>
648 </tr>
@@ -639,7 +664,7 b' def get_comments_for(comments, filename,'
639 <div>
664 <div>
640
665
641 %if comments_args:
666 %if comments_args:
642 <% comments = get_comments_for(inline_comments, *comments_args) %>
667 <% comments = get_comments_for('unified', inline_comments, *comments_args) %>
643 %else:
668 %else:
644 <% comments = None%>
669 <% comments = None%>
645 %endif
670 %endif
General Comments 0
You need to be logged in to leave comments. Login now