<%!
    from crab import CrabStatus
    from crab.util.web import abbr

    scripts = ["jobevents"]
%>
<%inherit file="base.html"/>

<%block name="links">
<a href="/host/${info['host'] | h}">${info['host'] | h}</a>
<a href="/user/${info['user'] | h}">${info['user'] | h}</a>
% if info['crabid'] is not None:
<span>${info['crabid'] | h}</span>
% else:
<span>${info['command'] | abbr}</span>
% endif
</%block>


<h2>Job Information</h2>

<table>
<!--
    <tr>
        <th>Host</th>
        <td>${info["host"] | h}</td>
    </tr>
    <tr>
        <th>User</th>
        <td>${info["user"] | h}</td>
    </tr>
-->
% if info["crabid"] != None:
    <tr>
        <th>Job ID</th>
        <td>${info["crabid"] | h}</td>
    </tr>
% endif
    <tr>
        <th>Command</th>
        <td>${info["command"] | h}</td>
    </tr>
     <tr>
        <th>Schedule</th>
% if info["time"] != None:
        <td>${info["time"] | h}</td>
% else:
        <td class="status_unknown">Unknown</td>
% endif
    </tr>
% if info["timezone"] != None:
    <tr>
        <th>Time zone</th>
        <td>${info["timezone"] | h}</td>
    </tr>
% endif
% if info["installed"] != None:
    <tr>
        <th>Installed</th>
        <td>${info["installed"] | h}</td>
    </tr>
% endif
% if info["deleted"] != None:
    <tr>
        <th>Deleted</th>
        <td>${info["deleted"] | h}</td>
    </tr>
% endif
% if config is not None:
%     if config['graceperiod'] is not None:
    <tr>
        <th>Grace period</th>
        <td>${config["graceperiod"] | h} minutes</td>
    </tr>
%     endif
%     if config['timeout'] is not None:
    <tr>
        <th>Time-out</th>
        <td>${config["timeout"] | h} minutes</td>
    </tr>
%     endif
% endif
% if notification is not None and len(notification):
    <tr>
        <th>Notifications</th>
        <td>${len(notification)} explicit
%     if len(notification) == 1:
            notification
%     else:
            notifications
%     endif
        </td>
    </tr>
% endif
% if config is not None:
%     if config['success_pattern'] is not None:
    <tr>
        <th>Success pattern</th>
        <td>${config["success_pattern"] | h}</td>
    </tr>
%    endif
%     if config['warning_pattern'] is not None:
    <tr>
        <th>Warning pattern</th>
        <td>${config["warning_pattern"] | h}</td>
    </tr>
%    endif
%     if config['fail_pattern'] is not None:
    <tr>
        <th>Failure pattern</th>
        <td>${config["fail_pattern"] | h}</td>
    </tr>
%    endif
% endif
</table>

<p>
    <a href="/job/${id | h}/config"><span class="fa fa-cog"></span> Edit configuration.</a>
    <a href="/job/${id | h}/notify"><span class="far fa-envelope"></span> Edit notifications.</a>
</p>
% if status['status'] is not None and not CrabStatus.is_ok(status['status']):
<p>
    <a href="/job/${id | h}/clear"><span class="fa fa-check-circle"></span> Clear status.</a> (${CrabStatus.get_name(status['status']) | h})
</p>
% endif
% if config is not None and config['inhibit']:
<p>
    <a href="/job/${id | h}/uninhibit"><span class="fa fa-play"></span> Resume inhibited job.</a>
</p>
% endif

% if config is not None:
%     if config["note"] is not None:
<h2>Notes</h2>
%         for noteline in config["note"].splitlines():
${noteline | h}</br>
%         endfor
%    endif
% endif


<h2>Job History</h2>

<form id="eventsform">
<p>
<select name="limit">
<option value="10">10 events</option>
<option value="20">20 events</option>
<option value="50">50 events</option>
<option value="100" selected="selected">100 events</option>
<option value="200">200 events</option>
<option value="500">500 events</option>
<option value="1000">1000 events</option>
</select>
&nbsp; &nbsp;
<input name="unfiltered" type="checkbox" />
Show all
&nbsp; &nbsp;
<a href="#" id="eventsprev"><span class="fa fa-backward"></span> Previous</a>
<a href="#" id="eventslast"><span class="fa fa-fast-forward"></span> Last</a>
</p>
</form>
<script>
var jobidnumber = '${id | h}';
</script>



<table>
    <thead>
    <tr>
        <th>Status</th>
        <th>Date and Time</th>
        <th>Command</th>
        <th>Duration</th>
    </tr>
    </thead>
    <tbody id="jobevents">
<%include file="jobevents.html" />
    </tbody>
</table>
