<% if current_user.andand.is_active %>
  <div>
    <strong>Recent jobs</strong>
    <%= link_to raw("Show all jobs &rarr;"), jobs_path, class: 'pull-right' %>
    <% if not current_user.andand.is_active or @my_jobs.empty? %>
      <br/>(None)
    <% else %>
      <table class="table table-bordered table-condensed table-fixedlayout">
	<colgroup>
          <col width="28%" />
          <col width="38%" />
          <col width="7%" />
          <col width="15%" />
          <col width="12%" />
	</colgroup>

        <tr>
	  <th>Script</th>
	  <th>Output</th>
	  <th>Log</th>
	  <th>Age</th>
	  <th>Status</th>
	</tr>

        <% @my_jobs[0..6].each do |j| %>
          <tr>
            <td>
              <small>
		<%= link_to j.script[0..31], job_path(j.uuid) %>
              </small>
            </td>

	    <td>
	      <small>
		<% if j.success %>

		  <a href="<%= collection_path(j.output) %>">
		    <% Collection.limit(1).where(uuid: j.output).each do |c|
			 c.files.each do |file| %>
		      <%= file[0] == '.' ? file[1] : "#{file[0]}/#{file[1]}" %>
		    <% end %>
		<% end %>
		</a>

	<% end %>
	</small>
</td>

<td>
  <small>
    <% if j.log %>
      <a href="<%= collection_path(j.log) %>">Log</a>
    <% end %>
  </small>
</td>

<td>
  <small>
    <%= raw(distance_of_time_in_words(j.created_at, Time.now).sub('about
','~').sub(' ','&nbsp;')) if j.created_at %>
  </small>
</td>

<td>
  <% if j.success %>
    <span class="label label-success">finished</span>
  <% elsif j.success == false %>
    <span class="label label-danger">failed</span>
  <% elsif j.running and j.started_at and not j.finished_at %>
    <% percent_total_tasks = 100 / (j.tasks_summary[:running] + j.tasks_summary[:done] + j.tasks_summary[:todo]) rescue 0 %>
    <div class="progress" style="margin-bottom: 0">
      <div class="bar bar-success" style="width: <%= j.tasks_summary[:done] * percent_total_tasks rescue 0 %>%;"></div>
      <div class="bar" style="width: <%= j.tasks_summary[:running] * percent_total_tasks rescue 0 %>%; opacity: 0.3"></div>
    </div>
  <% else %>
    <span class="label">queued</span>
  <% end %>
</td>

</tr>
<% end %>
</table>
<% end %>
</div>

<div>
  <strong>Recent pipeline instances</strong>
  <%= link_to raw("Show all pipeline instances &rarr;"), jobs_path, class: 'pull-right' %>
  <% if not current_user.andand.is_active or @my_pipelines.empty? %>
    <br/>(None)
  <% else %>
    <table class="table table-bordered table-condensed table-fixedlayout">
      <colgroup>
        <col width="73%" />
        <col width="15%" />
        <col width="12%" />
      </colgroup>

      <tr>
	<th>Pipeline template</th>
	<th>Age</th>
	<th>Status</th>
      </tr>

      <% @my_pipelines[0..6].each do |p| %>
        <tr>
          <td>
            <small>
	      <% PipelineTemplate.limit(1).where(uuid: p.pipeline_template_uuid).each do |i| %>
		<%= link_to i.name, pipeline_instance_path(p.uuid) %>
	      <% end %>
            </small>
          </td>

          <td>
            <small>
	      <%= raw(distance_of_time_in_words(p.created_at, Time.now).sub('about
','~').sub(' ','&nbsp;')) if p.created_at %>
            </small>
          </td>

          <td>
            <% if p.success %>
              <span class="label label-success">finished</span>
            <% elsif p.success == false %>
              <span class="label label-danger">failed</span>
            <% elsif p.active %>
              <span class="label label-info">running</span>
            <% else %>
              <span class="label">queued</span>
            <% end %>
          </td>

        </tr>
      <% end %>
    </table>
  <% end %>
</div>

<div>
  <strong>Recent collections</strong>
  <%= link_to raw("Show all collections &rarr;"), collections_path, class: 'pull-right' %>
  <% if not current_user.andand.is_active or @my_collections.empty? %>
    <br/>(None)
  <% else %>
    <table class="table table-bordered table-condensed table-fixedlayout">
      <colgroup>
        <col width="73%" />
        <col width="27%" />
      </colgroup>

      <tr>
	<th>Contents</th>
	<th>Age</th>
      </tr>

      <% @my_collections[0..6].each do |c| %>
        <tr>
          <td>
            <small>
	      <a href="<%= collection_path(c.uuid) %>">
		<% c.files.each do |file| %>
		  <%= file[0] == '.' ? file[1] : "#{file[0]}/#{file[1]}" %>
		<% end %>
	      </a>
            </small>
          </td>
          <td>
            <small>
	      <%= raw(distance_of_time_in_words(c.created_at, Time.now).sub('about
','~').sub(' ','&nbsp;')) if c.created_at %>
            </small>
          </td>
        </tr>
      <% end %>
    </table>
  <% end %>
</div>

<% else %>
  <%= image_tag "dax.png", style: "max-width=40%" %>
<% end %>