Skip to content

Commit 5b81529

Browse files
committed
Change icon of revision link in Log-View if revision is commented
1 parent aa945a8 commit 5b81529

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

code_comments/htdocs/code-comments.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,9 @@ button#subscribe {
130130
float: right;
131131
margin: 5px 0 5px 5px;
132132
}
133+
134+
/* Highlight links to commented revisions */
135+
.chglist td.rev a.chgset.chgset-commented {
136+
background-image: url(jquery-ui/images/ui-icons_4b954f_256x240.png);
137+
background-position: -131px -98px;
138+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$(document).ready(function($){
2+
function isLinkToCommentedRevision($link) {
3+
const href = $link.attr('href');
4+
const match = href && href.match(/^\/changeset\/([^/]+)\/.*$/);
5+
if (!match) {
6+
return false;
7+
}
8+
const targetRevision = match[1];
9+
return CodeCommentsCommentedRevisions.includes(targetRevision);
10+
}
11+
const $changesetLinks = jQuery('td.rev a.chgset')
12+
$changesetLinks.each(function(){
13+
$link = $(this)
14+
if (isLinkToCommentedRevision($link)) {
15+
$link.addClass('chgset-commented');
16+
}
17+
});
18+
});

code_comments/web.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,3 +351,30 @@ def match_request(self, req):
351351
def process_request(self, req):
352352
html = format_to_html(req, self.env, req.args.get('text', ''))
353353
req.send(html.encode('utf-8'))
354+
355+
356+
class HighlightCommentedRevisions(Component):
357+
implements(IRequestFilter)
358+
359+
# IRequestFilter methods
360+
def pre_process_request(self, req, handler):
361+
return handler
362+
363+
def post_process_request(self, req, template, data, metadata):
364+
if not re.match(r'^\/log\/\w+', req.path_info):
365+
return template, data, metadata
366+
367+
query_params = {
368+
'type': 'changeset',
369+
'reponame': data['reponame'],
370+
}
371+
revisions_with_comments = []
372+
for revision in data['changes']:
373+
query_params['revision'] = revision
374+
has_comments = bool(Comments(None, self.env).count(query_params))
375+
if has_comments:
376+
revisions_with_comments.append(revision)
377+
378+
add_script_data(req, {'CodeCommentsCommentedRevisions': revisions_with_comments})
379+
add_script(req, 'code-comments/log-view-enhancer.js')
380+
return template, data, metadata

0 commit comments

Comments
 (0)