[% WRAPPER layout.tt title="Machine status" %]
[% PROCESS common.tt %]
[% USE format %]

<table class="table table-condensed table-striped">
  <thead>
    <tr>
      <th>Job</th>
      <th>System</th>
      <th>Build</th>
      <th>Step</th>
      <th>What</th>
      <th>Since</th>
    </tr>
  </thead>
  [% FOREACH m IN machines %]
    [% name = m.key ? stripSSHUser(m.key) : "localhost" %]
    <thead>
      <tr>
        <th colspan="6">
          <tt [% IF m.value.disabled %]style="text-decoration: line-through;"[% END %]>[% INCLUDE renderMachineName machine=m.key %]</tt>
          [% IF m.value.systemTypes %]
            <span class="muted" style="font-weight: normal;">
              ([% comma=0; FOREACH system IN m.value.systemTypes %][% IF comma; %], [% ELSE; comma = 1; END %]<tt>[% system %]</tt>[% END %])
            </span>
          [% END %]
          [% IF m.value.nrStepsDone %]
            <span class="muted" style="font-weight: normal;">
              ([% m.value.nrStepsDone %] steps done, [% f = format("%.1f"); f(m.value.avgStepBuildTime) %] s/step)
            </span>
          [% END %]
        </th>
      </tr>
    </thead>
    <tbody>
      [% idle = 1 %]
      [% FOREACH step IN steps %]
        [% name2 = step.machine ? stripSSHUser(step.machine) : "localhost" %]
        [% IF name == name2 %]
          [% idle = 0 %]
          <tr>
            <td><tt>[% INCLUDE renderFullJobName project=step.project jobset=step.jobset job=step.job %]</tt></td>
            <td><tt>[% step.system %]</tt></td>
            <td><a href="[% c.uri_for('/build' step.build) %]">[% step.build %]</a></td>
            <td>[% IF step.busy >= 30 %]<a class="row-link" href="[% c.uri_for('/build' step.build 'nixlog' step.stepnr 'tail') %]">[% step.stepnr %]</a>[% ELSE; step.stepnr; END %]</td>
            <td><tt>[% step.drvpath.match('-(.*)').0 %]</tt></td>
            <td style="width: 10em">[% INCLUDE renderDuration duration = curTime - step.starttime %] </td>
          </tr>
        [% END %]
      [% END %]
      [% IF idle == 1 %]
        <tr><td colspan="6">Idle</td></tr>
      [% END %]
    </tbody>
  [% END %]
</table>

[% END %]