<%
    build_test_files = @test_files || []
%>
<% if @build.is_parallel%>
   <% ui_test_duration = 0 %>
    <% build_test_files.each do |bf|
      ui_test_duration += (bf.duration || 0)
    end %>
<% end %>	

				
<div style="margin-top: 5px;">

  <% unless @build.incomplete? %>

      <div class="progress hidden-print">

        <% @build.stage_timings.each_with_index do |entry, idx| %>
            <div id="bar_<%= idx %>" class="progress-bar <%= bar_class(@build, entry, idx) %>" data-toggle="tooltip" title="<%= entry[:stage_name] %> :  <%= entry[:duration].to_s %>" data-placement="bottom" style="width: <%= entry[:percentage]%>%;"></div>
        <% end %>

        <!-- bar-success  bar-warning bar-info  bar-inverse bar-danger-->
      </div>
  <% end %>

</div>
  
  <div style="margin-top: 8px;">  	
		<div class="row">
			<div class="col-sm-7 col-md-3" >
				<%= I18n.t(:started)%>:
				<b><span data-localtime-format="yyyy-MM-dd HH:mm"><%= @build.start_time.iso8601 rescue nil %></span></b>
			</div>
			<div class="col-sm-5 col-md-3" >
				<%= I18n.t(:duration) %>:
        <% if @build.incomplete? %>
            <b><%= format_seconds(@build.elapsed_time_in_progress) rescue nil %></b>
        <% else %>
            <b><%= format_seconds(@build.duration) rescue nil %></b>
        <% end %>				
			</div>			
			<% if @build.is_parallel && !@build.is_load_testing && !@build.incomplete? && ui_test_duration > 1 %>			
			<div class="col-sm-12 col-md-3" >
			  <%= I18n.t(:time_saved_by_parallel) %>:
        <b><%= ( ((ui_test_duration - @build.duration) / ui_test_duration) * 100 ).round(1) rescue nil %>%</b>
			</div>
			<div class="col-sm-12 col-md-2" >
			  <%= I18n.t(:false_alarms) %>:
			  
	    	<% build_false_alarms = (@build_false_alarms || @build.false_alarms) rescue [] %>
   		  <% if build_false_alarms.count == 0%>
          <b class="green"><%= build_false_alarms.count %></b>
        <% else %> 
          <b class="orange"><a href="javascript:void(0); " onclick='$("#false_alarms_modal").modal("show");'>
			  <%= build_false_alarms.count %></a> </b>
        <% end %>
			</div>
      
			<% elsif @build.is_parallel && @build.is_load_testing %>
				<div class="col-sm-12 col-md-6" >
        <% if !@build.load_server_url.blank? %>
          <%= I18n.t(:app_server) %>: &nbsp;<%= link_to @build.load_server_url, @build.load_server_url, :target => "_blank" %>
        <% end %>
			  </div>
			<% end %>
		</div>
  </div>

  <!-- running build_runner output -->  
  <%= partial "/builds/prepare_builder".to_sym %>		
  
  <!-- Change Log -->		
  <%= partial "/builds/change_log".to_sym %>			

 <!-- artifacts -->
  <% if !@build.incomplete? %>
      <% unless @build.custom_artifacts.empty? %>
          <div class="complete section_closed hidden-print" >
            <div class="section_header" onclick="toggle_section(this.parentNode)"><%= I18n.t(:build_artifacts) %></div>
            <div class="section_content">
              <% @build.custom_artifacts.each do |artifact| %>
                  <!-- TODO  folder linked on the build page does not work -->
                  <% next if File.directory?(@build.artifact(artifact)) %>
                  <div class="artifact">

                    <% if File.directory?(@build.artifact(artifact)) %>
                        <%= raw folder_html_icon %>
                        <a href="/artifacts/<%= @build.id %>/<%= artifact %>/index.html" target="_blank"><%= artifact %></a>
                    <% else %>
                        <%= raw file_icon(artifact) %>
												
												<% if is_binary_file?(artifact) %>
                        <a download target="_blank" href="/builds/<%= @build.id %>/artifact/<%= artifact %>"><%= @build.artifact_for_display(artifact) %></a>
                        <% else %>									
                        <a href="/builds/<%= @build.id %>/artifact/<%= artifact %>"><%= @build.artifact_for_display(artifact) %></a>												
												<% end %>
												
												<span class="hint"><%= ((File.stat(@build.artifact(artifact)).size / 1024).to_s + 'KB') rescue "" %></span>
                    <% end %>
                  </div>
              <% end %>
            </div>
          </div>
      <% end %>
  <% end %>


  <% if @ui_test_files && @ui_test_files.any? %>
      <div class="section_closed">
        <div class="section_header" onclick="toggle_section(this.parentNode)"><%= "UI Test files in order" %></div>
        <div class="section_content">
          <ol>
            <% @ui_test_files.each do |test_file| %>
                <li><%= test_file %> </li>
            <% end %>
          </ol>
        </div>
      </div>
  <% end %>
  
  <% if @build.is_parallel && @build.is_load_testing %>
      <% if @build.incomplete? %>
        <%= partial "/builds/load_test_results_inprogress".to_sym %>
      <% else %>
        <%= partial "/builds/load_test_results_completed".to_sym %>      
      <% end %>
  <% end %>
  
  <!-- UI test results -->
  <%= partial "/builds/ui_test_results".to_sym %>

  <div class="hidden-print <%= @build.incomplete? ? 'section_open' : 'section_closed' %>">
    <div class="section_header" onclick="toggle_section(this.parentNode)"><%= I18n.t(:build_log)%></div>
    <div class="section_content">
			
			<% if @build.builder_log_file && File.exist?( @build.builder_log_file )%>
		     <div class="logfile formatted"><%= raw format_build_log(@build.builder_log_output) %></div>						
			<% else %>
				<% @build.build_step_executions.each do |step| %>
					<h4><%= step.task_name %></h4>
		      <div class="logfile formatted"><%= raw format_build_log(step.log_output) %></div>			
				<% end %>
			<% end %>
			
    </div>
  </div>


  <% if @build.backtrace %>
      <h5>Builder Error Trace</h5>

      <div style="max-height: 400px; overflow:scroll; font-size: 11px;">
        <pre><%= raw @build.backtrace.split(",").join("\n") %></pre>
      </div>
  <% end %>
</div>

