Skip to content

Commit

Permalink
Change icon of revision link in Log-View if revision is commented.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebDieBln committed Sep 22, 2019
1 parent 3d99bf6 commit fa227a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions code_comments/htdocs/code-comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,9 @@ button#subscribe {
float: right;
margin: 5px 0 5px 5px;
}

/* Highlight links to commented revisions */
.chglist td.rev a.chgset.chgset-commented {
background-image: url(jquery-ui/images/ui-icons_4b954f_256x240.png);
background-position: -131px -98px;
}
27 changes: 27 additions & 0 deletions code_comments/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re

from trac.core import Component, implements
from trac.web.api import ITemplateStreamFilter
from trac.util import Markup
from trac.util.presentation import Paginator
from trac.util.text import to_unicode
Expand All @@ -13,6 +14,7 @@
Chrome, INavigationContributor, ITemplateProvider, add_link, add_notice,
add_script, add_script_data, add_stylesheet)
from trac.web.main import IRequestHandler, IRequestFilter
from genshi.filters import Transformer

from code_comments.comments import Comments
from code_comments.comment import CommentJSONEncoder, format_to_html
Expand Down Expand Up @@ -351,3 +353,28 @@ def match_request(self, req):
def process_request(self, req):
html = format_to_html(req, self.env, req.args.get('text', ''))
req.send(html.encode('utf-8'))

class HighlightCommentedRevisions(Component):
implements(ITemplateStreamFilter)

def filter_stream(self, req, method, filename, stream, data):
if re.match(r'^\/log\/\w+', req.path_info):
filter = Transformer('//a[@class="chgset"]')
stream |= filter.attr("class", lambda name, event: self.addCssClassIfCommented(name, event))
self.env.log.info(str(data))
return stream

def addCssClassIfCommented(self, name, event):
attrs = event[1][1]
link = attrs.get('href')
match = re.match(r'^\/changeset\/([^\/]+)\/([^\/\?\#]+)', link)
if match:
query_params = {}
query_params['type'] = 'changeset'
query_params['revision'] = match.group(1)
query_params['reponame'] = match.group(2)
count = Comments(None, self.env).count(query_params)
return attrs.get(name) + (" chgset-commented" if (count > 0) else "")
else:
# Should not happen, link contained no revision-id
return attrs.get(name)

0 comments on commit fa227a6

Please sign in to comment.