{% extends "master.html" %}
{% from "_formhelper.html" import render_field_in_row %}
{% from "_browseheader.html" import browse_header %}

{% block title %}Pull-requests of {{ username }}{% endblock %}
{% set tag = "users"%}


{% block content %}
<div class="repo-header p-t-1">
  <div class="container">
    {{browse_header(select=tag)}}
  </div>
</div>
<div class="p-t-2">
  <div class="container">
    <h3 class="p-b-2">
        Pull Requests opened by {{ username | avatar(20) | safe }} {{ username }}
    </h3>
    <div>
      <span class="btn-group btn-group-sm issues-tagbar" role="group">
          <a data-togglebutton="pr-status-open" id="toggle-open" class="btn btn-primary btn-sm" href="#">Open</a>
          <a data-togglebutton="pr-status-merged" id="toggle-merged" class="btn btn-secondary btn-sm" href="#">Merged</a>
          <a data-togglebutton="pr-status-closed" id="toggle-closed" class="btn btn-secondary btn-sm" href="#">Closed</a>
          <a data-togglebutton="pr-status-all" class="btn btn-secondary btn-sm" href="#">All</a>
      </span>
    </div>
    <table class="table table-hover table-striped m-b-0 m-t-1">
        <thead class="thead-default">
            <tr>
                <th class="nowrap">#</th>
                <th>Status</th>
                <th>Title</th>
                <th class="open_date nowrap">Opened</th>
                <th class="nowrap">Project</th>
                <th class="assigned nowrap">Assigned to</th>
            </tr>
        </thead>
        <tfoot>
        </tfoot>
        <tbody>
        {% for request in requests %}
            <tr class="pr-status pr-status-{{request.status|lower}}"
              {%if request.status|lower != "open" %}style="display:none;"{% endif %}>
                <td class="nowrap"><span class="label label-default">PR#{{ request.id }}</span></td>
                <td><span class="label {%
                    if request.status|lower == 'merged' %}label-success{%
                    elif request.status|lower == 'closed' %}label-danger{%
                    elif request.status|lower == 'open'%}label-primary{%
                    endif%}">{{request.status}}</span></td>
                <td class="stretch-table-column">
                  <a href="{{ url_for('request_pull', username=request.project.username if request.project.is_fork else None,
                      repo=request.project.name, requestid=request.id) }}">
                    {{ request.title | noJS("img") | safe }}
                  </a>
                </td>
                <td class="nowrap">
                    <span title="{{request.date_created.strftime('%Y-%m-%d %H:%M:%S')}}">{{
                        request.date_created | humanize}}</span>
                </td>
                <td class="nowrap">
                  <a href="{{ url_for(
                    'view_repo',
                    username=request.project.username if request.project.is_fork else None,
                    repo=request.project.name)}}">
                    {{ request.project.username + '/' if request.project.is_fork }}
                    {{ request.project.name }}
                  </a>
                </td>
                <td class="nowrap">
                  {% if request.assignee %}
                  {{ request.assignee.default_email | avatar(16) | safe }}
                  {{ request.assignee.user }}
                  {% else %}
                  <span class="text-muted">unassigned</span>
                  {% endif %}
                </td>
            </tr>
        {% else %}
            <tr>
                <td colspan="5" class="noresult">No pull-request found</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
  </div>
</div>

{% endblock %}

{% block jscripts %}
    {{ super() }}
    <script type="text/javascript">
      $(function(){
        $('.issues-tagbar .btn').click(function(){
          $('.issues-tagbar .btn-primary').addClass("btn-secondary");
          $('.issues-tagbar .btn-primary').removeClass("btn-primary");
          $(this).removeClass("btn-secondary");
          $(this).addClass("btn-primary");
          if ($(this).attr("data-togglebutton") == "pr-status-all"){
            $(".pr-status").show();
          } else {
            $(".pr-status").hide();
            $("."+$(this).attr("data-togglebutton")).show();
          }
        });
      });
    </script>
{% endblock %}
