{% extends "repo_master.html" %}

{% block title %}Issues - {{ repo.name }}{% endblock %}
{% set tag = "home"%}


{% block repo %}


  <h2>
    {% if status and status != 'Open' %}
      {{ issues|count }} Closed Issues
    {% else %}
      {{ issues|count }} Open Issues
    {% endif %}
    <span class="btn-group btn-group-sm pull-xs-right" role="group">
    {% if repo.milestones %}
      <a href="{{ url_for(
          'view_roadmap', username=username, repo=repo.name) }}"
         class="btn btn-secondary btn-sm">
        Roadmap
      </a>
    {% endif %}
      <a href="{{ url_for('new_issue', username=username, repo=repo.name) }}"
         class="btn btn-success btn-sm">
        New Issue
      </a>
    </span>
  </h2>
    {% if oth_issues %}
    <div class="addrem_bar issues_pbar m-b-1">
      {% if (issues | length + oth_issues) %}
        <span style="width: {{ (100.0 * (1 - issues | length / (issues | length + oth_issues)))|round|int }}%">
            {{ (100.0 * (1 - issues | length / (issues | length + oth_issues)))|round|int }}%
        </span>
      {% endif %}
    </div>
    {% endif %}

<section id="tags">
  <span class="btn-group btn-group-sm issues-tagbar" role="group" aria-label="Basic example">
    {% if status and status != 'Open' %}
      <a class="btn btn-secondary btn-sm" href="{{ url_for('view_issues', username=username,
                 repo=repo.name, tags=tags, author=author, assignee=assignee) }}">Open</a>
      <a class="btn btn-primary btn-sm" href="{{ url_for('view_issues', username=username,
                 repo=repo.name, status='Closed', tags=tags, author=author,
                 assignee=assignee) }}">Closed</a>
    {% else %}
      <a class="btn btn-primary btn-sm" href="{{ url_for('view_issues', username=username,
                 repo=repo.name, tags=tags, author=author, assignee=assignee) }}">Open</a>
      <a class="btn btn-secondary btn-sm" href="{{ url_for('view_issues', username=username,
                 repo=repo.name, status='Closed', tags=tags, author=author,
                 assignee=assignee) }}">Closed</a>
    {% endif %}
  </span>
  <span class="oi m-l-2" data-glyph="tag"></span>
  <span class="btn-group btn-group-sm issues-tagbar" role="group" aria-label="Basic example">
    {% for tag in tag_list %}
      {% if tag.tag in tags %}
        {% if status and status != 'Open' %}
        <a class="btn btn-secondary btn-sm {% if tag.tag in tags%}active{% endif %}"
            href="{{ url_for('view_issues', username=username,
                 repo=repo.name, status='Closed') }}"
                   title="Filter issues by tag">
         {% else %}
        <a class="btn btn-secondary btn-sm {% if tag.tag in tags%}active{% endif %}"
            href="{{ url_for('view_issues', username=username,
                 repo=repo.name) }}"
                   title="Filter issues by tag">
         {% endif %}
      {% else %}
        <a class="btn btn-secondary btn-sm {% if tag.tag in tags%}active{%endif%}"
            href="{{ url_for('view_issues', username=username,
                   repo=repo.name, tags=tag.tag,
                   author=author, assignee=assignee, status=status) }}"
                   title="Filter issues by tag">
      {% endif %}

        {{ tag.tag }}</a>
    {% endfor %}
