{% extends 'layout.html' %}
{% import '_macros.html' as macros %}
{% block content %}
<div class="ui grid">
  <div class="fourteen wide column">
    <div class="ui fluid icon input">
      <input id="main-table-search" autofocus="autofocus" type="text" placeholder="Type here to filter...">
      <i class="search icon"></i>
    </div>
  </div>
  <div class="two wide column">
    <div class="ui fluid icon dropdown large basic button">
      <input name="status" type="hidden" value="Failed">
      <i class="filter icon"></i>
      <span class="text">Filter By Status</span>
      <i class="dropdown icon"></i>
      <div class="menu">
        <a class="item" href="{{url_for_field('status', 'failed')}}">Failed</a>
        <a class="item" href="{{url_for_field('status', 'changed')}}">Changed</a>
        <a class="item" href="{{url_for_field('status', 'unchanged')}}">Unchanged</a>
        <a class="item" href="{{url_for_field('status', 'noop')}}">Noop</a>
        <a class="item" href="{{url_for_field('status', 'unreported')}}">Unreported</a>
      </div>
    </div>
  </div>
</div>
<table
  id="main-table"
  class='ui very basic very compact table'
  data-auto-width="false"
  data-paging="false"
  data-info="false"
  data-dom="t"
  data-order='[[ 2, "desc" ]]'
>
  <thead>
    <tr>
      <th>Status</th>
      <th>Certname</th>
      <th>Catalog</th>
      <th>Report</th>
      <th class="collapsing" data-orderable="false"></th>
    </tr>
  </thead>
  <tbody>
    {% for node in nodes %}
    <tr>
      <td data-order="{{ node.status }}">
        {% if node.latest_report_hash %}
          {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env, report_hash=node.latest_report_hash)}}
        {% else %}
          {{macros.status_counts(status=node.status, node_name=node.name, events=node.events, unreported_time=node.unreported_time, current_env=current_env)}}
        {% endif %}
      </td>
      <td><a href="{{url_for('node', env=current_env, node_name=node.name)}}">{{node.name}}</a></td>
      <td data-order="{{ node.catalog_timestamp | default('', true) }}">
        {% if node.catalog_timestamp %}
          <a href="{{url_for('catalog_node', env=current_env, node_name=node.name)}}" data-localise="{{ config.LOCALISE_TIMESTAMP|lower }}">{{node.catalog_timestamp}}</a>
        {% else %}
          <i class="large darkblue ban icon"></i>
        {% endif %}
      </td>
      <td data-order="{{ node.report_timestamp | default('', true) }}">
        {% if node.report_timestamp %}
          <a href="{{url_for('report', env=current_env, node_name=node.name, report_id=node.latest_report_hash)}}"  data-localise="{{ config.LOCALISE_TIMESTAMP|lower }}">{{ node.report_timestamp }}</a>
        {% else %}
          <i class="large darkblue ban icon"></i>
        {% endif %}
      </td>
      <td>
        {% if node.report_timestamp %}
        <a title='Reports' href="{{url_for('reports', env=current_env, node_name=node.name)}}"><i class='large darkblue book icon'></i></a>
        {% endif %}
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock content %}
