{% extends "layouts/content.html" %}
{% load static %}
{% load utils %}

{% block styles %}
<style>
.noselect {
  -webkit-touch-callout: none; /* iOS Safari */
    -webkit-user-select: none; /* Chrome/Safari/Opera */
     -khtml-user-select: none; /* Konqueror */
       -moz-user-select: none; /* Firefox */
        -ms-user-select: none; /* Internet Explorer/Edge */
            user-select: none; /* Non-prefixed version, currently
                                  not supported by any browser */
}
</style>
{% endblock %}
{% block content %}
<h2>Job definition file - {% if job.is_multinode %}{{ job.sub_id|default:job.id }}{% else %}{{ job.id }}{% endif %}
 <a class="btn btn-xs btn-info" href="{% url 'lava.scheduler.job.definition.plain' job.pk %}" title="Download as text file"><span class="glyphicon glyphicon-download"></span> download</a></h2>
{% if job.is_multinode %}
     {{ job.sub_id|default:job.id }} is part of a multinode job. Use the Multinode Definition to resubmit.
{% endif %}

<div class="row">
  <div class="col-md-4">
    <h4 class="modal-header">Device</h4>
    <dl class="dl-horizontal">
    {% if job.actual_device %}
      <dt>Name</dt>
      <dd><a href="{{ job.actual_device.get_absolute_url }}">{{ job.actual_device.hostname }}</a> <a
      href="{% url 'lava.scheduler.device_report' job.actual_device.pk %}">(reports)</a></dd>
    {% endif %}

    {% if job.requested_device_type %}
      <dt>Requested type</dt>
      <dd><a href="{{ job.requested_device_type.get_absolute_url }}">{{ job.requested_device_type }}</a> <a href="{% url 'lava.scheduler.device_type_report' job.requested_device_type %}">(reports)</a></dd>
    {% endif %}
    </dl>
  </div>
  <div class="col-md-4">
    <h4 class="modal-header">Logs</h4>
    <div class="row">
      <div class="col-md-6">
        <ul class="nav nav-pills nav-stacked">
          <li><a href="{% url 'lava.scheduler.job.detail' job.pk %}" class="btn btn-primary">Complete log</a></li>
        {% if job.results_link %}
          <li><a href="{{ job.results_link }}" class="btn btn-success">Results</a></li>
        {% endif %}
        </ul>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <h4 class="modal-header">Actions</h4>
    <div class="row">
      <div class="col-md-6">
        <ul class="nav nav-pills nav-stacked">
        {% if show_resubmit and not job.is_multinode %}
          <li><a href="{% url 'lava.scheduler.job.resubmit' job.pk %}" class="btn btn-default">Resubmit</a></li>
        {% endif %}
      {% if show_cancel %}
      <li><a class="btn btn-warning" id="cancel" href="{% url 'lava.scheduler.job.cancel' job.pk %}">Cancel</a></li>
      {% elif show_fail %}
      <li><a class="btn btn-danger" id="fail" title="This should not be used if lava-run is still running" href="{% url 'lava.scheduler.job.fail' job.pk %}">Fail</a></li>
      {% endif %}
        </ul>
      </div>
      <div class="col-md-6">
        <ul class="nav nav-pills nav-stacked">
        {% if user.is_authenticated %}
        <li><a href="{% url 'lava.scheduler.job.toggle_favorite' job.pk %}"  class="btn btn-info">
            {% if is_favorite %}
              Remove from favorites
            {% else %}
              Add to favorites
            {% endif %}
        </a></li>
        {% endif %}
        </ul>
      </div>
      <div class="col-md-6">
        <ul class="nav nav-pills nav-stacked">
        {% if job.is_multinode %}
          <li><a href="{% url 'lava.scheduler.job.multinode_definition' job.pk %}" class="btn btn-info">Multinode Definition</a></li>
        {% endif %}
        </ul>
      </div>
    </div>
  </div>
</div>
{% if job.is_multinode %}
<div class="row">
  <div class="col-md-6">
    <h4 class="modal-header">Sub jobs</h4>
    <dl class="dl-horizontal">
    {% for subjob in job.sub_jobs_list %}
      <dt><a href="{% url 'lava.scheduler.job.detail' subjob.id %}">{{ subjob.sub_id|default:job.id }}</a>
        {% if '0' in subjob.sub_id and '0' not in job.sub_id %}
            <abbr title="view job {{ subjob.sub_id }} to see the results, if any.">(?)</abbr>
        {% endif %}
      </dt>
      <dd>
    {% if subjob.actual_device.hostname %}
      on: <a href="{{ subjob.actual_device.get_absolute_url }}">{{ subjob.actual_device.hostname }}</a>
      as: {{ subjob.device_role }}&nbsp;
    {% else %}
      No device assigned as {{ subjob.device_role }}.</dd>
    {% endif %}
      </dd>
    {% endfor %}
    </dl>
  </div>
</div>
{% endif %}

<h4 class="modal-header">Definition</h4>
<div class="pull-right"><small><a href="javascript: void(0);" id="copy_link"
   class="btn btn-xs btn-default"><span class="glyphicon glyphicon-copy"></span> Copy to clipboard</a></small></div><span
   style="display: none" id="job_definition_text">{{ job.display_definition|replace_python_unicode }}</span><br/>
{% with job.display_definition|split_definition as definition_data %}
{% for line in definition_data %}
    <div class="row">
  <div class="col-md-1 noselect" id="defline{{ forloop.counter }}">
    <a href="#defline{{ forloop.counter }}">{{ forloop.counter }}</a>
   </div>
   <div class="col-md-8">
    <span style="font-family: monospace; white-space: pre;">{{ line.rstrip|replace_python_unicode }}</span>
   </div>
    </div>
{% endfor %}
{% endwith %}
{% endblock content %}

{% block scripts %}
<script src="{% static "lava_scheduler_app/js/job-definition.js" %}"></script>
{% endblock %}
