<%!
    from crab.util.string import mergelines
    from crab.util.web import abbr

    scripts = ["dyn:crabutil", "joblist"]
%>
<%inherit file="base.html"/>

<%def name="joblistrow(job)" filter="mergelines">
    <tr id="row_${job["id"] | h}">
        <td class="statuscell"><a href="/job/${job["id"] | h}/output" id="status_${job["id"] | h}" class="status_unknown">Loading</a></td>
% if job.get("host") is not None:
        <td class="linkcell"><a href="/host/${job['host']}" id="host_${job["id"] | h}">${job["host"] | h}</a></td>
% else:
        <td id="host_${job["id"] | h}">&nbsp;</td>
% endif
% if job.get('user') is not None:
        <td class="linkcell"><a href="/user/${job['user']}" id="user_${job["id"] | h}">${job['user'] | h}</a></td>
% else:
        <td id="user_${job["id"] | h}">&nbsp;</td>
% endif
% if job.get('crabid') is not None:
        <td class="linkcell"><a href="/job/${job['id'] | h}" id="crabid_${job["id"] | h}">${job["crabid"] | h}</a></td>
% else:
        <td class="status_unknown" id="crabid_${job["id"] | h}">Unspecified</td>
% endif
        <td class="linkcell"><a href="/job/${job["id"] | h}" id="command_${job["id"] | h}">
% if job.get('command') is not None:
            ${job["command"] | abbr}
% else:
            &nbsp;
% endif
        </a></td>
        <td id="reliability_${job["id"] | h}" class="status_unknown">Loading</td>
    </tr>
</%def>

<h2>Dashboard</h2>

<table id="joblist">
    <thead id="joblisthead">
    <tr>
        <th><a href="#" id="headingstatus">Status</a></th>
        <th><a href="#" id="headinghost">Host</a></th>
        <th><a href="#" id="headinguser">User</a></th>
        <th><a href="#" id="headingcrabid">Job ID</a></th>
        <th><a href="#" id="headingcommand">Command</a></th>
        <th><a href="#" id="headingreliability">Reliability</a></th>
    </tr>
    </thead>
    <tbody id="joblistbody">
% for job in jobs:
    ${joblistrow(job)}
% endfor
    </tbody>
</table>

<script>
<% job = {'id': 'XXX'} %>
var joblistrowtemplate = '${joblistrow(job)}';
</script>

<ul id="service_status"></ul>

<p>
    <a href="#" id="command_refresh">Refresh.</a>
    <span class="meta_info">
        Last refreshed <span id="last_refresh">Never</span>
    </span>
</p>
