diff --git a/pagure/lib/query.py b/pagure/lib/query.py index 008e731..a4a3c49 100644 --- a/pagure/lib/query.py +++ b/pagure/lib/query.py @@ -3210,6 +3210,7 @@ def search_pull_requests( status=None, author=None, assignee=None, + tags=None, count=False, offset=None, limit=None, @@ -3285,6 +3286,57 @@ def search_pull_requests( if branch_from is not None: query = query.filter(model.PullRequest.branch_from == branch_from) + if tags is not None and tags != []: + if isinstance(tags, six.string_types): + tags = [tags] + notags = [] + ytags = [] + for tag in tags: + if tag.startswith("!"): + notags.append(tag[1:]) + else: + ytags.append(tag) + + if ytags: + sub_q2 = session.query(sqlalchemy.distinct(model.PullRequest.uid)) + if project_id is not None: + sub_q2 = sub_q2.filter( + model.PullRequest.project_id == project_id + ) + sub_q2 = ( + sub_q2.filter( + model.PullRequest.uid == model.TagPullRequest.request_uid + ) + .filter(model.TagPullRequest.tag_id == model.TagColored.id) + .filter(model.TagColored.tag.in_(ytags)) + ) + if notags: + sub_q3 = session.query(sqlalchemy.distinct(model.PullRequest.uid)) + if project_id is not None: + sub_q3 = sub_q3.filter( + model.PullRequest.project_id == project_id + ) + sub_q3 = ( + sub_q3.filter( + model.PullRequest.uid == model.TagPullRequest.request_uid + ) + .filter(model.TagPullRequest.tag_id == model.TagColored.id) + .filter(model.TagColored.tag.in_(notags)) + ) + # Adjust the main query based on the parameters specified + if ytags and not notags: + query = query.filter(model.PullRequest.uid.in_(sub_q2)) + elif not ytags and notags: + query = query.filter(~model.PullRequest.uid.in_(sub_q3)) + elif ytags and notags: + final_set = set([i[0] for i in sub_q2.all()]) - set( + [i[0] for i in sub_q3.all()] + ) + if final_set: + query = query.filter( + model.PullRequest.uid.in_(list(final_set)) + ) + if search_pattern is not None: if "*" in search_pattern: search_pattern = search_pattern.replace("*", "%") diff --git a/pagure/templates/requests.html b/pagure/templates/requests.html index 927ba87..45a23f4 100644 --- a/pagure/templates/requests.html +++ b/pagure/templates/requests.html @@ -11,6 +11,20 @@ {% block header %} + {% endblock %} {% block repo %} @@ -133,6 +147,20 @@ repo=repo.name ) }}" method="GET"> +
+ +
+ +
+
+ +
+
+
@@ -309,6 +337,25 @@ $(document).ready(function() { $('input[name="search_pattern"]').val(''); }); + var $tags_selectize = $('#tags-selectize').selectize({ + plugins: ['remove_button'], + closeAfterSelect: true, + onInitialize: function(){ + $("#tags-filter-group .selectize-control").on('click', function(event){ + event.stopPropagation(); + }) + $("#filters-dropdown").on('click', function(event){ + event.stopPropagation(); + }) + } + }); + + var tags_selectize_control = $tags_selectize[0].selectize; + + $("#tags-selectize-reset").on('click', function(e){ + tags_selectize_control.clear(); + }); + var $assignee_selectize = $('#assignee-selectize').selectize({ valueField: 'user', labelField: 'user', diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index ca3e25a..b6834a8 100644 --- a/pagure/ui/fork.py +++ b/pagure/ui/fork.py @@ -69,6 +69,8 @@ def request_pulls(repo, username=None, namespace=None): """ List all Pull-requests associated to a repo """ status = flask.request.args.get("status", "Open") + tags = flask.request.args.getlist("tags") + tags = [tag.strip() for tag in tags if tag.strip()] assignee = flask.request.args.get("assignee", None) search_pattern = flask.request.args.get("search_pattern", None) author = flask.request.args.get("author", None) @@ -98,6 +100,7 @@ def request_pulls(repo, username=None, namespace=None): order_key=order_key, assignee=assignee, author=author, + tags=tags, search_pattern=search_pattern, offset=flask.g.offset, limit=flask.g.limit, @@ -112,6 +115,7 @@ def request_pulls(repo, username=None, namespace=None): order_key=order_key, assignee=assignee, author=author, + tags=tags, search_pattern=search_pattern, offset=flask.g.offset, limit=flask.g.limit, @@ -126,6 +130,7 @@ def request_pulls(repo, username=None, namespace=None): order_key=order_key, assignee=assignee, author=author, + tags=tags, search_pattern=search_pattern, offset=flask.g.offset, limit=flask.g.limit, @@ -140,6 +145,7 @@ def request_pulls(repo, username=None, namespace=None): order_key=order_key, assignee=assignee, author=author, + tags=tags, search_pattern=search_pattern, offset=flask.g.offset, limit=flask.g.limit, @@ -151,6 +157,7 @@ def request_pulls(repo, username=None, namespace=None): status="Open", assignee=assignee, author=author, + tags=tags, search_pattern=search_pattern, count=True, ) @@ -161,6 +168,7 @@ def request_pulls(repo, username=None, namespace=None): status="Merged", assignee=assignee, author=author, + tags=tags, search_pattern=search_pattern, count=True, ) @@ -171,6 +179,7 @@ def request_pulls(repo, username=None, namespace=None): status="Closed", assignee=assignee, author=author, + tags=tags, search_pattern=search_pattern, count=True, ) @@ -193,11 +202,15 @@ def request_pulls(repo, username=None, namespace=None): total_requests = closed_cnt + merged_cnt + open_cnt total_page = int(ceil(total_requests / float(flask.g.limit))) + tag_list = pagure.lib.query.get_tags_of_project(flask.g.session, repo) + return flask.render_template( "requests.html", select="requests", repo=repo, username=username, + tag_list=tag_list, + tags=tags, requests=requests, open_cnt=open_cnt, merged_cnt=merged_cnt,