From 5b81529e086baef23cf28e5a34f974a66d32e95c Mon Sep 17 00:00:00 2001 From: Sebastian Dietrich Date: Sun, 26 Nov 2017 00:18:53 +0100 Subject: [PATCH] Change icon of revision link in Log-View if revision is commented --- code_comments/htdocs/code-comments.css | 6 +++++ code_comments/htdocs/log-view-enhancer.js | 18 +++++++++++++++ code_comments/web.py | 27 +++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 code_comments/htdocs/log-view-enhancer.js diff --git a/code_comments/htdocs/code-comments.css b/code_comments/htdocs/code-comments.css index afe1651..b9507c5 100644 --- a/code_comments/htdocs/code-comments.css +++ b/code_comments/htdocs/code-comments.css @@ -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; +} diff --git a/code_comments/htdocs/log-view-enhancer.js b/code_comments/htdocs/log-view-enhancer.js new file mode 100644 index 0000000..091c5fe --- /dev/null +++ b/code_comments/htdocs/log-view-enhancer.js @@ -0,0 +1,18 @@ +$(document).ready(function($){ + function isLinkToCommentedRevision($link) { + const href = $link.attr('href'); + const match = href && href.match(/^\/changeset\/([^/]+)\/.*$/); + if (!match) { + return false; + } + const targetRevision = match[1]; + return CodeCommentsCommentedRevisions.includes(targetRevision); + } + const $changesetLinks = jQuery('td.rev a.chgset') + $changesetLinks.each(function(){ + $link = $(this) + if (isLinkToCommentedRevision($link)) { + $link.addClass('chgset-commented'); + } + }); +}); diff --git a/code_comments/web.py b/code_comments/web.py index 83342c7..89628a0 100644 --- a/code_comments/web.py +++ b/code_comments/web.py @@ -351,3 +351,30 @@ 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(IRequestFilter) + + # IRequestFilter methods + def pre_process_request(self, req, handler): + return handler + + def post_process_request(self, req, template, data, metadata): + if not re.match(r'^\/log\/\w+', req.path_info): + return template, data, metadata + + query_params = { + 'type': 'changeset', + 'reponame': data['reponame'], + } + revisions_with_comments = [] + for revision in data['changes']: + query_params['revision'] = revision + has_comments = bool(Comments(None, self.env).count(query_params)) + if has_comments: + revisions_with_comments.append(revision) + + add_script_data(req, {'CodeCommentsCommentedRevisions': revisions_with_comments}) + add_script(req, 'code-comments/log-view-enhancer.js') + return template, data, metadata