{% extends "base.html" %}

{% block main_area %}
{% include "step_details_modal.html" %}
{% include "buildset_details_modal.html" %}
{% include "build_details_modal.html" %}

<input type="hidden" id="waterfall-repo-id" value="{{repository.id}}"/>
<input type="hidden" id="waterfall-repo-name" value="{{repository.name}}"/>
<table>
  <tbody id="waterfall-table">
    <tr class="waterfall-row" id="waterfall-first-row">
      <td class="buildsets-column placeholder">
	<ul>
	  <li class="buildset buildset-placeholder">
	    buildsets
	  </li>
	</ul>
      </td>
      {% for builder in builders %}
      <td class="builders-column">
	<ul class="">
	  <li class="builder builder-{{builder.status}}">
	    {{builder.name}}
	    <input type="hidden" id="builder-{{builder.id}}" value="{{builder.status}}">
	  </li>
	</ul>
      </td>
      {% end %}
    </tr>
    {% for buildset in buildsets %}
    <tr class="waterfall-row">
      <td class="buildsets-column">
	<ul class="">
	  <li class="buildset" id="buildset-{{buildset.id}}">
	    commit: {{buildset.commit[:8]}}<br/>
	    branch: {{buildset.branch}}<br/>
	    <button type="button" class=" btn btn-default btn-rebuild btn-transparent btn-buildset-details btn-sm"
		    data-toggle="modal"
		    data-target="#buildsetDetailsModal"
		    data-dismiss="modal"
		    data-buildset-commit="{{buildset.commit}}"
		    data-buildset-branch="{{buildset.branch}}"
		    data-buildset-commit-author="{{buildset.author}}"
		    data-buildset-commit-title="{{buildset.title}}"
		    data-buildset-created="{{fmtdt(buildset.created)}}"
		    data-buildset-started="{{fmtdt(buildset.started)}}"
		    data-buildset-finished="{{fmtdt(buildset.finished)}}"
		    data-buildset-total-time="{{buildset.total_time}}">
	      <span data-toggle="tooltip" title="Buildset details" data-placement="right">

		<span class="glyphicon glyphicon-modal-window" aria-hidden="true"></span>
	      </span>
	    </button>

	    <span data-toggle="tooltip" title="Re-schedule buildset" data-placement="right">
	      <button type="button" class="btn btn-default btn-rebuild btn-transparent btn-rebuild-buildset btn-sm"
		      data-buildset-commit="{{buildset.commit}}"
		      data-buildset-branch="{{buildset.branch}}">

		<span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>
	      </button>
	     </span>

	  </li>
	</ul>
      </td>
      {% for i, build in enumerate(ordered_builds(buildset.builds)) %}
      <td class="builder-column builder-column-id-{{build.builder.id}} builder-column-index-{{i}}" id="build-builder-{{build.builder.id}}">
	{% for ending in get_ending(build, i, builders)%}
   	  {% raw ending %}
	{% end %}
	<ul>
	  <li class="step step-{{build.status}}" id="build-info-{{build.uuid}}">
	    Build - {{build.status}} <i class="fa fa-3x fa-fw toxic-spinner-running " id="spinner-build-{{build.uuid}}"
					{% if build.status != 'running' %} style="display:none" {% end %}>

	      </i>
	    <span data-toggle="tooltip" title="Re-schedule build" data-placement="right" {% if build.status in ['pending', 'running'] %} style="display:none" {% end %}>
	      <button type="button" class="btn btn-default btn-rebuild btn-transparent btn-rebuild-build btn-sm"
		      data-buildset-commit="{{buildset.commit}}"
		      data-buildset-branch="{{buildset.branch}}"
		      data-builder-name="{{ build.builder.name}}">
		<span class="glyphicon glyphicon-repeat" aria-hidden="true"></span>
	      </button>
	    </span>

	    <span data-toggle="tooltip" title="Build details" data-placement="right" {% if build.status in ['pending', 'running'] %} style="display:none" {% end %} class="build-details-btn">
	      <button type="button" class="btn btn-default btn-build-details btn-transparent btn-build-details-build btn-sm"
		      data-buildset-commit="{{buildset.commit}}"
		      data-buildset-branch="{{buildset.branch}}"
		      data-builder-name="{{build.builder.name}}"
		      data-buildset-commit-author="{{buildset.author}}"
		      data-buildset-commit-title="{{buildset.title}}"
		      data-build-created="{{fmtdt(buildset.created)}}"
		      data-build-started="{{fmtdt(build.started)}}"
		      data-build-finished="{{fmtdt(build.finished)}}"
		      data-build-total-time="{{build.total_time}}"
		      data-toggle="modal"
		      data-target="#buildDetailsModal">
		<span class="glyphicon glyphicon-modal-window" aria-hidden="true"></span>
	      </button>
	    </span>

	  </li>
	  {% for step in build.steps %}
	  <li class="step step-{{step.status}}" id="step-{{step.uuid}}">
	    <div class="build-step-info-container">
	      <div class="step-info-text">
		{{step.name}} - {{step.status}}
	      </div>
	      <div class="step-info-btn">
		<button type="button" class="btn btn-default btn-step-details btn-transparent btn-sm"
			data-toggle="modal"
			data-target="#stepDetailsModal"
			data-dismiss="modal"
			data-step-uuid="{{step.uuid}}"
			data-step-command="{{step.command}}"
			data-step-output="{{step.output}}"
			data-step-status="{{step.status}}"
			data-step-start="{{fmtdt(step.started)}}"
			data-step-end="{{fmtdt(step.finished)}}"
			data-step-total-time="{{step.total_time}}">
		  <span data-toggle="tooltip" title="Step details" data-placement="right">
		    <span class="glyphicon glyphicon-modal-window" aria-hidden="true"></span>
		  </span>
	      </div>

	      </button>
	    </div>
	  </li>
	  {% end %}
	</ul>
      </td>
      {% end %}
    </tr>
    {% end %}
  </tbody>
</table>
{% end %}

{% block js_bottom %}
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="{{static_url}}toxicbuild/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="{{static_url}}toxicbuild/js/bootstrap.min.js"></script>
<script src="{{static_url}}toxicbuild/js/utils.js"></script>
<script src="{{static_url}}toxicbuild/js/waterfall.js"></script>
<script>
  TOXICDEBUG = true;
  BUILDERS = {% raw [b.to_json() for b in builders] %}
  jQuery(function () {
    jQuery('[data-toggle="tooltip"]').tooltip()
  });
</script>
{% end %}
