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 Dec 16, 2017
1 parent a06c315 commit 5b17906
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 @@ -3,10 +3,12 @@
from trac.core import *
from trac.web.chrome import INavigationContributor, ITemplateProvider, add_script, add_script_data, add_stylesheet, add_notice, add_link
from trac.web.main import IRequestHandler, IRequestFilter
from trac.web.api import ITemplateStreamFilter
from trac.util import Markup
from trac.util.text import to_unicode
from trac.util.presentation import Paginator
from trac.versioncontrol.api import RepositoryManager
from genshi.filters import Transformer
from code_comments.comments import Comments
from code_comments.comment import CommentJSONEncoder, format_to_html

Expand Down Expand Up @@ -290,3 +292,28 @@ def match_request(self, req):

def process_request(self, req):
req.send(format_to_html(req, self.env, req.args.get('text', '')).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 5b17906

Please sign in to comment.