Skip to content

Commit a60e169

Browse files
committed
Change icon of revision link in Log-View if revision is commented.
1 parent a06c315 commit a60e169

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
@@ -3,10 +3,12 @@
33
from trac.core import *
44
from trac.web.chrome import INavigationContributor, ITemplateProvider, add_script, add_script_data, add_stylesheet, add_notice, add_link
55
from trac.web.main import IRequestHandler, IRequestFilter
6+
from trac.web.api import ITemplateStreamFilter
67
from trac.util import Markup
78
from trac.util.text import to_unicode
89
from trac.util.presentation import Paginator
910
from trac.versioncontrol.api import RepositoryManager
11+
from genshi.filters import Transformer
1012
from code_comments.comments import Comments
1113
from code_comments.comment import CommentJSONEncoder, format_to_html
1214

@@ -290,3 +292,28 @@ def match_request(self, req):
290292

291293
def process_request(self, req):
292294
req.send(format_to_html(req, self.env, req.args.get('text', '')).encode('utf-8'))
295+
296+
class HighlightCommentedRevisions(Component):
297+
implements(ITemplateStreamFilter)
298+
299+
def filter_stream(self, req, method, filename, stream, data):
300+
if re.match(r'^\/log\/\w+', req.path_info):
301+
filter = Transformer('//a[@class="chgset"]')
302+
stream |= filter.attr("class", lambda name, event: self.addCssClassIfCommented(name, event))
303+
self.env.log.info(str(data))
304+
return stream
305+
306+
def addCssClassIfCommented(self, name, event):
307+
attrs = event[1][1]
308+
link = attrs.get('href')
309+
match = re.match(r'^\/changeset\/([^\/]+)\/([^\/\?\#]+)', link)
310+
if match:
311+
query_params = {}
312+
query_params['type'] = 'changeset'
313+
query_params['revision'] = match.group(1)
314+
query_params['reponame'] = match.group(2)
315+
count = Comments(None, self.env).count(query_params)
316+
return attrs.get(name) + (" chgset-commented" if (count > 0) else "")
317+
else:
318+
# Should not happen, link contained no revision-id
319+
return attrs.get(name)

0 commit comments

Comments
 (0)