{% extends "master.html" %}

{% block title %}Flags · Anitya{% endblock %}

{%block header %}
{% if refresh %}
<meta http-equiv="refresh" content="5" >
{% endif %}
{% endblock %}


{% block body %}

<div class="page-header">
  <h1>Flags</h1>
  {% if refresh %}
  <p>This page should refresh automatically every 5 seconds</p>
  <a href="{{ url_for('anitya_ui.browse_flags', page=page) }}">
    <button type="submit" class="btn btn-danger" id="checknow">
      <span class="glyphicon glyphicon-remove-sign"></span>
      Remove auto-refresh
    </button>
  </a>
  {% else %}
  <a href="{{ url_for('anitya_ui.browse_flags', page=page, refresh=True) }}">
    <button type="submit" class="btn btn-success" id="checknow">
      <span class="glyphicon glyphicon-refresh"></span>
      Activate auto-refresh
    </button>
  </a>
  {% endif %}
</div>

<div class="row show-grid">
  <div class="col-sm-4">
    {% if total_page > 1 %}
    <ul class="pagination pagination-sm">
        <li>
            {% if page > 1%}
              <a href="{{ url_for('anitya_ui.browse_flags', page=page-1, project=project,
                user=flags_for_user, from_date=from_date) }}">
                «
              </a>
            {% else %}
              <a> « </a>
            {% endif %}
        </li>
        <li>
            <a> {{ page }} / {{ total_page }} </a>
        </li>
        <li>
            {% if page < total_page %}
              <a href="{{ url_for('anitya_ui.browse_flags', page=page+1, project=project,
                user=flags_for_user, from_date=from_date) }}">
                »
              </a>
            {% else %}
              <a> » </a>
            {% endif %}
        </li>
    </ul>
    {% endif %}
  </div>

  <div class="col-xs-10">
    <form action="{{url_for('anitya_ui.browse_flags') }}" class="form-inline"
          role="form" action="GET" id="flags_form">
      <div class="form-group col-xs-6 col-sm-2">
        <select name="state" class="form-control">
            <option value="open" {% if state== 'open' %}selected="selected"{% endif %}>open</option>
            <option value="closed" {% if state== 'closed' %}selected="selected"{% endif %}>closed</option>
            <option value="" {% if state== '' %}selected="selected"{% endif %}>all</option>
        </select>
      </div>
      <div class="form-group col-xs-6 col-sm-3">
        <input type="text" name="project" placeholder="Project name"
            class="form-control" value="{{ project }}"/>
      </div>
      <div class="form-group col-xs-6 col-sm-4">
        <input type="text" name="user" placeholder="User identifier"
            class="form-control" value="{{ flags_for_user }}"/>
      </div>
      <div class="form-group col-xs-6 col-sm-2">
        <div class='input-group date' id='datetimepicker'>
            <input type='text' class="form-control col-sm-6" name="from_date"
                id="from_date" placeholder="From Date"
                value="{{ from_date }}"
                data-date-format="YYYY-MM-DD"/>
            <span class="input-group-addon">
                <span class="glyphicon glyphicon-calendar"></span>
            </span>
        </div>
      </div>
      <div class="form-group col-xs-6 col-sm-1">
        <button type="submit" class="btn btn-default" class="form-control">
          Filter
        </button>
      </div>
    </form>
  </div>

</div>


<table id="flag_list">
<tr><th></th><th>State</th><th>Created</th><th>Project</th><th>User</th><th>Reason</th></tr>
{% for flag in flags %}
    <tr>
        <td>
          {% if flag.state == 'open' %}
          <form method="POST" action="{{ url_for('anitya_ui.set_flag_state', flag_id=flag.id, state='closed') }}">
            <button type="submit" class="btn btn-warning btn-sm pull-right inline"
                  id="flag_btn">
              <span class="glyphicon glyphicon-eye-close"></span>
              Close
            </button>
          {% else %}
          <form method="POST" action="{{ url_for('anitya_ui.set_flag_state', flag_id=flag.id, state='open') }}">
            <button type="submit" class="btn btn-success btn-sm pull-right inline"
                  id="flag_btn">
              <span class="glyphicon glyphicon-eye-open"></span>
              Open
            </button>
          {% endif %}
          {{ form.csrf_token }}
          </form>

        </td>
        <td> {{ flag.state }} </td>
        <td>
            {{ flag.created_on.strftime('%Y-%m-%d %H:%M:%S') }}
        </td>
        <td>
          {% if flag.project -%}
          <a href="{{ url_for('anitya_ui.project', project_id=flag.project.id) }}">{{ flag.project.name }}</a>
          {%- endif %}
        </td>
        <td> {{ flag.user }} </td>
        <td> {{ flag.reason }} </td>
    </tr>
{% endfor %}
</table>

{% endblock %}

{% block jscript %}
{{ super() }}
<script type="text/javascript">
    $(function () {
        $('#datetimepicker').datetimepicker({
            pickTime: false
        });
    });
</script>
{% endblock %}