</span>
</section>
<div class="card m-t-1">
<table id="pagure-issues-list" class="table table-hover table-striped m-b-0">
    <thead class="thead-default">
        <tr>
            <th id="issue-title">Issue</th>
            <th class="open_date">Opened</th>
            {% if status and status|lower != 'open' %}
            <th class="close_date">Closed</th>
            {% endif %}
            <th class="priority" data-sort="int">
                Priority&nbsp;(<a href="{{ url_for('view_issues', username=username,
                repo=repo.name, tags=tags, author=author, assignee=assignee,
                status=status) }}">reset</a>)
            </th>
            <th class="open_by">
                Reporter&nbsp;(<a href="{{ url_for('view_issues', username=username,
                repo=repo.name, tags=tags, assignee=assignee, priority=priority,
                status=status) }}">reset</a>)
            </th>
            {% if not status or status|lower == 'open' %}
            <th class="assigned">
              Assignee&nbsp;(<a href="{{ url_for('view_issues', username=username,
                repo=repo.name, tags=tags, author=author, priority=priority,
                status=status) }}">reset</a>)
            </th>
            {% endif %}
        </tr>
    </thead>
    <tfoot>
    </tfoot>
    <tbody>
    {% for issue in issues %}
        <tr>
            <td>
              <span class="label label-default">#{{ issue.id }}</span>
              {% if status and status != 'Open' %}
              <span class="label {% if
                issue.status|lower == 'invalid' %}label-danger{%
                elif issue.status|lower == 'fixed' %}label-success{%
                elif issue.status|lower == 'insufficient data' %}label-warning{%
                elif issue.status|lower == 'duplicate' %}label-default{%
                endif %}">{{issue.status}}</span>
              {% endif %}
              {% if issue.private %}
              <span class="oi red-icon" data-glyph="lock-locked" title="Private issue"></span>
              {% endif %}
              <a href="{{ url_for('view_issue', username=username,
                         repo=repo.name, issueid=issue.id) }}">
                {{ issue.title | noJS("img") | safe }}
              </a>
               &nbsp;&nbsp;
              {% if issue.user_comments|count > 0 %}
              <span class="text-muted">
                <span class="oi" data-glyph="comment-square"
                    title="Comments on the ticket"></span>
                  {{issue.user_comments|count}}
            </span>
              {% endif %}
              {% for tag in issue.tags%}
                <span class="label label-info">{{tag.tag}}</span>
              {% endfor%}
            </td>
            <td class="td-open_date nowrap">
                <span title="{{issue.date_created.strftime('%Y-%m-%d %H:%M:%S')}}">{{
                        issue.date_created | humanize}}</span>
            </td>
            {% if status and status|lower != 'open' %}
            <td class="nowrap">
                {% if issue.closed_at != None %}
                <span title="{{issue.closed_at.strftime('%Y-%m-%d %H:%M:%S')}}">{{
                        issue.closed_at | humanize}}</span>
                {% endif %}
            </td>
            {% endif %}
            <td class="td-priority nowrap" data-sort-value="{{
              issue.priority
              if issue.priority
              else repo.priorities | increment_largest_priority | string }}">
              {% if issue.priority %}

                <a href="{{ url_for('view_issues', username=username,
                    repo=repo.name, author=author,
                    tags=tags, assignee=assignee, status=status,
                    priority=issue.priority) }}"
                    title="Filter issues by priority">{{
                  repo.priorities[issue.priority | string] }}
                </a>
              {% endif %}
            </td>
            {% if not status or status|lower == 'open' %}
            <td class="nowrap">
                <a href="{{ url_for('view_issues', username=username,
                    repo=repo.name, author=issue.user.user,
                    tags=tags, assignee=assignee, status=status) }}"
                    title="Filter issues by reporter">
                    {{ issue.user.default_email | avatar(16) | safe }}
                    {{ issue.user.user }}
                </a>
            </td>
            {% endif %}
            <td class="nowrap">
              {% if issue.assignee %}
              <a href="{{ url_for('view_issues', username=username,
                repo=repo.name, assignee=issue.assignee.username,
                tags=tags, author=author, status=status) }}"
                title="Filter issues by assignee">
                {{ issue.assignee.default_email | avatar(16) | safe }}
                {{ issue.assignee.user }}
              </a>
              {% else %}
              <a class="text-muted" href="{{ url_for('view_issues', username=username,
                repo=repo.name, tags=tags, author=author, status=status,
                assignee=0) }}">unassigned</a>
              {% endif %}
            </td>
        </tr>
    {% else %}
        <tr>
            <td colspan="5" class="noresult">No issues found</td>
        </tr>
    {% endfor %}
    </tbody>
</table>
</div>
{% endblock %}
{% block jscripts %}
{{ super() }}

<script type="text/javascript"
  src="{{ url_for('static', filename='stupidtable.min.js') }}">
</script>
<script>
$.ready(function() {
  $("#pagure-issues-list").stupidtable();
});
</script>
{% endblock %}
