Skip to content

Commit fdaff49

Browse files
committed
Allow filtering the list of code comments by repository
1 parent f35cf28 commit fdaff49

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

code_comments/comments.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ def comment_from_row(self, row):
2121
def get_filter_values(self):
2222
comments = self.all()
2323
return {
24+
'repos': self.get_all_repos(comments),
2425
'paths': self.get_all_paths(comments),
2526
'authors': self.get_all_comment_authors(comments),
2627
}
2728

29+
def get_all_repos(self, comments):
30+
# Skip the empty string which is the repository for comments on attachments
31+
return sorted(list(set([comment.reponame for comment in comments if comment.reponame != ''])))
32+
2833
def get_all_paths(self, comments):
2934
def get_directory(path):
3035
parts = os.path.split(path)[0].split('/')

code_comments/templates/comments.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ <h1>Code Comments</h1>
1515
<button id="send-to-ticket" type="submit" data-url="${href('code-comments', 'create-ticket')}">Create ticket with selected</button>
1616
&nbsp;Filter comments:
1717
<form action="${href('code-comments')}" method="GET" style="display: inline;">
18+
<select id="filter-by-repo" name="filter-by-repo">
19+
<option value='' selected="selected">-- All repositories --</option>
20+
<option py:for="repo in repos"
21+
selected="${current_repo_selection == repo or None}"
22+
value="$repo" py:content="repo"></option>
23+
</select>
1824
<select id="filter-by-path" name="filter-by-path">
1925
<option value='' selected="selected">-- All paths --</option>
2026
<option py:for="path in paths"

code_comments/web.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,15 @@ def post_process_request(self, req, template, data, content_type):
198198
return template, data, content_type
199199

200200
def add_path_and_author_filters(self):
201+
self.data['current_repo_selection'] = ''
201202
self.data['current_path_selection'] = ''
202203
self.data['current_author_selection'] = ''
203204

205+
if self.req.args.get('filter-by-repo'):
206+
self.args['reponame'] = \
207+
self.req.args['filter-by-repo']
208+
self.data['current_repo_selection'] = \
209+
self.req.args['filter-by-repo']
204210
if self.req.args.get('filter-by-path'):
205211
self.args['path__prefix'] = \
206212
self.req.args['filter-by-path']

0 commit comments

Comments
 (0)