{% extends 'simple_service.html' %}
{% comment %}
#
# This file is part of FreedomBox.
#
# 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 (at your option) 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 static %}

{% block page_head %}

  {% if is_running %}
    <noscript>
      <meta http-equiv="refresh" content="3" />
    </noscript>
  {% endif %}

{% endblock %}


{% block configuration %}

  {% if not is_running %}
    <form class="form form-diagnostics-button" method="post"
          action="{% url 'diagnostics:index' %}">
      {% csrf_token %}

      <input type="submit" class="btn btn-primary"
             value="{% trans "Run Diagnostics" %}"/>
    </form>
  {% else %}
    <p>{% trans "Diagnotics test is currently running" %}</p>
    <div class="progress">
      <div class="progress-bar progress-bar-striped active"
           role="progressbar" aria-valuemin="0" aria-valuemax="100"
           aria-valuenow="{{ results.progress_percentage }}"
           style="width: {{ results.progress_percentage }}%">
        {{ results.progress_percentage }}%
      </div>
    </div>

  {% endif %}

  {% if results %}
    <h3>{% trans "Results" %}</h3>
    {% if results.error %}
      <div class="alert alert-danger alert-dismissable">
        <a class="close" data-dismiss="alert">&times;</a>
        {{ results.error }}
      </div>
    {% else %}
      {% for module, module_results in results.results.items %}
        <h4>{% blocktrans %}Module: {{ module }}{% endblocktrans %}</h4>

        {% if module_results %}
          {% include "diagnostics_results.html" with results=module_results %}
        {% else %}
          <p><span class="glyphicon glyphicon-hourglass"></span></p>
        {% endif %}
      {% endfor %}
    {% endif %}
  {% endif %}

{% endblock %}


{% block page_js %}
  {% if is_running %}
    <script type="text/javascript" src="{% static 'theme/js/refresh.js' %}"></script>
  {% endif %}
{% endblock %}

