{% extends "aggregator/base.html" %}

{% load pagination_tags %}

{% block content %}

<div class="page-header">
  <h1>Layer details for: {{ layer.title }}</h1>
</div>

{% if user.is_superuser %}
  {% include "aggregator/publish.html" with csw_resourcetype=layer.csw_resourcetype csw_source=layer.url publish_type='Layer' csw_xml=layer.xml %}
{% endif %}

<div class="row">
  <div class="col-md-6">
    {% if user.is_superuser %}
    <ul>
      <button type="button" class="btn btn-success btn-circle btn nohover" data-toggle="modal" data-target="#publish-modal">Publish</button>
    </ul>
    {% endif %}
    <ul>
      {% if layer.service %}
      <li><a href="{% url 'service_detail' layer.catalog.slug layer.service.id %}">Go to service page</a></li>
      {% endif %}
      <li><a href="map/demo/">Go to demo page</a></li>
    </ul>
</div>
  <div class="col-md-6">
    {% if user.is_superuser %}
    Administrative actions:
    <form action="{{ layer.get_absolute_url }}" method="post">
      {% csrf_token %}
      <input type="submit" name="check" value="Check now">
      <input type="submit" name="remove" value="Remove checks">
      <input type="submit" name="index" value="Index in Search Backend">
    </form>
    {% endif %}
  </div>
</div>

<div class="layer-thumb">
  <img src="{{ MEDIA_URL }}{{ layer.thumbnail }}" width="50" />
</div>

<div class="row">
  <div class="col-md-12">
    <table class="table">
      <tbody>
        <tr>
          <td><strong>Endpoints</strong></td>
          <td>
            <ul>
            {% if layer.service %}
            <li>Service Hypermap Page: <a href="{% url 'service_detail' layer.catalog.slug layer.service.id %}">{{ layer.service.title }}</a></li>
            {% endif %}
            <li>Layer Page: <a href="{{ layer.page_url }}">{{ layer.page_url|truncatechars:80 }}</a></li>
            <li>Layer Hypermap EndPoint: <a href="{{ layer.get_url_endpoint }}">{{ layer.get_url_endpoint|truncatechars:80 }}</a></li>
            {% if user.is_superuser %}
              <li>Service EndPoint: <a href="{{ layer.service.url }}">{{ layer.service.url|truncatechars:80 }}</a></li>
              <li>Layer EndPoint: <a href="{{ layer.url }}">{{ layer.url|truncatechars:80 }}</a></li>
              <li>Search EndPoint:
              {% if SEARCH_TYPE == 'elasticsearch' %}
              <a href="{{SEARCH_URL}}/hypermap/_search?q=layer_id:{{layer.id}}" target="new">{{SEARCH_URL}}/hypermap/_search?q=layer_id:{{layer.id}}</a>
              {% elif SEARCH_TYPE == 'solr' %}
              <a href="{{SEARCH_URL}}/select?q=layer_id:{{layer.id}}&wt=json&indent=true" target="new">{{SEARCH_URL}}/select?q=layer_id:{{layer.id}}&wt=json&indent=true</a>
              {% endif %}
              <li>Metadata:
                  <a href="{{SITE_URL}}{% url 'csw_global_dispatch_by_catalog' catalog_slug %}?service=CSW&version=2.0.2&request=GetRecordById&id={{layer.id}}" target="new">
                    {{SITE_URL}}{% url 'csw_global_dispatch_by_catalog' catalog_slug %}?service=CSW&version=2.0.2&request=GetRecordById&id={{layer.id}}
                  </a>
              </li>
              </li>
            {% endif %}
          </ul>
          </td>
        </tr>
        <tr>
          <td><strong>Name</strong></td>
          <td>{{ layer.name }}</td>
        </tr>
        <tr>
          <td><strong>Title</strong></td>
          <td>{{ layer.title }}</td>
        </tr>
        <tr>
          <td><strong>Abstract</strong></td>
          <td>{{ layer.abstract }}</td>
        </tr>
        <tr>
          <td><strong>Keywords</strong></td>
          <td>
            <ul>
              {% for keyword in layer.keywords.all %}
              <li>{{ keyword.name }}</li>
              {% endfor %}
          </ul>
          </td>
        </tr>
        <tr>
          <td><strong>Is Public?</strong></td>
          <td>{{ layer.is_public }}</td>
        </tr>
        <tr>
          <td><strong>Is Monitored?</strong></td>
          <td>{{ layer.is_monitored }}</td>
        </tr>
        {% if layer.type = 'Hypermap:WorldMap' %}
          <tr>
            <td><strong>Username</strong></td>
            <td>{{ layer.layerwm.username }}</td>
          </tr>
          <tr>
            <td><strong>Category</strong></td>
            <td>{{ layer.layerwm.category }}</td>
          </tr>
        {% endif %}
        <tr>
        <td><strong>Dates</strong></td>
        <td>
          {% if layer.layerdate_set.count > 0 %}
          <ul>
            {% if layer.type = 'Hypermap:WorldMap' %}
              <li>Start Date: {{ layer.layerwm.temporal_extent_start }}</li>
              <li>End Date: {{ layer.layerwm.temporal_extent_end }}</li>
            {% endif %}
            {% for date in layer.layerdate_set.all %}
              {% if date.type == 0 %}
                 <li>{{ date.date }} Detected</li>
              {% else %}
                 <li>{{ date.date }} From Metadata</li>
              {% endif %}
            {% endfor %}
          </ul>
          {% else %}
            No dates for this layer
          {% endif %}
        </td>
      </tr>
        <tr>
          <td><strong>Spatial Reference Systems</strong></td>
          <td>
            <ul>
              {% for srs in layer.service.srs.all %}
              <li>{{ srs.code }}</li>
              {% endfor %}
          </ul>
          </td>
        </tr>
        <tr>
          <td><strong>Bounding Box (x0, y0, x1, y1)</strong></td>
          <td>{{ layer.bbox_x0|floatformat:8 }}, {{ layer.bbox_y0|floatformat:8 }}, {{ layer.bbox_x1|floatformat:8 }}, {{ layer.bbox_y1|floatformat:8 }}</td>
        </tr>
        <tr>
          <td><strong>Monitoring Period</strong></td>
          <td>
            {% if layer.checks_count > 0 %}
            <ul>
              <li>First Check: {{ layer.first_check }}</li>
              <li>Last Check: {{ layer.last_check }}</li>
              <li>Total Checks: {{ layer.checks_count }}</li>
              <li>Reliability: {{ layer.reliability }}</li>
              <li><a href="{{ layer.get_absolute_url }}">See full check stats</a></li>
            </ul>
            {% else %}
              No checks performed so far
            {% endif %}
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</div>

<div class="clearfix"></div>
<div id="run-chart" class="run-chart"></div>

{% endblock %}
