{% extends 'tom_common/base.html' %}
{% load bootstrap4 static cache %}
{% block title %} Data Product List {% endblock %}
{% block additional_css %}
<link rel="stylesheet" href="{% static 'tom_observations/css/main.css' %}">
{% endblock %}
{% block content %}
{% include 'tom_dataproducts/partials/js9_scripts.html' %}
<div class="row">
  <div class="col-md-10">
    <div class="row">
      <div class="col-md-12">
        {% bootstrap_pagination page_obj extra=request.GET.urlencode %}
      </div>
    </div>
    <table class="table">
      <thead>
        <tr>
          <th>File</th>
          <th>Target</th>
          <th>Observation</th>
          <th>Groups</th>
          <th>Type</th>
          <th>Thumbnail</th>
        </tr>
      </thead>
      <tbody>
        {% for product in object_list %}
        <tr>
          <td><a href="{{ product.data.url }}">{{ product.get_file_name|truncatechars:40 }}</a></th>
          <td><a href="{% url 'tom_targets:detail' product.target.id %}">{{ product.target.name|truncatechars:40 }}</a></td>
          {% if product.observation_record.id %}
          <td><a href="{% url 'tom_observations:detail' product.observation_record.id %}">{{ product.observation_record|truncatechars:40 }}</a></td>
          {% else %}
          <td></td>
          {% endif %}
          <td>
            {% for group in product.group.all %}
            <a href="{% url 'tom_dataproducts:group-detail' group.id %}">{{ group.name|truncatechars:40 }}</a>
            {% endfor %}
          </td>
          <td>
            {% if product.data_product_type %}
              {{ product.get_type_display }}
            {% endif %}
          </a></td>
          {% if product.get_file_extension == '.fz' or product.get_file_extension == '.fits' %}
          <td>
            {% if product.get_preview %}
            {% cache None thumbnail product.id %}
            <img src="{{ product.get_preview }}" class="thumbnail"><br/>
            {% endcache %}
            {% include 'tom_dataproducts/partials/js9_button.html' with url=product.data.url only %}
            {% else %}
            <img src="{% static 'tom_dataproducts/img/placeholder.png' %}" class="thumbnail"><br/>
            {% endif %}
          </td>
          {% else %}
          <td></td>
          {% endif %}
        </tr>
        {% empty %}
        <tr>
          <td colspan="7">
            No data yet. You might want to save some data products from your
            <a href="{% url 'tom_observations:list' %}">completed observations</a>.
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% bootstrap_pagination page_obj extra=request.GET.urlencode %}
  </div>
  <div class="col-md-2">
    <form action="" method="get" class="form">
      {% bootstrap_form filter.form %}
      {% buttons %}
        <button type="submit" class="btn btn-primary">
          Filter
        </button>
        <a href="{% url 'tom_dataproducts:list' %}" class="btn btn-secondary" title="Reset">Reset</a>
      {% endbuttons %}
    </form>
    <h5>Data Groups</h5>
    {% for group in product_groups %}
    <p>
      <a href="{% url 'tom_dataproducts:group-detail' group.id %}">{{ group.name }}</a><br/>
      <span class="text-muted">Products: {{ group.dataproduct_set.count }}</span>
    </p>
    {% endfor %}
    <a href="{% url 'tom_dataproducts:group-list' %}">Manage groups</a>
  </div>
</div>
{% endblock %}
