{% extends "base.html" %}

{% load static %}
{% load projecttags %}
{% load humanize %}

{% block pagecontent %}
<div class="row-fluid">
  {% if not objects.paginator.count and not request.GET.filter and not request.GET.search %}
    <!-- Empty - no data in database -->
    <div class="hero-unit span12">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <div class="row-fluid">
            <div class="span6">
                <h1>This is Toaster</h1>
                <p>A web interface to <a href="http://www.yoctoproject.org/tools-resources/projects/bitbake">BitBake</a>, the <a href="http://www.yoctoproject.org">Yocto Project</a> build system.</p>
                <p class="hero-actions">
                    <a class="btn btn-primary btn-large" href="https://www.yoctoproject.org/documentation/toaster-manual">Show me the manual</a>
                    <a class="btn btn-large" href="https://wiki.yoctoproject.org/wiki/Contribute_to_Toaster">I want to contribute</a>
                </p>
            </div>
            <div class="span5">
                <a href="http://www.yoctoproject.org"><img src="{% static 'img/toaster.png' %}" class="thumbnail" alt="Yocto Project"/> </a>
            </div>
        </div>
    </div>
  {% endif %}

  {%if mru.count > 0%}
  <div class="page-header top-air">
      <h1>
          Recent Builds
       </h1>
  </div>
  {% for build in mru %}
    <div class="alert {%if build.outcome == build.SUCCEEDED%}alert-success{%elif build.outcome == build.FAILED%}alert-error{%else%}alert-info{%endif%}">
        <div class="row-fluid">
            <div class="lead span5">
                {%if build.outcome == build.SUCCEEDED%}<i class="icon-ok-sign success"></i>{%elif build.outcome == build.FAILED%}<i class="icon-minus-sign error"></i>{%else%}{%endif%}
    {%if build.outcome == build.SUCCEEDED or build.outcome == build.FAILED %}
                <a href="{%url 'builddashboard' build.pk%}" class="{%if build.outcome == build.SUCCEEDED %}success{%else%}error{%endif%}">
    {% endif %}
                <span data-toggle="tooltip" {%if build.target_set.all.count > 1%}title="Targets: {%for target in build.target_set.all%}{{target.target}} {%endfor%}"{%endif%}>{{build.target_set.all.0.target}} {%if build.target_set.all.count > 1%}(+ {{build.target_set.all.count|add:"-1"}}){%endif%} {{build.machine}} ({{build.completed_on|naturaltime}})</span>
    {%if build.outcome == build.SUCCEEDED or build.outcome == build.FAILED %}
                </a>
    {% endif %}
            </div>
    {%if build.outcome == build.SUCCEEDED or build.outcome == build.FAILED %}
            <div class="span2 lead">
    {% if  build.errors_no %}
                <i class="icon-minus-sign red"></i> <a href="{%url 'builddashboard' build.pk%}#errors" class="error">{{build.errors_no}} error{{build.errors_no|pluralize}}</a>
    {% endif %}
            </div>
            <div class="span2 lead">
    {% if  build.warnings_no %}
                <i class="icon-warning-sign yellow"></i> <a href="{%url 'builddashboard' build.pk%}#warnings" class="warning">{{build.warnings_no}} warning{{build.warnings_no|pluralize}}</a>
    {% endif %}
            </div>
            <div class="lead pull-right">
                Build time: <a href="{% url 'buildtime' build.pk %}">{{ build.timespent|sectohms }}</a>
            </div>
    {%endif%}{%if build.outcome == build.IN_PROGRESS %}
            <div class="span4">
                <div class="progress" style="margin-top:5px;" data-toggle="tooltip" title="{{build.completeper}}% of tasks complete">
                    <div style="width: {{build.completeper}}%;" class="bar"></div>
                </div>
            </div>
            <div class="lead pull-right">ETA: in {{build.eta|naturaltime}}</div>
    {%endif%}
        </div>
    </div>

  {% endfor %}{%endif%}

  {% if not objects.paginator.count and not request.GET.filter and not request.GET.search %}
    <!-- Empty - no data in database -->
    {% if mru.count == 0 %}
    <div class="page-header top-air">
       <h1>All builds</h1>
    </div>
    <div class="alert alert-info lead">
        Toaster has not recorded any builds yet. Go build something with <a href="http://www.yoctoproject.org/docs/current/yocto-project-qs/yocto-project-qs.html#test-run">Knotty</a> or <a href="https://www.yoctoproject.org/documentation/hob-manual">Hob</a>
    </div>
    {% endif %}
  {% else %}
  <div class="page-header top-air">
     <h1>
      {% if request.GET.filter and objects.paginator.count > 0 or request.GET.search and objects.paginator.count > 0 %}
          {{objects.paginator.count}} build{{objects.paginator.count|pluralize}} found
      {%elif request.GET.filter and objects.paginator.count == 0 or request.GET.search and objects.paginator.count == 0 %}
          No builds found
      {%else%}
          All builds
      {%endif%}
     </h1>
  </div>

  {% if objects.paginator.count == 0 %}
    <div class="row-fluid">
      <div class="alert">
        <form class="no-results input-append" id="searchform">
            <input id="search" name="search" class="input-xxlarge" type="text" value="{{request.GET.search}}"/>{% if request.GET.search %}<a href="javascript:$('#search').val('');searchform.submit()" class="add-on btn" tabindex="-1"><i class="icon-remove"></i></a>{% endif %}
            <button class="btn" type="submit" value="Search">Search</button>
            <button class="btn btn-link" onclick="javascript:$('#search').val('');searchform.submit()">Show all builds</button>
        </form>
      </div>
    </div>


  {% else %}
  {% include "basetable_top.html" %}
        <!-- Table data rows; the order needs to match the order of "tablecols" definitions; and the <td class value needs to match the tablecols clclass value for show/hide buttons to work -->
        {% for build in objects %}
        <tr class="data">
            <td class="outcome"><a href="{% url "builddashboard" build.id %}">{%if build.outcome == build.SUCCEEDED%}<i class="icon-ok-sign success"></i>{%elif build.outcome == build.FAILED%}<i class="icon-minus-sign error"></i>{%else%}{%endif%}</a></td>
            <td class="target">{% for t in build.target_set.all %} <a href="{% url "builddashboard" build.id %}"> {{t.target}} </a> <br />{% endfor %}</td>
            <td class="machine"><a href="{% url "builddashboard" build.id %}">{{build.machine}}</a></td>
            <td class="started_on"><a href="{% url "builddashboard" build.id %}">{{build.started_on|date:"d/m/y H:i"}}</a></td>
            <td class="completed_on"><a href="{% url "builddashboard" build.id %}">{{build.completed_on|date:"d/m/y H:i"}}</a></td>
            <td class="failed_tasks error">{% query build.task_build outcome=4 order__gt=0 as exectask%}{% if exectask.count == 1 %}<a href="{% url "task" build.id exectask.0.id %}">{{exectask.0.recipe.name}}.{{exectask.0.task_name}}</a>{% elif exectask.count > 1%}<a href="{% url "tasks" build.id %}?filter=outcome%3A4">{{exectask.count}}</a>{%endif%}</td>
            <td class="errors_no">{% if  build.errors_no %}<a class="errors_no error" href="{% url "builddashboard" build.id %}#errors">{{build.errors_no}} error{{build.errors_no|pluralize}}</a>{%endif%}</td>
            <td class="warnings_no">{% if  build.warnings_no %}<a class="warnings_no warning" href="{% url "builddashboard" build.id %}#warnings">{{build.warnings_no}} warning{{build.warnings_no|pluralize}}</a>{%endif%}</td>
            <td class="time"><a href="{% url "buildtime" build.id %}">{{build.timespent|sectohms}}</a></td>
            <td class="log">{{build.cooker_log_path}}</td>
            <td class="output">
              {% if build.outcome == build.SUCCEEDED %}
              <a href="{%url "builddashboard" build.id%}#images">{{fstypes|get_dict_value:build.id}}</a>
              {% endif %}
            </td>
        </tr>

        {% endfor %}


  {% include "basetable_bottom.html" %}
  {% endif %} {# objects.paginator.count #}
{% endif %} {# empty #}
</div><!-- end row-fluid-->

{% endblock %}
