Skip to content

Feature: Change icon for commented changesets #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)