{% extends "layouts/content.html" %}
{% 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>Multinode Job definition file - {{ job.sub_id }}  <a class="btn btn-xs btn-info" href="{% url 'lava.scheduler.job.multinode_definition.plain' job.pk %}" title="Download as text file"><span class="glyphicon glyphicon-download"></span> download</a></h2>

<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">
        {% if job_file_present %}
          <li><a href="{% url 'lava.scheduler.job.detail' job.pk %}" class="btn btn-primary">Complete log</a></li>
        {% endif %}
        {% 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 %}
          <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.sub_id %}">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.sub_id %}">Fail</a></li>
      {% endif %}
        </ul>
      </div>
      <div class="col-md-6">
        <ul class="nav nav-pills nav-stacked">
          <li><a href="{% url 'lava.scheduler.job.definition' job.pk %}" class="btn btn-info">Definition of {{ job.sub_id }}</a></li>
        {% 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>
  </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.sub_id %}">{{ subjob.sub_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 %}
      ({{ subjob.id }})
      </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 }}.
    {% endif %}
      </dd>
    {% endfor %}
    </dl>
  </div>
</div>
{% endif %}


<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.multinode_definition }}</span><br/>
{% with job.multinode_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-11">
    <span style="font-family: monospace; white-space: pre;">{{ line.rstrip }}</span>
   </div>
    </div>
{% endfor %}
{% endwith %}

{% endblock content %}

{% block scripts %}
<script type="text/javascript" src="{{ STATIC_URL }}lava_scheduler_app/js/job-definition.min.js"></script>
{% endblock %}
