[% IF NOT results.size %]
<div class="span2 alert alert-info">The job queue is empty.</div>
[% ELSE %]
<div class="alert alert-info">
  Backends: [% num_backends | html_entity %] /
  Workers: [% tot_workers | html_entity %] /
  Running: [% jq_running | html_entity %] /
  Backlog: [% jq_backlog | html_entity %] /
  Done: [% jq_done | html_entity %] /
  Errored: [% jq_errored | html_entity %] /
  Stale: [% jq_stale | html_entity %] /
  Total: [% jq_total | html_entity %]
</div>
<table class="table table-bordered table-condensed table-hover nd_floatinghead">
  <thead>
    <tr>
      <th class="nd_center-cell">Backend</th>
      <th class="nd_center-cell">Action</th>
      <th class="nd_center-cell">Device / Info</th>
      <th class="nd_center-cell">Submitted By</th>
      <th class="nd_center-cell">Status</th>
      <th class="nd_center-cell">Duration</th>
      <th class="nd_center-cell">Details</th>
      <th class="nd_center-cell">Cancel</th>
    </tr>
  </thead>
  <tbody>
    [% FOREACH row IN results %]
    <tr
      [% ' class="nd_jobqueueitem success"' IF row.status == 'done' %]
      [% ' class="nd_jobqueueitem error"'   IF row.status == 'error' %]
      [% ' class="nd_jobqueueitem info"'    IF (row.status == 'queued' AND row.backend != '') %]
      data-content="[% row.log | html_entity %]"
    >
      <td class="nd_center-cell">[% row.backend | html_entity %]</td>

      <td class="nd_center-cell">
        [% FOREACH word IN row.action.split('_') %]
        [% word.ucfirst | html_entity %]&nbsp;
        [% END %]
      </td>

      <td class="nd_center-cell">
        [% IF row.device %]
          [% IF row.action == 'discover' AND row.status == 'error' %]
          <a href="[% uri_for('/') | none %]?device=[% row.device | uri %]">[% row.device | html_entity %]</a>
          [% ELSE %]
          <a href="[% uri_for('/device') | none %]?q=[% row.device | uri %]">[% row.target.dns || row.device | html_entity %]</a>
          [% END %]
        [% ELSE %]
        <span title="[% row.log | html_entity %]">[% row.log.substr(0, 40) | html_entity %][% '...' IF row.log AND row.log.length > 40 %]</span>
        [% END %]
      </td>

      <td class="nd_center-cell">[% row.username | html_entity %]</td>

      [% IF (row.status == 'queued' AND row.backend != '') %]
      <td class="nd_center-cell">Running</td>
      [% ELSE %]
      <td class="nd_center-cell">[% row.status.ucfirst | html_entity %]</td>
      [% END %]

      <td class="nd_center-cell">[% row.duration | html_entity %]</td>

      <td class="nd_center-cell">
        <button class="btn nd_jobqueue-extra" data-extra="nd_jobqueue_[% row.job | html_entity %]"><i class="icon-plus"></i></button>
      </td>

      <td class="nd_center-cell">
        <input data-form="del" name="job" type="hidden" value="[% row.job | html_entity %]">
        <button class="btn nd_adminbutton" name="del" type="submit"><i class="icon-trash text-error"></i></button>
      </td>
    </tr>

    <tr id="nd_jobqueue_[% row.job | html_entity %]" class="nd_collapse-pre-hidden">
      <td colspan="8">
        <table>
        <tr><td class="span2">ID</td><td> [% row.job | html_entity %] </td></tr>
        <tr><td>Entered</td><td> [% row.entered_stamp | html_entity %] </td></tr>
        <tr><td>Started</td><td> [% row.started_stamp | html_entity %] </td></tr>
        <tr><td>Finished</td><td> [% row.finished_stamp | html_entity %] </td></tr>
        <tr><td>Device IP</td><td> [% row.device | html_entity %] </td></tr>
        <tr><td>Port</td><td> [% row.port | html_entity %] </td></tr>
        <tr><td>Subaction</td><td> [% row.subaction | html_entity %] </td></tr>
        <tr><td>User IP</td><td> [% row.userip | html_entity %] </td></tr>
        <tr><td>Device Key</td><td> [% row.device_key | html_entity %] </td></tr>
        <tr><td>Log</td><td> [% row.log | html_entity %] </td></tr>
        </table>
      </td>
    </tr>
    [% END %]
  </tbody>
</table>
[% END %]

