#5009 Rework the "My PR" page so it does not pull so many info at once
Merged 5 days ago by pingou. Opened 17 days ago by pingou.

@@ -11,54 +11,49 @@ 

        <h4 class="mb-0 font-weight-bold">

            Pull Requests for {{ username | avatar(20) | safe }} {{ username }}

        </h4>

+ 

+       <div class="ml-auto">

+           <span class="btn-group btn-group-sm issues-tagbar" role="group">

+               <a data-togglebutton="pr-type-filed" href="?type=filed&status={{ pr_status }}" id="toggle-open"

+                 class="btn {{ 'btn-primary' if pr_type == 'filed' else 'btn-outline-primary' }} btn-sm">PR I filed</a>

+               <a data-togglebutton="pr-type-actionable" href="?type=actionable&status={{ pr_status }}" id="toggle-merged"

+                 class="btn {{ 'btn-primary' if pr_type == 'actionable' else 'btn-outline-primary' }} btn-sm">PR I can act on</a>

+           </span>

+       </div>

        <div class="ml-auto">

            <span class="btn-group btn-group-sm issues-tagbar" role="group">

-               <a data-togglebutton="pr-status-open" href="#" id="toggle-open"

-                 class="btn btn-primary btn-sm">Open</a>

-               <a data-togglebutton="pr-status-merged" href="#" id="toggle-merged"

-                 class="btn btn-outline-primary btn-sm">Merged</a>

-               <a data-togglebutton="pr-status-closed" href="#" id="toggle-closed"

-                 class="btn btn-outline-primary btn-sm">Cancelled</a>

-               <a data-togglebutton="pr-status-all" href="#"

-                 class="btn btn-outline-primary btn-sm">All</a>

+               <a data-togglebutton="pr-status-open" href="?type={{ pr_type }}&status=open" id="toggle-open"

+                 class="btn {{ 'btn-primary' if pr_status == 'open' else 'btn-outline-primary' }} btn-sm">Open</a>

+               <a data-togglebutton="pr-status-merged" href="?type={{ pr_type }}&status=merged" id="toggle-merged"

+                 class="btn {{ 'btn-primary' if pr_status == 'merged' else 'btn-outline-primary' }} btn-sm">Merged</a>

+               <a data-togglebutton="pr-status-closed" href="?type={{ pr_type }}&status=cancelled" id="toggle-closed"

+                 class="btn {{ 'btn-primary' if pr_status == 'cancelled' else 'btn-outline-primary' }} btn-sm">Cancelled</a>

+               <a data-togglebutton="pr-status-all" href="?type={{ pr_type }}&status=all"

+                 class="btn {{ 'btn-primary' if pr_status == 'all' else 'btn-outline-primary' }} btn-sm">All</a>

            </span>

        </div>

      </div>

  

      <div class="d-flex mt-4 mb-2 align-items-center">

+         {% if pr_type == "filed" %}

          <h5 class="font-weight-bold mb-0">Pull Requests Created</h5>

+         {% else %}

+         <h5 class="font-weight-bold mb-0">Pull Requests {{username}} can act on</h5>

+         {% endif %}

          <span class="ml-auto btn btn-outline-secondary border-0 o-100 disabled font-weight-bold">

            <span id="opened_pr_count"></span> PRs

          </span>

      </div>

  

-     {% for request in requests|selectattr("user.username", "equalto", username) %}

-       {% if request.status|lower != "open" %}

-         {% set hidden = "hidden "%}

-       {% else %}

-         {% set hidden = "" %}

-       {% endif %}

-     {% set htmlclass = hidden+"pr-created pr-status pr-status-"+request.status|lower%}

+     {% for request in requests %}

+     {% set htmlclass = "pr-created pr-status pr-status-"+request.status|lower%}

        {{render_pullrequest_row(request, request.project, username, class=htmlclass, showproject=True)}}

      {% endfor %}

  

+     {% if total_pages > 1 %}

+     {{ pagination_link('page', page, total_pages) }}

+     {% endif %}

  

-     <div class="d-flex mt-4 mb-2 align-items-center">

-         <h5 class="font-weight-bold mb-0">Pull Requests {{username}} can act on</h5>

-         <span class="ml-auto btn btn-outline-secondary border-0 o-100 disabled font-weight-bold">

-           <span id="assigned_pr_count"></span> PRs

-         </span>

-     </div>

- 

-     {% for request in requests|rejectattr("user.username", "equalto", username) %}

-       {% if request.status|lower != "open" %}

-         {% set hidden = "hidden "%}

-       {% else %}

-         {% set hidden = "" %}

-       {% endif %}

-     {% set htmlclass = hidden+"pr-assigned pr-status pr-status-"+request.status|lower%}

