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

{% load tags %}
{% load staticfiles %}

{% block title %} - {{ satellite }}{% endblock %}

{% block css %}
  <link rel="stylesheet" href="{% static 'lib/mapbox-gl/dist/mapbox-gl.css' %}">
{% endblock css %}

{% block top %}{% endblock %}

{% block content %}

  <!-- Satellite Overview Section -->
  <div class="row">
    <div class="col-md-12 satellite-panels">
      <div class="panel panel-default panel-satellite">
        <div class="panel-heading">
          <div class="satellite-title">
            {{ satellite }}
          </div>
          <div class="pull-right">
            {% if satellite.names %}
              <div class="satellite-names-full hidden-xs">{{ satellite.names }}</div>
            {% endif %}
            <span class="label satellite-status" data-status="{{ satellite.status }}">
              {{ satellite.status }}
            </span>
            <a type="button"
               title="SatNOGS Network observations"
               class="btn btn-default btn-xs"
               href="https://network.satnogs.org/observations/?norad={{ satellite.norad_cat_id }}"
               target="_blank">
              <span class="glyphicon glyphicon-new-window" aria-hidden="true"></span> Observations</span>
            </a>
          </div>
        </div>
        <div class="row panel-body">
          <div class="col-sm-3">
            <div>
              <img src="{{ satellite.get_image }}" alt="{{ satellite.name }}" class="satellite-img-full">
            </div>
            <div class="satellite-description">
              {{ satellite.get_description|safe }}
            </div>
          </div>
          <div class="col-sm-9">
          {% if satellite.status != 're-entered' %}
              <div id="map"
                   data-name="{{ satellite.name }}"
                   data-tle1="{{ satellite.latest_tle.tle1 }}"
                   data-tle2="{{ satellite.latest_tle.tle2 }}"
                   data-mapboxtoken="{{ mapbox_token }}"></div>
          {% endif %}
          </div>
        </div>
      </div>
    </div>
  </div>

  <!-- Transmitters Section -->
  <div class="row">
    <div class="col-md-12 satellite-panels">
      <div class="panel panel-default panel-satellite">
        <div class="panel-heading">
          <div class="satellite-title">
            Transmitters <span class="badge hidden-xs">{{ satellite.transmitter_set.count }}</span>
            {% if transmitter_suggestions %}
              <div class="transmitter-suggestions-counter label label-default hidden-xs">
                {{ transmitter_suggestions.count }} suggestion{{ transmitter_suggestions.count|pluralize }} pending
              </div>
            {% endif %}
          </div>
          <div class="satellite-suggest pull-right">
            <button type="button"
                    class="btn btn-primary btn-sm"
                    data-toggle="modal" data-target="#NewSuggestionModal">
              <span class="glyphicon glyphicon-plus" title="Suggest edits"></span> Suggest <span class="hidden-xs">New Transmitter</span>
            </button>
          </div>
        </div>
        <div class="row panel-body">
          <div class="col-md-12">
            <div class="row">
              {% for transmitter in satellite.transmitters.all %}
                <div class="col-md-4">
                  <div class="panel {% if satellite.status == 're-entered' %}panel-default{% elif transmitter.status == 'active' %}panel-success{% else %}panel-danger{% endif %} panel-transmitter">
                    <div class="panel-heading">
                      <h3 class="panel-title">
                        <span class="transmitter-title">{{ transmitter.description }}</span>
                        <button type="button"
                                title="UUID: {{ transmitter.uuid }}"
                                class="btn btn-default btn-sm pull-right transmitter-uuid js-copy"
                                data-toggle="tooltip"
                                data-placement="bottom"
                                data-copy="{{ transmitter.uuid }}">
                          <span class="glyphicon glyphicon-info-sign" title="Suggest edits"></span>
                        </button>
                        <button type="button"
                                class="btn btn-default btn-sm pull-right suggest-transmitter"
                                data-toggle="modal"
                                data-target="#EditSuggestionModal-{{ transmitter.id }}">
                          <span class="glyphicon glyphicon-edit" title="Suggest edits"></span>
                        </button>
                      </h3>
                    </div>
                    <div class="row panel-body">
                      <div class="col-md-12">
                        {% if transmitter.type %}
                          {% include "includes/field.html" with name="Type" value=transmitter.type %}
                        {% endif %}
                        {% if transmitter.service %}
                          {% include "includes/field.html" with name="Service" value=transmitter.service %}
                        {% endif %}
                        {% if transmitter.downlink_mode %}
                          {% include "includes/field.html" with name="Downlink Mode" value=transmitter.downlink_mode %}
                        {% endif %}
                        {% if transmitter.uplink_mode %}
                          {% include "includes/field.html" with name="Uplink Mode" value=transmitter.uplink_mode %}
                        {% endif %}
                        {% if transmitter.baud %}
                          {% include "includes/field.html" with name="Baud" value=transmitter.baud %}
                        {% endif %}
                        {% if transmitter.type == 'Transmitter' %}
                          {% if transmitter.downlink_low %}
                            {% include "includes/field.html" with name="Downlink" value=transmitter.downlink_low hz=transmitter.downlink_low %}
                          {% endif %}
                          {% if transmitter.downlink_drift %}
                            {% include "includes/field.html" with name="Downlink Drifted" value=transmitter.downlink_drift hz=transmitter.downlink_drift class="drifted" freq_or=transmitter.downlink_low %}
                          {% endif %}
                        {% endif %}
                        {% if transmitter.type == 'Transceiver' %}
                          {% if transmitter.downlink_low %}
                            {% include "includes/field.html" with name="Downlink" value=transmitter.downlink_low hz=transmitter.downlink_low %}
                          {% endif %}
                          {% if transmitter.downlink_drift %}
                            {% include "includes/field.html" with name="Downlink Drifted" value=transmitter.downlink_drift hz=transmitter.downlink_drift class="drifted" freq_or=transmitter.downlink_low %}
                          {% endif %}
                          {% if transmitter.uplink_low %}
                            {% include "includes/field.html" with name="Uplink" value=transmitter.uplink_low hz=transmitter.uplink_low %}
                          {% endif %}
                          {% if transmitter.uplink_drift %}
                            {% include "includes/field.html" with name="Uplink Drifted" value=transmitter.uplink_drift hz=transmitter.uplink_drift class="drifted" freq_or=transmitter.uplink_low %}
                          {% endif %}
                        {% endif %}
                        {% if transmitter.type == 'Transponder' %}
                          {% if transmitter.downlink_low %}
                            {% include "includes/field.html" with name="Downlink Low" value=transmitter.downlink_low hz=transmitter.downlink_low %}
                          {% endif %}
                          {% if transmitter.downlink_high %}
                            {% include "includes/field.html" with name="Downlink High" value=transmitter.downlink_high hz=transmitter.downlink_high %}
                          {% endif %}
                          {% if transmitter.downlink_drift %}
                            {% include "includes/field.html" with name="Downlink Drift" value=transmitter.downlink_drift hz=transmitter.downlink_drift %}
                          {% endif %}
                          {% if transmitter.uplink_low %}
                            {% include "includes/field.html" with name="Uplink Low" value=transmitter.uplink_low hz=transmitter.uplink_low %}
                          {% endif %}
                          {% if transmitter.uplink_high %}
                            {% include "includes/field.html" with name="Uplink High" value=transmitter.uplink_high hz=transmitter.uplink_high %}
                          {% endif %}
                          {% if transmitter.uplink_drift %}
                            {% include "includes/field.html" with name="Uplink Drift" value=transmitter.uplink_drift hz=transmitter.uplink_drift %}
                          {% endif %}
                          {% if transmitter.invert %}
                            {% include "includes/field.html" with name="Invert" value=transmitter.invert %}
                          {% endif %}
                        {% endif %}
                      </div>
                    </div>
                    <div class="panel-footer transmitter-citation-footer">
                        Updated on {{ transmitter.created|date:'Y-m-d H:i' }} by {{ transmitter.user }}
                        <button type="button"
                                class="btn btn-default btn-sm pull-right transmitter-citation"
                                data-toggle="modal"
                                data-target="#TransmitterCitation-{{ transmitter.id }}">
                          Citation
                        </button>
                    </div>
                  </div>

                  <!-- Citation Modal -->
                  <div class="modal fade" id="TransmitterCitation-{{ transmitter.id }}" tabindex="-1" role="dialog" aria-labelledby="CitationModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                      <div class="modal-content">
                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                          <h4 class="modal-title" id="CitationModalLabel">Citation for {{ transmitter.uuid }}</h4>
                        </div>
                        <div class="modal-body">
                          {{ transmitter.citation }}
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                      </div>
                    </div>
                  </div>

                  <!-- Edit Suggestion Modal -->
                  <div class="modal fade transmitter_suggestion-edit-modal" id="EditSuggestionModal-{{ transmitter.id }}" tabindex="-1" role="dialog" aria-labelledby="EditSuggestionModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                      <div class="modal-content">
                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                          <h4 class="modal-title" id="EditSuggestionModalLabel">Suggest an edit to this Transmitter</h4>
                        </div>
                        {% if request.user.is_authenticated %}
                          <form action="{% url 'transmitter_suggestion' %}" method="post" id="edittransmitter_suggestion-form">{% csrf_token %}
                            <div class="modal-body">
                              <input type="hidden" name="uuid" value="{{ transmitter.uuid }}"></input>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Description</div>
                                <input type="text" class="form-control" name="description" value="{{ transmitter.description }}">
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Status</div>
                                <select class="form-control transmitter_suggestion-status" name="status">
                                  {% for status in statuses %}
                                    <option value="{{ status }}" {% ifequal transmitter.status status %}selected{% endifequal %}>
                                      {{ status }}
                                    </option>
                                  {% endfor %}
                                </select>
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Type</div>
                                <select class="form-control transmitter_suggestion-type" name="type">
                                  {% for type in types %}
                                    <option value="{{ type }}" {% ifequal transmitter.type type %}selected{% endifequal %}>
                                      {{ type }}
                                    </option>
                                  {% endfor %}
                                </select>
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Service</div>
                                <select class="form-control transmitter_suggestion-service" name="service">
                                  {% for service in services %}
                                    <option value="{{ service }}" {% ifequal transmitter.service service %}selected{% endifequal %}>
                                      {{ service }}
                                    </option>
                                  {% endfor %}
                                </select>
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Downlink mode</div>
                                <select class="form-control" name="downlink_mode">
                                  <option value="" selected></option>
                                  {% for mode in modes %}
                                    <option value="{{ mode.id }}" {% ifequal transmitter.downlink_mode mode %}selected{% endifequal %}>
                                      {{ mode }}
                                    </option>
                                  {% endfor %}
                                </select>
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Uplink mode</div>
                                <select class="form-control" name="uplink_mode">
                                  <option value="" selected></option>
                                  {% for mode in modes %}
                                    <option value="{{ mode.id }}" {% ifequal transmitter.uplink_mode mode %}selected{% endifequal %}>
                                      {{ mode }}
                                    </option>
                                  {% endfor %}
                                </select>
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Uplink Low</div>
                                <input type="number" class="form-control" name="uplink_low" value="{{ transmitter.uplink_low|default_if_none:'' }}">
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Uplink High</div>
                                <input type="number" class="form-control" name="uplink_high" value="{{ transmitter.uplink_high|default_if_none:'' }}">
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Uplink Drifted</div>
                                <input type="number" class="form-control uplink-drifted-sugedit" name="" value="{{ transmitter.uplink_low|default_if_none:'' }}">
                                <div class="input-group-addon">PPB Drift</div>
                                <input type="text" class="form-control uplink-ppb-sugedit" name="uplink_drift" value="{{ transmitter.uplink_drift|default_if_none:'' }}" readonly>
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Downlink Low</div>
                                <input type="number" class="form-control" name="downlink_low" value="{{ transmitter.downlink_low|default_if_none:'' }}">
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Downlink High</div>
                                <input type="number" class="form-control" name="downlink_high" value="{{ transmitter.downlink_high|default_if_none:'' }}">
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Downlink Drifted</div>
                                <input type="number" class="form-control downlink-drifted-sugedit" name="" value="{{ transmitter.downlink_low|default_if_none:'' }}">
                                <div class="input-group-addon">PPB Drift</div>
                                <input type="text" class="form-control downlink-ppb-sugedit" name="downlink_drift" value="{{ transmitter.downlink_drift|default_if_none:'' }}" readonly>
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <input type="checkbox" value="1" name="invert" {% if transmitter.invert %}checked{% endif %}> Invert
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Baud Rate</div>
                                <input type="number" class="form-control" name="baud" value="{{ transmitter.baud|default_if_none:'' }}">
                              </div>
                              <div class="input-group transmitter-element-suggest">
                                <div class="input-group-addon">Citation URL</div>
                                <input type="text" class="form-control" name="citation" maxlength="255" required>
                              </div>
                            </div>
                            <div class="modal-footer">
                              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                              <button type="submit" class="btn btn-primary">Send</button>
                            </div>
                            <input type="hidden" name="transmitter" value="{{ transmitter.pk }}">
                            <input type="hidden" name="satellite" value="{{ satellite.pk }}">
                          </form>
                        {% else %}
                          <div class="modal-body">
                            <div class="text-danger">You need to login first to add a new transmitter suggestion.</div>
                          </div>
                          <div class="modal-footer">
                            <button class="btn btn-default" data-dismiss="modal">Close</button>
                            <a href="{% url 'account_login' %}" class="btn btn-primary">Log In</a>
                          </div>
                        {% endif %}
                      </div>
                    </div>
                  </div>
                </div>
                {% if forloop.counter|divisibleby:3 %}
                  </div>
                   {% if not loop.last %}
                     <div class="row">
                   {% endif %}
                {% endif %}
              {% empty %}
                <div class="row panel-body">
                  <div class="col-md-12">
                    <span class="text-danger">No approved transmitters yet for this Satellite.</span>
                  </div>
                </div>
              {% endfor %}
            </div>

            {% if request.user.is_superuser %}
              <hr>
              <div class="row">
                {% for transmitter_suggestion in transmitter_suggestions %}
                  <div class="col-md-4">
                    <div class="panel panel-{% if transmitter_suggestion.transmitter %}info{% else %}warning{% endif %} panel-transmitter">
                      <div class="panel-heading">
                        <h3 class="panel-title">
                          <span class="transmitter-title">{{ transmitter_suggestion.description }}</span>
                          <a type="button" href="{% url 'admin:base_transmittersuggestion_changelist' %}"
                             target="_blank" title="Edit on admin"
                             class="btn btn-default btn-sm pull-right suggest-transmitter">
                            <span class="glyphicon glyphicon-wrench" ></span>
                          </a>
                        </h3>
                      </div>
                      <div class="row panel-body">
                        <div class="col-md-12">
                          {% if transmitter_suggestion.description != transmitter_suggestion.transmitter.description %}
                            {% include "includes/field.html" with name="Description" value=transmitter_suggestion.description original=transmitter_suggestion.transmitter.description %}
                          {% endif %}
                          {% if transmitter_suggestion.status %}
                            {% include "includes/field.html" with name="Status" value=transmitter_suggestion.status original=transmitter_suggestion.transmitter.status %}
                          {% endif %}
                          {% if transmitter_suggestion.type %}
                            {% include "includes/field.html" with name="Type" value=transmitter_suggestion.type original=transmitter_suggestion.transmitter.type %}
                          {% endif %}
                          {% if transmitter_suggestion.service %}
                            {% include "includes/field.html" with name="Service" value=transmitter_suggestion.service original=transmitter_suggestion.transmitter.service %}
                          {% endif %}
                          {% if transmitter_suggestion.downlink_mode %}
                            {% include "includes/field.html" with name="Downlink Mode" value=transmitter_suggestion.downlink_mode original=transmitter_suggestion.transmitter.downlink_mode %}
                          {% endif %}
                          {% if transmitter_suggestion.uplink_mode %}
                            {% include "includes/field.html" with name="Uplink Mode" value=transmitter_suggestion.uplink_mode original=transmitter_suggestion.transmitter.uplink_mode %}
                          {% endif %}
                          {% if transmitter_suggestion.invert %}
                            {% include "includes/field.html" with name="Invert" value=transmitter_suggestion.invert original=transmitter_suggestion.transmitter.invert %}
                          {% endif %}
                          {% if transmitter_suggestion.baud %}
                            {% include "includes/field.html" with name="Baud" value=transmitter_suggestion.baud original=transmitter_suggestion.transmitter.baud %}
                          {% endif %}
                          {% if transmitter_suggestion.uplink_low %}
                            {% include "includes/field.html" with name="Uplink Low" value=transmitter_suggestion.uplink_low original=transmitter_suggestion.transmitter.uplink_low hz=transmitter.uplink_low %}
                          {% endif %}
                          {% if transmitter_suggestion.uplink_high %}
                            {% include "includes/field.html" with name="Uplink High" value=transmitter_suggestion.uplink_high original=transmitter_suggestion.transmitter.uplink_high hz=transmitter.uplink_high %}
                          {% endif %}
                          {% if transmitter_suggestion.uplink_drift %}
                            {% include "includes/field.html" with name="Uplink Drift" value=transmitter_suggestion.uplink_drift original=transmitter_suggestion.transmitter.uplink_drift hz=transmitter.uplink_drift %}
                          {% endif %}
                          {% if transmitter_suggestion.downlink_low %}
                            {% include "includes/field.html" with name="Downlink Low" value=transmitter_suggestion.downlink_low original=transmitter_suggestion.transmitter.downlink_low hz=transmitter.downlink_low %}
                          {% endif %}
                          {% if transmitter_suggestion.downlink_high %}
                            {% include "includes/field.html" with name="Downlink High" value=transmitter_suggestion.downlink_high original=transmitter_suggestion.transmitter.downlink_high hz=transmitter.downlink_high %}
                          {% endif %}
                          {% if transmitter_suggestion.downlink_drift %}
                            {% include "includes/field.html" with name="Downlink Drift" value=transmitter_suggestion.downlink_drift original=transmitter_suggestion.transmitter.downlink_drift hz=transmitter.downlink_drift %}
                          {% endif %}
                          {% if transmitter_suggestion.citation %}
                            {% include "includes/field.html" with name="Citation" value=transmitter_suggestion.citation|urlizetrunc:35 original=transmitter_suggestion.transmitter.citation|urlizetrunc:35 %}
                          {% endif %}
                        </div>
                      </div>
                    </div>
                  </div>
                  {% if forloop.counter|divisibleby:3 %}
                    </div>
                     {% if not loop.last %}
                       <div class="row">
                     {% endif %}
                  {% endif %}
                {% endfor %}
              </div>
            {% endif %}

          </div>
        </div>
      </div>
    </div>
  </div>

  <script id="telemetryDescriptorsTemplate" type="text/template">
    <li class="list-group-item telemetry-key" data-key="<%- key %>" data-unit="<%- unit %>"><%- description %></li>
  </script>


  <!-- Data Structs Section -->
  {% if satellite.telemetry_decoder_count %}
    <div class="row">
      <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 satellite-panels">
        <div class="panel panel-default panel-satellite">
          <div class="panel-heading">
            <div class="satellite-title" id="telemetry-block" data-satid="{{ satellite.norad_cat_id }}">
              Data Decoding Structs
            </div>
          </div>
          <div class="row panel-body">
            <div class="col-md-12">
              <div class="row">
                {% for telemetry in satellite.telemetries.all %}
                  <div class="col-md-4">
                    <div class="panel panel-primary panel-transmitter">
                      <div class="panel-heading">
                        <h3 class="panel-title">
                          <span class="transmitter-title">{{ telemetry.name }}</span>
                        </h3>
                      </div>
                      <div class="row panel-body">
                        <div class="col-md-12">
                          {% include "includes/field.html" with name="Decoder Script" value=telemetry.decoder %}
                          <div class="row transmitter-element">
                            <div class="col-md-6">
                              <span class="label label-default">Decoder Struct</span>
                            </div>
                            <div class="col-md-6">
                              <a href="#" data-toggle="modal"
                                 data-target="#StructModal-{{ telemetry.id }}">
                                Click here
                              </a>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>

                  <!-- Struct Modal -->
                  <div class="modal fade" id="StructModal-{{ telemetry.id }}" tabindex="-1" role="dialog" aria-labelledby="StructModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                      <div class="modal-content">
                        <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                          <h4 class="modal-title" id="EditSuggestionModalLabel">Kaitai Struct for {{ telemetry.name }}</h4>
                        </div>
                        <div class="modal-body">
                          {% if not telemetry.schema == '' %}
                            <div class="kaitai-header">
                              See <a href="http://kaitai.io" target="_blank">kaitai.io</a> for more information on the format.
                            </div>
                            <div class="kaitai-struct">
                              <pre>{{ telemetry.schema }}</pre>
                            </div>
                          {% else %}
                            <div>
                              Struct format appears to be missing.
                            </div>
                          {% endif %}
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        </div>
                      </div>
                    </div>
                  </div>
                {% empty %}
                  <div class="row panel-body">
                    <div class="col-md-12">
                      <span class="text-danger">No data structs yet for this Satellite.</span>
                    </div>
                  </div>
                {% endfor %}
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  {% endif %}

  <!-- Orbital Elements Section -->
  {% if satellite.latest_tle.redistributable %}
  <div class="row">
    <div class="col-md-12 satellite-panels">
      <div class="panel panel-default panel-satellite">
        <div class="panel-heading">
          <div class="satellite-title">
            Orbital Elements
          </div>
        </div>
        <div class="row panel-body">
          <div class="col-md-12">
            <div class="row">
              <div class="col-md-12">
                <div class="panel panel-primary panel-tle">
                  <div class="panel-heading">
                    <h3 class="panel-title">
                      <span class="tle-title">Latest TLE</span>
                    </h3>
                  </div>
                  <div class="row panel-body">
                    <div class="col-md-12">
                      <div class="row tle-element">
                        <div class="col-md-2">
                          <span class="label label-default">NORAD ID</span>
                        </div>
                        <div class="col-md-10">
                          {{ satellite.latest_tle.norad_cat_id }}
                        </div>
                      </div>
                      <div class="row tle-element">
                        <div class="col-md-2">
                          <span class="label label-default">TLE source</span>
                        </div>
                        <div class="col-md-10">
                          {{ satellite.latest_tle.source }}
                        </div>
                      </div>
                      <div class="row tle-element">
                        <div class="col-md-2">
                          <span class="label label-default">TLE</span>
                        </div>
                        <div class="col-md-10">
                          <pre>{{ satellite.latest_tle.tle1 }}<br>{{ satellite.latest_tle.tle2 }}</pre>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  {% endif %}

  <!-- Telemetry Frames Section -->
  <!-- This is a hacky way of getting around slow db queries. See #237 -->
  {% for sat in sats_cache %}
    {% if sat.norad_cat_id == satellite.norad_cat_id and sat.count != 0 %}
      <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 satellite-panels">
          <div class="panel panel-default panel-satellite">
            <div class="panel-heading">
              <div class="satellite-title" id="telemetry-block" data-satid="{{ satellite.norad_cat_id }}">
                Telemetry (frames)
              </div>
            </div>
            {% if request.user.is_authenticated %}
              <div class="row panel-body">
                <div class="panel-satellite chart">
                  <div class="col-md-3 panel-satellite">
                    <div class="btn-group">
                      <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <span class="glyphicon glyphicon-download"></span> Download <span class="caret"></span>
                      </button>
                      <ul class="dropdown-menu">
                        <li><a href="{% url 'request_export_all' norad=satellite.norad_cat_id %}">Everything</a></li>
                        <li><a href="{% url 'request_export' norad=satellite.norad_cat_id period=1 %}">Last week</a></li>
                        <li><a href="{% url 'request_export' norad=satellite.norad_cat_id period=2 %}">Last month</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            {% endif %}
            <div class="panel-footer">
              <span class="badge">Frames: {{ sat.count }}</span>
              Latest frame submitted on {{ latest_frame.timestamp|date:'Y-m-d H:i:s' }} by
              {{ latest_frame.observer }}
            </div>
          </div>
        </div>
      </div>
    {% endif %}
  {% endfor %}

  <!-- Transmitter Suggestion Modal -->
  <div class="modal fade" id="NewSuggestionModal" tabindex="-1" role="dialog" aria-labelledby="NewSuggestionModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title" id="NewSuggestionModalLabel">Suggest a new Transmitter</h4>
        </div>
        {% if request.user.is_authenticated %}
          <form action="{% url 'transmitter_suggestion' %}" method="post" id="newtransmitter_suggestion-form">{% csrf_token %}
            <div class="modal-body">
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Description</div>
                <input type="text" class="form-control" name="description">
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Status</div>
                <select class="form-control transmitter_suggestion-status" name="status">
                  {% for status in statuses %}
                    <option value="{{ status }}">
                      {{ status }}
                    </option>
                  {% endfor %}
                </select>
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Type</div>
                <select class="form-control transmitter_suggestion-type" name="type">
                  {% for type in types %}
                    <option value="{{ type }}">
                      {{ type }}
                    </option>
                  {% endfor %}
                </select>
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Service</div>
                <select class="form-control" name="service" required>
                  {% for service in services %}
                    <option value="{{ service }}">
                      {{ service }}
                    </option>
                  {% endfor %}
                </select>
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Downlink Mode</div>
                <select class="form-control" name="downlink_mode">
                  <option value="" selected></option>
                  {% for mode in modes %}
                    <option value="{{ mode.id }}">
                      {{ mode }}
                    </option>
                  {% endfor %}
                </select>
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Uplink mode</div>
                <select class="form-control" name="uplink_mode">
                  <option value="" selected></option>
                  {% for mode in modes %}
                    <option value="{{ mode.id }}">
                      {{ mode }}
                    </option>
                  {% endfor %}
                </select>
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Uplink_Low</div>
                <input type="number" class="form-control" name="uplink_low">
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Uplink High</div>
                <input type="number" class="form-control" name="uplink_high">
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Uplink Drifted</div>
                <input type="number" class="form-control uplink-drifted-sugedit" name="">
                <div class="input-group-addon">PPB Drift</div>
                <input type="text" class="form-control uplink-ppb-sugedit" name="uplink_drift" readonly>
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Downlink Low</div>
                <input type="number" class="form-control" name="downlink_low">
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Downlink High</div>
                <input type="number" class="form-control" name="downlink_high">
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Downlink Drifted</div>
                <input type="number" class="form-control downlink-drifted-sugedit" name="" value="{{ transmitter.downlink_low|default_if_none:'' }}">
                <div class="input-group-addon">PPB Drift</div>
                <input type="text" class="form-control downlink-ppb-sugedit" name="downlink_drift" value="{{ transmitter.downlink_drift|default_if_none:'' }}" readonly>
              </div>
              <div class="input-group transmitter-element-suggest">
                <input type="checkbox" value="1" name="invert"> Invert
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Baud Rate</div>
                <input type="number" class="form-control" name="baud">
              </div>
              <div class="input-group transmitter-element-suggest">
                <div class="input-group-addon">Citation URL</div>
                <input type="text" class="form-control" name="citation" maxlength="255" required>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="submit" class="btn btn-primary">Send</button>
            </div>
            <input type="hidden" name="satellite" value="{{ satellite.pk }}">
          </form>
        {% else %}
          <div class="modal-body">
            <div class="text-danger">You need to login first to add a new transmitter suggestion.</div>
          </div>
          <div class="modal-footer">
            <button class="btn btn-default" data-dismiss="modal">Close</button>
            <a href="{% url 'account_login' %}" class="btn btn-primary">Log In</a>
          </div>
        {% endif %}
      </div>
    </div>
  </div>


{% endblock %}

{% block javascript %}
  <script src="{% static 'lib/moment/min/moment.min.js' %}"></script>
  <script src="{% static 'lib/mapbox-gl/dist/mapbox-gl.js' %}"></script>
  <script src="{% static 'lib/gpredict.js/dist/gpredict.min.js' %}"></script>
  <script src="{% static 'js/map.js' %}"></script>
  <script src="{% static 'js/satellite.js' %}"></script>
{% endblock %}
