From e244449593987b604e4715327822a7d85125058a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 25 2019 16:15:51 +0000 Subject: [PATCH 1/3] Load all the tickets for the depending/blocking fields The ajax call had not been adjusted for the change in the pagination of the endpoints so it was returning only some of the tickets instead of all of them. This commit adjusts this. We may need to optimize this for large projects but this can be done in another change. Fixes https://pagure.io/pagure/issue/3939 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index a36f0e6..6bffda5 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -1092,6 +1092,22 @@ $(".comment_and_close_action").click(function(event){ } ); + function _get_issues(url, callback){ + $.getJSON( + url, + function( data ) { + issues = data.issues.filter(function(el) { + return el.id !== {{issue.id}}; + }); + callback(issues); + if (data.pagination.next){ + _get_issues(data.pagination.next, callback) + } + } + ); + } + + var _block_loaded = false; $('.mainform #blocking').selectize({ plugins: ['remove_button'], valueField: 'id', @@ -1108,21 +1124,20 @@ $(".comment_and_close_action").click(function(event){ }, create: false, load: function(query, callback) { - $.getJSON( - "{{ url_for('api_ns.api_view_issues', - repo=repo.name, - username=username, - namespace=repo.namespace) }}", - function( data ) { - issues = data.issues.filter(function(el) { - return el.id !== {{issue.id}}; - }); - callback(issues); - } - ); + if (_block_loaded){ + callback(); + return; + }; + var _url = "{{ url_for('api_ns.api_view_issues', + repo=repo.name, + username=username, + namespace=repo.namespace) }}"; + _get_issues(_url, callback); + _block_loaded = true; } }); + var _dep_loaded = false; $('.mainform #depending').selectize({ plugins: ['remove_button'], valueField: 'id', @@ -1139,18 +1154,16 @@ $(".comment_and_close_action").click(function(event){ }, create: false, load: function(query, callback) { - $.getJSON( - "{{ url_for('api_ns.api_view_issues', - repo=repo.name, - username=username, - namespace=repo.namespace) }}", - function( data ) { - issues = data.issues.filter(function(el) { - return el.id !== {{issue.id}}; - }); - callback(issues); - } - ); + if (_dep_loaded){ + callback(); + return; + }; + var _url = "{{ url_for('api_ns.api_view_issues', + repo=repo.name, + username=username, + namespace=repo.namespace) }}"; + _get_issues(_url, callback); + _dep_loaded = true; } }); From b4744291d62e117b91f14d3c915b00f11dc54f06 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 25 2019 16:15:51 +0000 Subject: [PATCH 2/3] Add support for restricting the issues search to certain identifiers Basically you can now restrict the issues search to the ones containing the provided identifier (providing, not matching). This will allow the UI to get only the tickets of interest. Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/query.py b/pagure/lib/query.py index af0619c..078aeac 100644 --- a/pagure/lib/query.py +++ b/pagure/lib/query.py @@ -47,8 +47,7 @@ import sqlalchemy.schema import werkzeug from six.moves.urllib_parse import urlparse, urlencode, parse_qsl -from sqlalchemy import func -from sqlalchemy import asc, desc +from sqlalchemy import asc, desc, func, cast, Text from sqlalchemy.orm import aliased from flask import url_for @@ -2728,6 +2727,7 @@ def search_issues( count=False, offset=None, limit=None, + search_id=None, search_pattern=None, search_content=None, custom_search=None, @@ -2788,6 +2788,8 @@ def search_issues( :kwarg count: a boolean to specify if the method should return the list of Issues or just do a COUNT query. :type count: boolean + :kwarg search_id: an integer to search in issues identifier + :type search_id: int or None :kwarg search_pattern: a string to search in issues title :type search_pattern: str or None :kwarg search_content: a string to search in the issues comments @@ -3021,6 +3023,11 @@ def search_issues( model.Issue.title.ilike("%%%s%%" % search_pattern) ) + if search_id is not None: + query = query.filter( + cast(model.Issue.id, Text).ilike("%%%s%%" % search_id) + ) + column = model.Issue.date_created if order_key: # If we are ordering by assignee, then order by the assignees' From b8db6426d203de0b9b36133ae7ad690811f21d3e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Feb 25 2019 16:15:51 +0000 Subject: [PATCH 3/3] When loading blocking or depending tickets restricts the list of tickets Instead of loading the entire list of issues, use the user's input to restrict the tickets to the ones containing the identifier given. Fixes https://pagure.io/pagure/issue/2081 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/api/issue.py b/pagure/api/issue.py index 7835460..c0707e4 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -521,6 +521,7 @@ def api_view_issues(repo, username=None, namespace=None): status = flask.request.args.get("status", None) tags = flask.request.args.getlist("tags") tags = [tag.strip() for tag in tags if tag.strip()] + search_id = flask.request.args.get("query_id", None) priority_key = None if priority: @@ -560,6 +561,7 @@ def api_view_issues(repo, username=None, namespace=None): "priority": priority_key, "order": order, "no_milestones": no_stones, + "search_id": search_id, } if status is not None: diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 6bffda5..9adda95 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -1107,7 +1107,6 @@ $(".comment_and_close_action").click(function(event){ ); } - var _block_loaded = false; $('.mainform #blocking').selectize({ plugins: ['remove_button'], valueField: 'id', @@ -1124,20 +1123,18 @@ $(".comment_and_close_action").click(function(event){ }, create: false, load: function(query, callback) { - if (_block_loaded){ + if (!query){ callback(); return; }; var _url = "{{ url_for('api_ns.api_view_issues', repo=repo.name, username=username, - namespace=repo.namespace) }}"; + namespace=repo.namespace) }}" + "?query_id=" + query; _get_issues(_url, callback); - _block_loaded = true; } }); - var _dep_loaded = false; $('.mainform #depending').selectize({ plugins: ['remove_button'], valueField: 'id', @@ -1154,16 +1151,15 @@ $(".comment_and_close_action").click(function(event){ }, create: false, load: function(query, callback) { - if (_dep_loaded){ + if (!query){ callback(); return; }; var _url = "{{ url_for('api_ns.api_view_issues', repo=repo.name, username=username, - namespace=repo.namespace) }}"; + namespace=repo.namespace) }}" + "?query_id=" + query; _get_issues(_url, callback); - _dep_loaded = true; } });