<%!

    from crab import CrabEvent, CrabStatus

%><html>
    <head>
      <title>Crab Report</title>
    </head>
    <body>
        ${summary('error', 'Jobs with Errors')}
        ${summary('warning', 'Jobs with Warnings')}
        ${summary('ok', 'Successful Jobs')}

<%def name="summary(section, title)">
<%
    jobs = getattr(report, section)
%>
% if jobs:
        <h1>${title | h}</h1>

        <table>
% for id_ in jobs:
<%
    info = report.info[id_]
%>
            <tr>
                <td>${info['host'] | h}</td>
                <td>${info['user'] | h}</td>
                <td><a href="#job_${id_ | h}">${info['title'] | h}</a></td>
            </tr>
% endfor
        </table>
% endif
</%def>

        <h1>Event Listing</h1>

% for id_ in set.union(report.error, report.warning, report.ok):
<%
    info = report.info[id_]
%>
        <h2 id="job_${id_ | h}">
            <a href="${base_url | h}/job/${id_ | h}">
                ${info['user'] | h} @
                ${info['host'] | h } :
                ${info['title'] | h}
        </a></h2>

        <table>
% for event in report.events[id_]:
            <tr>
                <td>${CrabEvent.get_name(event['type']) | h}</td>
% if event['type'] == CrabEvent.FINISH:
                <td><a href="${base_url | h}/job/${id_ | h}/output/${event['eventid'] | h}">
                    ${CrabStatus.get_name(event['status']) | h}
                </a></td>
% else:
                <td>${CrabStatus.get_name(event['status']) | h}</td>
% endif
                <td>${event['datetime'] | h}</td>
% if event['type'] == CrabEvent.FINISH and report.stdout:
                <td>
%     if event['eventid'] in report.stdout and report.stdout[event['eventid']]:
                    <pre>${report.stdout[event['eventid']].strip() | h}</pre>
%     endif
%     if event['eventid'] in report.stderr and report.stderr[event['eventid']]:
%         if event['eventid'] in report.stdout and report.stdout[event['eventid']]:
                    <p><b>Standard error:</b></p>
%         endif
                    <pre>${report.stderr[event['eventid']].strip() | h}</pre>
%     endif
                </td>
% endif
            </tr>
% endfor
        </table>
% endfor
    </body>
</html>
