{% extends "base.html" %}

{% block title %}ReciPy - Run Details
  {% if active_page == 'latest_run' %} - Latest Run{% endif %}
{% endblock %}

{% block content %}
{{ super() }}

<div class="row">
  <div class="col-md-12">
    <div class="top-buffer">
      <ol class="breadcrumb">
        <li>
          <a href="{{ url_for('index', query=query) }}">
            <i class="glyphicon glyphicon-arrow-left"></i>
          </a>
          <a href="{{ url_for('index', query=query) }}">
            back to
            {% if query | length > 0 %} search results
            {% else %} runs
            {% endif %}
          </a>
        </li>
      </ol>
    </div>
  </div>
</div>

<div class="row">
  <div class="col-md-6">
    <h3>Run {{ run.unique_id | string | highlight(query) | safe }}</h3>
  </div>
  <div class="col-md-2 col-md-offset-4">
    <div class="pull-right align-with-header">
      <form role="form" action="{{ url_for('runs2json') }}" method="post">
        <input type="hidden" name="run_ids" value="[{{ run.eid }}]"></input>
        <button type="submit" class="btn btn-info">Save as JSON</button>
      </form>
    </div>
  </div>
</div>

<div class="row">
  <div class="col-md-12">
    <table class="table table-striped table-condensed">
      <tr>
        <td class="col-md-1">Date</td>
        <td>{{ run.date | datetimefilter }}</td>
      </tr>
      <tr>
        <td class="col-md-1">Author</td>
        <td>{{ run.author | highlight(query) | safe }}</td>
      </tr>
      <tr>
        <td class="col-md-1">Command</td>
        <td>
          <code>{{ run.command | highlight(query) | safe }}</code>
        </td>
      </tr>
      <tr>
        <td class="col-md-1">Script</td>
        <td>
          <code>{{ run.script | highlight(query) | safe }}</code>
        </td>
      </tr>
      {% if run.command_args|length > 0 %}
      <tr>
        <td class="col-md-1">Command line arguments</td>
        <td>
          <code>{{ run.command_args | highlight(query) | safe }}</code>
        </td>
      </tr>
      {% endif %}
      <tr>
        <td class="col-md-1">Inputs</td>
        <td>
          {% if run.inputs | length > 0 %}
            <code>{{ run.inputs | join('</code>,
            <code>') | highlight(query) | safe }}
          {% else %}
            <em>none</em>
          {% endif %}
        </td>
      </tr>
      <tr>
        <td class="col-md-1">Outputs</td>
        <td>
          {% if run.outputs | length > 0 %}
            <code>{{ run.outputs | join('</code>,
            <code>') | highlight(query) | safe }}</code>
          {% else %}
            <em>none</em>
          {% endif %}
        </td>
      </tr>
      {% if run.exception %}
      <tr>
        <td class="col-md-1">Exception</td>
        <td>
          <i>{{ run.exception.type }}</i> <code>{{ run.exception.message }}</code>
          {% if run.exception.traceback %}
          <br /><strong>Traceback:</strong>
          <pre>{{ run.exception.traceback | highlight(query) | safe }}</pre>
          {% endif %}
        </td>
      </tr>
      {% endif %}
      <tr>
        <td class="col-md-1">Environment</td>
        <td>{{ run.environment | join(' ') | highlight(query) | safe }}</td>
      </tr>
      <tr>
        <td class="col-md-1">Notes</td>
        <td>
          <form class="form-inline" role="form" action="{{ url_for('annotate') }}" method="post">
            <div class="input-group">
              <textarea class="form-control" id="notes" name="notes" rows="5" cols="80">{{ run.notes }}</textarea>
              {{ annotateRunForm.run_id(value=run.eid) }}
            </div>
            <div class="input-group bottom-box">
              <button type="submit" class="btn btn-info">Save notes</button>
            </div>
          </form>
        </td>
      </tr>
    </table>
  </div>
</div>

{% if run.gitcommit %}
<div class="row">
  <div class="col-md-12">
    <h3>Git</h3>
  </div>
</div>

<div class="row">
  <div class="col-md-12">
    <table class="table table-striped table-condensed">
      <tr>
        <td class="col-md-1">Git Repo</td>
        <td>
          <code>{{ run.gitrepo | highlight(query) | safe }}</code>
          {% if run.gitorigin and run.gitorigin | length > 0 %}
          (online: <a href="{{ run.gitorigin | gitorigin2url | safe }}">{{ run.gitorigin | gitorigin2url | safe }}</a>)
          {% endif %}
        </td>
      </tr>
      <tr>
        <td class="col-md-1">Git Origin</td>
        <td>
          {{ run.gitorigin | highlight(query) | safe }}
        </td>
      </tr>
      <tr>
        <td class="col-md-1">Git Commit</td>
        <td>
          {% if run.gitorigin and run.gitorigin | length > 0 %}
          <a href="{{ run.gitorigin | gitorigin2url | safe }}/commit/{{ run.gitcommit | highlight(query) | safe }}">
              {{ run.gitcommit | highlight(query) | safe }}
            </a>
            {% else %}
            {{ run.gitcommit | highlight(query) | safe }}
            {% endif %}
        </td>
      </tr>
      <tr>
        <td class="col-md-1">Git diff</td>
        {% if run.diff and run.diff | length > 0 %}
          <td style="padding: 0;">
            {{ run.diff | colordiff | highlight(query) | safe }}
          </td>
        {% else %}
          <td>No changes</td>
        {% endif %}
      </tr>
    </table>
  </div>
</div>
{% endif %}

{% endblock %}
