[% WRAPPER layout.tt title="Jobset $project.name:$jobset.name" %]
[% PROCESS common.tt %]


[% BLOCK renderJobsetInput %]
  <tr class="input [% extraClass %]" [% IF id %]id="[% id %]"[% END %]>
    <td>
      <tt>[% HTML.escape(input.name) %]</tt>
    </td>
    <td>
      [% INCLUDE renderSelection curValue=input.type param="$baseName-type" options=inputTypes %]
    </td>
    <td class="inputalts" id="[% baseName %]">
      [% FOREACH alt IN input.jobsetinputalts %]
        <tt class="inputalt">
          [% IF input.type == "string" %]
            "[% HTML.escape(alt.value) %]"
          [% ELSE %]
            [% HTML.escape(alt.value) %]
          [% END %]
        </tt>
      [% END %]
    </td>
  </tr>
[% END %]


[% BLOCK renderJobsetInputs %]
  <h3>Inputs</h3>
  <table class="tablesorter table table-striped table-condensed">
    <thead>
      <tr><th>Input name</th><th>Type</th><th>Values</th></tr>
    </thead>
    <tbody class="inputs">
      [% FOREACH input IN jobset.jobsetinputs %]
        [% INCLUDE renderJobsetInput input=input baseName="input-$input.name" %]
      [% END %]
    </tbody>
  </table>
[% END %]


<ul class="nav nav-tabs">
  <li class="active"><a href="#tabs-evaluations" data-toggle="tab">Evaluations</a></li>
  [% IF jobset.errormsg %]
    <li><a href="#tabs-errors" data-toggle="tab"><img src="/static/images/error_16.png" /> Evaluation errors</a></li>
  [% END %]
  <li><a href="#tabs-status" data-toggle="tab">Job status</a></li>
  <li><a href="#tabs-jobs" data-toggle="tab">Jobs</a></li>
  <li><a href="#tabs-setup" data-toggle="tab">Configuration</a></li>
</ul>

<div id="generic-tabs" class="tab-content">

  <div id="tabs-evaluations" class="tab-pane active">

    <table class="info-table">
      <tr>
        <th>Last checked:</th>
        <td>
          [% IF jobset.lastcheckedtime %]
            [% INCLUDE renderDateTime timestamp = jobset.lastcheckedtime %], [% IF jobset.errormsg %]<em class="text-warning">with errors!</em>[% ELSE %]<em>no errors</em>[% END %]
          [% ELSE %]
            <em>never</em>
          [% END %]
        </td>
      </tr>
      <tr>
        <th>Last evaluation:</th>
        <td>
          [% IF latestEval %]
            [% INCLUDE renderDateTime timestamp = latestEval.timestamp %]
          [% ELSE %]
            <em>never</em>
          [% END %]
        </td>
      </tr>
      [% IF jobset.triggertime %]
      <tr>
        <th>Evaluation pending since:</th>
        <td>[% INCLUDE renderDateTime timestamp = jobset.triggertime %]</td>
      </tr>
      [% END %]
    </table>

    <br/>

    [% IF evals.size() > 0 %]
      [% INCLUDE renderEvals linkToAll=c.uri_for(c.controller('Jobset').action_for('evals'), [project.name, jobset.name]) %]
    [% END %]

  </div>

  [% INCLUDE makeLazyTab tabName="tabs-status" uri=c.uri_for('/jobset' project.name jobset.name "status-tab") %]

  [% IF jobset.errormsg %]
    <div id="tabs-errors" class="tab-pane">
      <p>Errors occurred at [% INCLUDE renderDateTime timestamp=jobset.errortime %].</p>
      <pre class="alert alert-error">[% HTML.escape(jobset.errormsg) %]</pre>
    </div>
  [% END %]

  <div id="tabs-setup" class="tab-pane">

    <a class="btn pull-right" href="[% c.uri_for('/jobset' project.name jobset.name "edit") %]"><i class="icon-edit"></i> Edit</a>

    <table class="info-table">
      <tr>
        <th>Description:</th>
        <td>[% HTML.escape(jobset.description) %]</td>
      </tr>
      <tr>
        <th>Nix expression:</th>
        <td>
          <tt>[% HTML.escape(jobset.nixexprpath) %]</tt> in input
          <tt>[% HTML.escape(jobset.nixexprinput) %]</tt>
        </td>
      </tr>
      <tr>
        <th>Enabled:</th>
        <td>[% jobset.enabled ? "Yes" : "No" %]</td>
      </tr>
      <tr>
        <th>Enable email notification:</th>
        <td>[% jobset.enableemail ? "Yes" : "No" %]</td>
      </tr>
      <tr>
        <th>Email override:</th>
        <td>[% HTML.escape(jobset.emailoverride) %]</td>
      </tr>
      <tr>
        <th>Number of builds to keep:</th>
        <td>[% jobset.keepnr %]</td>
      </tr>
    </table>

    [% INCLUDE renderJobsetInputs %]
  </div>

  [% INCLUDE makeLazyTab tabName="tabs-jobs" uri=c.uri_for('/jobset' project.name jobset.name "jobs-tab") %]

</div>

[% END %]
