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

{% comment %}
 coding: utf-8

 maposmatic, the web front-end of the MapOSMatic city map generation system
 Copyright (C) 2012  David Decotigny
 Copyright (C) 2012  Frédéric Lehobey
 Copyright (C) 2012  Pierre Mauduit
 Copyright (C) 2012  David Mentré
 Copyright (C) 2012  Maxime Petazzoni
 Copyright (C) 2012  Thomas Petazzoni
 Copyright (C) 2012  Gaël Utard

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}
{% load i18n %}
{% load extratags %}

{% block body-class %}maps{% endblock %}
{% block menu-maps %}active{% endblock %}

{% block title %}{% trans "Maps" %}{% endblock %}

{% block page %}
{% with maps as data %}{% with form.cleaned_data.query as query %}{% include "maposmatic/pagination.html" %}{% endwith %}{% endwith %}
<h1>{% trans "Maps" %}</h1>
<br style="clear: both;" />

{% for map in maps.object_list %}
{% if forloop.counter0|divisibleby:2 %}<div class="row-fluid">{% endif %}
<div class="span6 map map-status-{{ map.status }}">
  <div class="info">
    {% if map.needs_waiting and map.current_position_in_queue %}
    <p class="queue-position">#{{ map.current_position_in_queue }}</p>
    {% endif %}
    <h2><a href="{% url map-by-id map.id %}">{{ map.maptitle }}</a></h2>

    <p class="details">
      {% if map.administrative_city %}
      {{ map.administrative_city }}
      {% else %}
      ({{ map.lat_upper_left|floatformat:3 }}, {{ map.lon_upper_left|floatformat:3 }}) &rarr;
      ({{ map.lat_bottom_right|floatformat:3 }}, {{ map.lon_bottom_right|floatformat:3 }})
      {% endif %}
      <br />
      {% with map.submission_time|date:"DATETIME_FORMAT" as date %}
      {% blocktrans %}Request submitted: {{ date }}{% endblocktrans %}
      {% endwith %}
      <br />
      {% if map.is_rendering %}
      {% with map.startofrendering_time|date:"DATETIME_FORMAT" as date %}
      {% blocktrans %}Rendering started: {{ date }}{% endblocktrans %}
      {% endwith %}
      {% endif %}
      {% if map.is_done or map.is_obsolete %}
      {% with map.endofrendering_time|date:"DATETIME_FORMAT" as date %}
      {% blocktrans %}Rendering completed: {{ date }}{% endblocktrans %}
      {% endwith %}
      {% endif %}
      {% if map.is_cancelled %}
      {% with map.endofrendering_time|date:"DATETIME_FORMAT" as date %}
      {% blocktrans %}Rendering cancelled: {{ date }}{% endblocktrans %}
      {% endwith %}
      {% endif %}
    </p>

    {% if map.is_waiting %}
      <a class="btn disabled tooltipped"
         data-placement="top"
         data-original-title="{% with map.submission_time|timesince as date %}
           {% blocktrans %}Pending, submitted {{ date }} ago{% endblocktrans %}
         {% endwith %}">
        <i class="icon-time"></i> {% trans "Pending..." %}
      </a>
    {% endif %}
    {% if map.is_rendering %}
      <a class="btn disabled tooltipped"
         data-placement="top"
         data-original-title="
         {% with map.startofrendering_time|timesince:map.endofrendering_time as date %}
           {% blocktrans %}Rendering is in progress, started {{ date }} ago{% endblocktrans %}
         {% endwith %}">
        <i class="icon-refresh"></i> {% trans "Rendering..." %}
      </a>
    {% endif %}
    {% if map.is_done_ok and map.has_output_files %}
      <div class="btn-group">
        {% with map.output_files.maps.pdf as file %}
        <a href="{{ file.0 }}" class="btn btn-primary">
          <i class="icon-white icon-download-alt"></i> {% trans "Download" %}
        </a>
        {% endwith %}
        <button class="btn btn-primary dropdown-toggle tooltipped"
                data-toggle="dropdown"
                data-original-title="{% trans "Download other formats and map indeces" %}">
          <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
        {% for format,file in map.output_files.maps.items %}
          <li><a href="{{ file.0 }}" title="{{ file.1 }}">{{ format|upper }} {% trans "map" %} ({{ file.2|filesizeformat }})</a></li>
        {% endfor %}

        {% if map.output_files.indeces|length %}
          <li class="divider"></li>
          {% for format,file in map.output_files.indeces.items %}<li><a href="{{ file.0 }}" title="{{ file.1 }}">{{ format|upper }} {% trans "index" %}</a></li>{% endfor %}
        {% endif %}
        </ul>
      </div>
    {% endif %}
    {% if not map.is_done_ok and not map.needs_waiting %}
      <a class="btn disabled tooltipped"
         data-placement="top"
         data-original-title="{{ map.status|job_status_to_str:map.resultmsg }}">
        <i class="icon-ban-circle"></i> {% trans "Download" %}
      </a>
    {% endif %}

    <form class="form-horizontal pull-right" method="post" action="{% url recreate %}">
      <input type="hidden" name="id" value="{{ map.id }}" />
      <button class="btn tooltipped"
              data-original-title="{% trans "Recreate map" %}"
              type="submit" {% if map.needs_waiting or not map.can_recreate %}disabled="disabled"{% endif %}>
        <i class="icon-refresh"></i>
      </button>

      <a class="btn popovered {% if not map.get_thumbnail %}disabled{% endif %}"
         rel="popover" data-placement="left" data-html="true"
         data-original-title="{% trans "Map thumbnail" %}"
         data-content='<img class="thumbnail" src="{{ map.get_thumbnail }}" />'>
         <i class="icon-search"></i>
      </a>
    </form>
  </div>

  {% if gis_lastupdate %}
  <div class="mapthumbnail" id="map-{{ map.id }}"
       data-geo-osm-id="{{ map.administrative_osmid }}"
       data-geo-from-lat="{{ map.lat_upper_left }}"
       data-geo-from-lon="{{ map.lon_upper_left }}"
       data-geo-to-lat="{{ map.lat_bottom_right }}"
       data-geo-to-lon="{{ map.lon_bottom_right }}"></div>
  {% endif %}
</div>
{% if forloop.last or not forloop.counter0|divisibleby:2 %}</div>{% endif %}
{% empty %}
<p>
{% ifequal form.cleaned_data.query "" %}
  {% blocktrans %}Our database does not contain any rendered maps for the moment.{% endblocktrans %}
{% else %}
  {% blocktrans %}No map matches your query.{% endblocktrans %} <a href="{% url new %}">{% trans "Create a new map!" %}</a>
{% endifequal %}
</p>
{% endfor %}

{% with maps as data %}{% with form.cleaned_data.query as query %}{% include "maposmatic/pagination.html" %}{% endwith %}{% endwith %}
{% endblock %}
