{% extends 'nova/base.html' %}
{% load i18n parse_date sizeformat %}
{% block title %}Instance Overview{% endblock %}

{% block page_header %}
  {% include "horizon/common/_page_header.html" with title="Overview: "|add:"<small>This page shows your cloud usage.</small>" %}
{% endblock page_header %}

{% block dash_main %}

  {% if usage.instances %}
    <div id="usage">
      <div class="usage_block first">
        <h3>CPU</h3>
        <ul>
          <li><span class="quantity">{{ usage.total_active_vcpus|default:0 }}</span><span class="unit">Cores</span> Active</li>
          <li><span class="quantity">{{ usage.total_cpu_usage|floatformat|default:0 }}</span><span class="unit">CPU-HR</span> Used</li>
        </ul>
      </div>

      <div class="usage_block">
        <h3>RAM</h3>
        <ul>
          <li><span class="quantity">{{ total_ram|default:0 }}</span><span class="unit">{{ ram_unit }}</span> Active</li>
        </ul>
      </div>

      <div class="usage_block last">
        <h3>Disk</h3>
        <ul>
          <li><span class="quantity">{{ usage.total_active_disk_size|default:0 }}</span><span class="unit">GB</span> Active</li>
          <li><span class="quantity">{{ usage.total_disk_usage|floatformat|default:0 }}</span><span class="unit">GB-HR</span> Used</li>
        </ul>
      </div>
    </div>

    <div class='table_title wide'>
      <a class="csv_download_link pull-right" href="{{ csv_link }}">{% trans "Download CSV" %}</a>

      {% if show_terminated %}
        <a id="toggle_terminated" href="{{dash_url}}">{% trans "Hide Terminated" %}</a>
      {% else %}
        <a id="toggle_terminated" href="{{dash_url}}?show_terminated=True">{% trans "Show Terminated" %}</a>
      {% endif %}

      <h3>Server Usage Summary</h3>
    </div>

    <table class="zebra-striped">
      <tr id='headings'>
        <th>{% trans "Name" %}</th>
        <th>{% trans "User" %}</th>
        <th>{% trans "Size" %}</th>
        <th>{% trans "Uptime" %}</th>
        <th>{% trans "State" %}</th>
      </tr>
      <tbody class='main'>
        {% for instance in instances %}
          {% if instance.ended_at %}
            <tr class="terminated">
          {% else %}
            <tr class="{% cycle 'odd' 'even' %}">
          {% endif %}
            <td>{{ instance.name }}</td>
            <td>{{ instance.user_id }}</td>
            <td>{{ instance.ram_size|mbformat }} Ram | {{ instance.vcpus }} VCPU | {{ instance.disk_size }}GB Disk</td>
            <td>{{ instance.uptime_at|timesince }}</td>
            <td>{{ instance.state|lower|capfirst }}</td>
        </tr>
        {% empty %}
          <tr>
              <td colspan=9>{% trans "No active instances." %}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  {% else %}
    {% include 'nova/instances_and_volumes/instances/_no_instances.html' %}
  {% endif %}
{% endblock %}
