Skip to content

Commit 5b092b8

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

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

code_comments/htdocs/code-comments.css

+6
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+
}

code_comments/web.py

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66

77
from trac.core import Component, implements
8+
from trac.web.api import ITemplateStreamFilter
89
from trac.util import Markup
910
from trac.util.presentation import Paginator
1011
from trac.util.text import to_unicode
@@ -13,6 +14,7 @@
1314
Chrome, INavigationContributor, ITemplateProvider, add_link, add_notice,
1415
add_script, add_script_data, add_stylesheet)
1516
from trac.web.main import IRequestHandler, IRequestFilter
17+
from genshi.filters import Transformer
1618

1719
from code_comments.comments import Comments
1820
from code_comments.comment import CommentJSONEncoder, format_to_html
@@ -351,3 +353,28 @@ def match_request(self, req):
351353
def process_request(self, req):
352354
html = format_to_html(req, self.env, req.args.get('text', ''))
353355
req.send(html.encode('utf-8'))
356+
357+
class HighlightCommentedRevisions(Component):
358+
implements(ITemplateStreamFilter)
359+
360+
def filter_stream(self, req, method, filename, stream, data):
361+
if re.match(r'^\/log\/\w+', req.path_info):
362+
filter = Transformer('//a[@class="chgset"]')
363+
stream |= filter.attr("class", lambda name, event: self.addCssClassIfCommented(name, event))
364+
self.env.log.info(str(data))
365+
return stream
366+
367+
def addCssClassIfCommented(self, name, event):
368+
attrs = event[1][1]
369+
link = attrs.get('href')
370+
match = re.match(r'^\/changeset\/([^\/]+)\/([^\/\?\#]+)', link)
371+
if match:
372+
query_params = {}
373+
query_params['type'] = 'changeset'
374+
query_params['revision'] = match.group(1)
375+
query_params['reponame'] = match.group(2)
376+
count = Comments(None, self.env).count(query_params)
377+
return attrs.get(name) + (" chgset-commented" if (count > 0) else "")
378+
else:
379+
# Should not happen, link contained no revision-id
380+
return attrs.get(name)

0 commit comments

Comments
 (0)