{% extends "repo_master.html" %}

{% from "_render_repo.html" import pagination_link %}

{% block title %}Issues - {{
    repo.namespace + '/' if repo.namespace }}{{ repo.name }}{% endblock %}
{% set tag = "home"%}


{% block repo %}


  <h2>
    {% if status|lower in ['open', 'true'] %}
      {{ issues|count }} Open Issues (of {{ issues_cnt }})
    {% elif status|lower not in ['open', 'true', 'all', 'none'] %}
      {{ issues|count }} Closed Issues (of {{ issues_cnt }})
    {% else %}
      {{ issues|count }} Issues
    {% endif %}
    <span class="btn-group btn-group-sm pull-xs-right" role="group">
    {% if repo.milestones %}
      <a href="{{ url_for(
          'view_roadmap',
          repo=repo.name,
          username=username,
          namespace=repo.namespace) }}">
        <button class="btn btn-secondary btn-sm">Roadmap</button>
      </a>
    {% endif %}
    {% if g.repo.reports %}
    <div class="dropdown" id="PR-dropdown">
      <button class="btn btn-primary btn-sm dropdown-toggle"
        type="button" id="dropdownMenu1" data-toggle="dropdown"
        aria-haspopup="true" aria-expanded="false">
        Report
      </button>
      <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenu1">
        {% for report in repo.reports %}
        <a class="dropdown-item" href="{{ url_for(
            'view_report', namespace=repo.namespace,
            username=username, repo=repo.name, report=report) }}">
          <small>Report: {{ report }}</small>
        </a>
        {% endfor %}
      </div>
    </div>
    {% endif %}
    </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">
      <a class="btn {%
        if status|lower in ['open', 'true'] %}btn-primary{%
        else %}btn-secondary{%
        endif %} btn-sm" href="{{ url_for('view_issues',
          repo=repo.name,
          username=username,
          namespace=repo.namespace,
          tags=tags, author=author,
          assignee=assignee) }}">Open</a>
      <a class="btn {%
        if status|lower in ['closed', 'false'] %}btn-primary{%
        else %}btn-secondary{%
        endif %} btn-sm" href="{{ url_for('view_issues',
          repo=repo.name,
          username=username,
          namespace=repo.namespace,
          tags=tags, author=author, status='Closed',
          assignee=assignee) }}">Closed</a>
      <a class="btn {%
        if status|lower in ['all', 'none'] %}btn-primary{%
        else %}btn-secondary{%
        endif %} btn-sm" href="{{ url_for('view_issues',
          repo=repo.name,
          username=username,
          namespace=repo.namespace,
          tags=tags, author=author, status='all',
          assignee=assignee) }}">All</a>
  </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',
                repo=repo.name,
                username=username,
                namespace=repo.namespace,
                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',
                repo=repo.name,
                username=username,
                namespace=repo.namespace) }}"
                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',
                repo=repo.name,
                username=username,
                namespace=repo.namespace,
                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',
              repo=repo.name,
              username=username,
              namespace=repo.namespace,
              tags=tags, author=author, assignee=assignee,
              status=status) }}">reset</a>)
            </th>
            <th class="open_by">
              Reporter&nbsp;(<a href="{{ url_for('view_issues',
              repo=repo.name,
              username=username,
              namespace=repo.namespace,
              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',
              repo=repo.name,
              username=username,
              namespace=repo.namespace,
              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 != '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',
                  repo=repo.name,
                  username=username,
                  namespace=repo.namespace,
                  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',
                    repo=repo.name,
                    username=username,
                    namespace=repo.namespace,
                    author=author, tags=tags, assignee=assignee,
                    status=status, priority=issue.priority) }}"
                    title="Filter issues by priority">{{
                  repo.priorities[issue.priority | string] }}
                </a>
              {% endif %}
            </td>
            <td class="nowrap">
                <a href="{{ url_for('view_issues',
                    repo=repo.name,
                    username=username,
                    namespace=repo.namespace,
                    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>
            <td class="nowrap">
            {% if not status or status|lower == 'open' %}
              {% if issue.assignee %}
                <a href="{{ url_for('view_issues',
                  repo=repo.name,
                  username=username,
                  namespace=repo.namespace,
                  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',
                  repo=repo.name,
                  username=username,
                  namespace=repo.namespace,
                  tags=tags, author=author, status=status,
                  assignee=0) }}">unassigned
                </a>
              {% endif %}
            {% endif %}
            </td>
        </tr>
    {% else %}
        <tr>
            <td colspan="5" class="noresult">No issues found</td>
        </tr>
    {% endfor %}
    </tbody>
</table>
</div>
<button type="button" class="btn btn-secondary btn-sm pull-xs-right"
  data-toggle="modal" data-target="#report_modal">
  Save report
</button>
<div class="modal fade" id="report_modal" tabindex="-1"
      role="dialog" aria-labelledby="New report" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
          <span class="sr-only">Close</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">New Report</h4>
      </div>
      <div class="modal-body">
        <form action="{{ url_for(
            '.save_reports', namespace=repo.namespace,
            username=username, repo=repo.name) }}" method="post" class="icon">
          <fieldset class="form-group">
            <label for="report_name">Report name</label>
            <input class="form-control" name="report_name" required/>
            <small class="text-muted">name of the report</small>
          </fieldset>
          {{ add_report_form.csrf_token }}
          <button class="btn btn-primary" type="submit" title="Save this report">
            Save
          </button>
        </form>
      </div>
    </div>
  </div>
</div>

{{ pagination_link('page', g.page, total_page) }}

{% 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 %}
