{% extends "tcms_base.html" %}

{% load report_tags %}
{% load static %}

{% block subtitle %}Custom Report{% endblock %}

{% block custom_stylesheet %}
<link rel="stylesheet" type="text/css" href="{% static "style/print.css" %}" media="print" />
<link rel="stylesheet" type="text/css" href="{% static "style/dataTables/jquery.dataTables.css" %}" />
<link rel="stylesheet" type="text/css" href="{% static "style/dataTables/jquery.dataTables_themeroller.css" %}" />
{% endblock %}

{% block custom_javascript %}
<script type="text/javascript" src="{% static "js/lib/jquery.dataTables.js" %}"></script>
<script type="text/javascript" src="{% static "js/report.js" %}"></script>
<script type="text/javascript">
Nitrate.Utils.after_page_load(Nitrate.Report.CustomSearch.on_load);
</script>
{% endblock %}

{% block contents %}
<div id="content">
	<div class="sprites crumble"><a href="{% url "nitrate-index" %}">Home</a> &gt;&gt; Custom Reporting</div>
	<div class="itemSearch">
		<h2>Report Options</h2>
		<form id="id_form_search" action="{% url "report-custom" %}">
			{% include "report/form/search.html" %}
			<div class="bottom">
				<input type="submit" name="a" value="Search" title="Create report" />
				{# <input type="reset" alue="Save Query" name="" title="Save Query" /> #}
			</div>
		</form>
	</div>
	{% if builds %}
	<div class="report_bar">
		<b>{{ builds|length }} builds are selected</b>
		<div class='coverage_report'>Plan<span class="red">{{ total_plans_count }}</span> Run<span class="red">{{ total_runs_count }}</span>Manual Cases<span class="red">{{manual_count|percentage:total_count}}({{manual_count}}/{{total_count}})</span>Automated Cases<span class="red">{{auto_count|percentage:total_count}}({{auto_count}}/{{total_count}})</span>Manual/Automated<span class="red">{{both_count|percentage:total_count}}({{both_count}}/{{total_count}})</span></div>
	</div>
	<table class="list border-bottom" cellpadding="0" cellspacing="0" border="0" id="id_table_report">
		<thead>
			<tr>
				<th align="left">Build</th>
				<th align="left" width="100">Plan</th>
				<th align="left" width="100">Run</th>
				<th align="left" width="100">Case-Run</th>
				<th align="left" width="150">Passed case-run</th>
				<th align="left" width="150">Failed case-run</th>
			</tr>
		</thead>
		<tbody>
			{% for build in builds %}
			<tr class="{% cycle 'even' 'odd' %}">
				<td>
					<input type="hidden" name="build_id" value="{{ build.pk }}" />
					{% if build.plans_count %}<a class="build_link"  href="{% url "report-custom-details" %}">{% endif %}{{ build }}</a>
				</td>
				<td valign="top">{{ build.plans_count|default_if_none:0 }}</td>
				<td valign="top">
				{% if build.runs_count %}
					<a href="{% url "runs-all" %}?product={{ build.product.pk }}&build={{ build.pk }}&product_version={{ REQUEST_CONTENTS.build_run__product_version }}">{{ build.runs_count }}</a>
				{% else %}{{ build.runs_count|default_if_none:0 }}{% endif %}
				</td>
				<td valign="top">{{ build.case_runs_count|default_if_none:0 }}</td>
				<td valign="top">
				<div class="progress-bar">
					<div class="progress-inner" style="background-position:0px 0px; width:100%;">
						<div class="progress-passed" style="width:{{ build.passed_case_runs_percent|floatformat:1 }}%; float:left;">&nbsp;</div>
					</div>
					<div class="percent" style="left:35%;">{{ build.passed_case_runs_percent|floatformat:1 }}% ({{ build.passed_case_runs_count }})</div> </div>
				</td>
				<td valign="top">
				<div class="progress-bar">
					<div class="progress-inner" style="background-position:0px 0px; width:100%;">
						<div class="progress-failed" style="width:{{ build.failed_case_runs_percent|floatformat:1 }}%; float:left;">&nbsp;</div>
					</div>
					<div class="percent" style="left:35%;">{{ build.failed_case_runs_percent|floatformat:1 }}% ({{ build.failed_case_runs_count }})</div>
				</div>
				</td>
			</tr>
			{% endfor %}
		</tbody>
	</table>
	{% else %}
	<table class="list border-bottom" cellpadding="0" cellspacing="0" border="0">
		<thead>
			<tr>
				<th align="left" class="text">Build</th>
				<th align="left" class="number" width="100">Plan</th>
				<th align="left" class="number" width="100">Run</th>
				<th align="left" class="number" width="100">Case-Run</th>
				<th align="left" class="number" width="150">Passed case-run</th>
				<th align="left" class="number" width="150">Failed case-run</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	{% endif %}
</div>
{% endblock %}
