{% extends "panel/base.html" %}
{% load jsonify %}
{% load static %}
{% block title %}{{ build_release.release }}{% endblock %}
{% block navlist %}
    <li><a href="{% url 'panel:index' %}">Panel</a></li>
    <li><a href="{% url 'release_dashboard:build_index'%}">Build Release</a></li>
    <li><a href="{% url 'release_dashboard:build_release' build_release.release %}">{{ build_release.release }}</a></li>
{% endblock %}
{% block content %}
<div class="container">
  <div class="panel panel-default" id="release_metadata">
    {% include "panel/release_info.html" %}
  </div>
</div>
<div class="container">
  <div class="panel panel-default">
    {% if not build_release.is_update %}
      {% include "panel/base_release_job.html" %}
    {% endif %}
  </div>
  <div id="release-job-list"></div>
</div>
<div class="container">
    <div class="panel panel-default" id="stats">
      {% include "panel/release_stats.html" %}
    </div>
    <div class="panel panel-default project-clone hidden">
      {% include "panel/base_project.html" %}
    </div>
    <div id="project-list"></div>
</div>
{% endblock %}

{% block extrajs %}
<script src="{% static 'panel/js/panel.js' %}"></script>
<script src="{% static 'panel/js/panel_release.js' %}"></script>
<script type="text/javascript">
$( document ).ready(function() {
  $.panel = 'release';
  $.release.uuid = '{{ build_release.uuid }}';
  $.release.release_jobs_size = {{ release_jobs_size }};
  $.release.max_uuids = 1;
{% if build_release.done %}
  $( "#update-info-all" ).addClass( "hidden" );
{% else %}
  $.release.interval = 15000;
  $( "#update-info" ).text($.release.interval/1000);
  $.release.timer = setInterval(function(){
    update_release_info('{{ build_release.release }}');
    $( "#update-info" ).text($.release.interval/1000);
  }, $.release.interval);
  $.release.update_info_timer = setInterval(function(){
    var step = parseInt($( "#update-info" ).text());
    $( "#update-info" ).text(step - 1);
  }, 1000);
{% endif %}
set_stats_total('{{ total }}');
{% for projectname in queued_projects %}
set_project_stats('{{ projectname }}', 'queued');
{% endfor %}
{% for job, values in release_jobs.items %}
values = {{ values.0|jsonify }};
create_new_release_job(values);
{% endfor %}
{% for projectname, project in projects.items %}
  create_new_project('{{ build_release.release }}', '{{ projectname }}', false);
  {% for uuid, uuid_value in project.items %}
    {% if uuid_value.latest %}
      values = {tag: '{{ uuid }}', latest: true };
      create_new_uuid('{{ build_release.release }}', '{{ projectname }}', values, false);
      {% for key, job in uuid_value.items %}
      {% if key != 'latest' %}
        data = {{ job|jsonify }};
        create_new_job('{{ projectname }}', '{{ uuid }}', data);
      {% endif %}
      {% endfor %}
    {% endif %}
  {% endfor %}
{% endfor %}
update_stats();
update_release_info('{{ build_release.release }}');
});
</script>
{% endblock %}