-       {{render_pullrequest_row(request, request.project, username, class=htmlclass, showproject=True)}}

-     {% endfor %}

    </div>

  </div>

  
@@ -69,31 +64,6 @@ 

  <script type="text/javascript" nonce="{{ g.nonce }}" src="{{

    url_for('static', filename='tags.js') }}?version={{ g.version}}"></script>

  <script type="text/javascript" nonce="{{ g.nonce }}">

-   count_issues(status='.pr-status-open');

-   $(function(){

-     $('.issues-tagbar .btn').click(function(){

-       var current_btn = $(this).attr("data-togglebutton");

-       count_issues(status='.'+current_btn);

-       $('.issues-tagbar .btn-primary').addClass("btn-outline-primary");

-       $('.issues-tagbar .btn-primary').removeClass("btn-primary");

-       $(this).removeClass("btn-outline-primary");

-       $(this).addClass("btn-primary");

-       if (current_btn == "pr-status-all"){

-         count_issues(status='');

-         $(".pr-status").show();

-       } else {

-         $(".pr-status").hide();

-         $("."+$(this).attr("data-togglebutton")).show();

-       }

-       showNoResultMessage();

-     });

-   });

- 

-   function count_issues(status='.pr-status-open') {

-     var assigned_pr_count = $(status + '.pr-assigned').length;

-     var opened_pr_count = $(status + '.pr-created').length;

-     $('#assigned_pr_count').text(assigned_pr_count);

-     $('#opened_pr_count').text(opened_pr_count);

-   }

+   $('#opened_pr_count').text($('.request-row').length);

  </script>

  {% endblock %}

file modified
+54 -1
@@ -898,9 +898,59 @@ 

      """

      user = _get_user(username=username)

  

+     pr_type = flask.request.args.get("type", "filed").lower()

+     if pr_type not in ["filed", "actionable"]:

+         flask.flash("Invalid list of PR selected", "error")

+         pr_type = "filed"

+ 

+     pr_status = flask.request.args.get("status", "open").lower()

+     if pr_status not in ["open", "merged", "cancelled", "all"]:

+         flask.flash("Invalid PR status provided", "error")

+         pr_status = "open"

+ 

+     page = flask.request.args.get("page", 1)

+     try:

+         page = int(page)

+         if page < 1:

+             page = 1

+     except ValueError:

+         page = 1

+ 

+     limit = pagure_config["ITEM_PER_PAGE"]

+     start = limit * (page - 1)

+ 

+     filed = actionable = None

+     if pr_type == "filed":

+         filed = user.user

+     else:

+         actionable = user.user

+ 

+     status = None

+     if pr_status == "open":

+         status = "Open"

+     elif pr_status == "merged":

+         status = "Merged"

+     elif pr_status == "cancelled":

+         status = "Closed"

+ 

      requests = pagure.lib.query.get_pull_request_of_user(

-         flask.g.session, username=username

+         flask.g.session,

+         username=username,

+         filed=filed,

+         actionable=actionable,

+         status=status,

+         offset=start,

+         limit=limit,

+     )

+     requests_length = pagure.lib.query.get_pull_request_of_user(

+         flask.g.session,

+         username=username,

+         filed=filed,

+         actionable=actionable,

+         status=status,

+         count=True,

      )

+     total_pages = int(ceil(requests_length / float(limit)))

  

      userprofile_common = get_userprofile_common(user)

  
@@ -910,6 +960,9 @@ 

          user=user,

          requests=requests,

          select="requests",

+         pr_type=pr_type,

+         pr_status=pr_status,

+         total_pages=total_pages,

          repos_length=userprofile_common["repos_length"],

          forks_length=userprofile_common["forks_length"],

      )

@@ -1544,12 +1544,19 @@ 

          self.assertEqual(req.title, "test pull-request #2")

  

          # Check pingou's PR list

-         output = self.app.get("/user/pingou/requests")

+         output = self.app.get("/user/pingou/requests?type=filed")

          self.assertEqual(output.status_code, 200)

          output_text = output.get_data(as_text=True)

          self.assertIn("test pull-request #1", output_text)

+         self.assertNotIn("test pull-request #2", output_text)

+         self.assertEqual(output_text.count('pr-status pr-status-open"'), 1)

+ 

+         output = self.app.get("/user/pingou/requests?type=actionable")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertNotIn("test pull-request #1", output_text)

          self.assertIn("test pull-request #2", output_text)

-         self.assertEqual(output_text.count('pr-status pr-status-open"'), 2)

+         self.assertEqual(output_text.count('pr-status pr-status-open"'), 1)

  

          # Check foo's PR list

          output = self.app.get("/user/foo/requests")