{% extends 'detail.html.j2' %}

{% load json %}
{% load markdown %}


{% block tabs %}
<form action="" method="post">
  {% csrf_token %}
<div id="details" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.details %}

    <hr />

    <div style="display: block; width: 100%;">
      <h3>Operating System</h3>
      <br>
      {{ operating_system.as_p }}
      <input type="submit" name="{{ operating_system.prefix }}" value="Submit" />
    </div>


    <div style="display: block; width: 100%;">
      <h3>Dependent Services</h3>
      <table>
          <tr>
              <th>Name</th>
              <th>Ports</th>
          </tr>
          {% if services %}
          {% for service in services %}
          <tr>
              <td><a href="{% url 'ITIM:_service_view' service.pk %}">{{ service }}</a></td>
              <td>{% for port in service.port.all %}{{ port }} ({{ port.description}}), {% endfor %}</td>
          </tr>
          {% endfor%}
          {% else %}
          <tr>
          <td colspan="2"> Nothing Found</td>
          </tr>
          {% endif %}
      </table>
    </div>


    <div style="display: block; width: 100%;">
      <h3>Device Config</h3>
      <br>
      <textarea cols="90" rows="30" readonly>{{ device.config }}</textarea>
    </div>


</div>



<div id="software" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.software %}

    <hr>
    Installed Software: {{ installed_software }}
    <input type="button" value="Add Software Action" onclick="window.location='{% url 'ITAM:_device_software_add' device.id %}';">
    <table>
      <thead>
        <th>Name</th>
        <th>Category</th>
        <th>Action</th>
        <th>Desired Version</th>
        <th>Installed Version</th>
        <th>Installed</th>
        <th>&nbsp;</th>
      </thead>
      {% if softwares %}
      {% for software in softwares %}
      <tr>
        <td><a href="{% url 'ITAM:_software_view' pk=software.software_id %}">{{ software.software }}</a></td>
        <td>{{ software.software.category }}</td>
        <td>
          {% url 'ITAM:_device_software_view' device_id=device.id pk=software.id as icon_link %}
          {% if software.get_action_display == 'Install' %}
            {% include 'icons/success_text.html.j2' with icon_text=software.get_action_display icon_link=icon_link %}
          {% elif software.get_action_display == 'Remove'%}
            {% include 'icons/cross_text.html.j2' with icon_text=software.get_action_display icon_link=icon_link %}
          {% else %}
            {% include 'icons/add_link.html.j2' with icon_text='Add' icon_link=icon_link %}
          {% endif %}
        </td>
        <td>
          {% if software.version %}
            {{ software.version }}
          {% else %}
            -
          {% endif %}
        </td>
        <td>
          {% if software.installedversion %}
            {{ software.installedversion }}
          {% else %}
            -
          {% endif %}
        </td>
        <td>
          {% if software.installed %}
            {{ software.installed }}
          {% else %}
            -
          {% endif %}
        </td>
        <td>&nbsp;</td>
      </tr>
      {% endfor %}
      {% else %}
      <td colspan="5">Nothing Found</td>
      {% endif %}
    </table>

    <div class="pagination">
        <span class="step-links">
            {% if page_obj.has_previous %}
                <a href="?page=1&tab=software">&laquo; first</a>
                <a href="?page={{ page_obj.previous_page_number }}&tab=software">previous</a>
            {% endif %}

            <span class="current">
                Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
            </span>

            {% if page_obj.has_next %}
                <a href="?page={{ page_obj.next_page_number }}&tab=software">next</a>
                <a href="?page={{ page_obj.paginator.num_pages }}&tab=software">last &raquo;</a>
            {% endif %}
        </span>
    </div>

</div>

<div id="tickets" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.tickets %}

    <table>
        <thead>
          <th>Name</th>
          <th>Status</th>
          <th>&nbsp</th>
        </thead>
        {% if tickets %}
        {% for ticket in tickets %}
        <tr>
          <td>{% concat_strings "#" ticket.ticket.id as ticket_ref %}{{ ticket_ref | markdown | safe}}</td>
          <td>{% include 'core/ticket/badge_ticket_status.html.j2' with ticket_status_text=ticket.ticket.get_status_display ticket_status=ticket.ticket.get_status_display|ticket_status %}</td>
          <td>&nbsp;</td>
        </tr>
        {% endfor %}
        {% else %}
        <tr>
            <td colspan="3">No related tickets exist</td>
        </tr>
        {% endif %}
    </table>

</div>

<div id="notes" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.notes %}

    {{ notes_form }}
    <input type="submit" name="{{notes_form.prefix}}" value="Submit" />
    <div class="comments">
      {% if notes %}
      {% for note in notes%}
      {% include 'note.html.j2' %}
      {% endfor %}
      {% endif %}
    </div>

</div>



<div id="config_management" class="content-tab">

    {% include 'content/section.html.j2' with tab=form.tabs.config_management %}

    <div>
      <textarea cols="90" rows="30" readonly>{{ config }}</textarea>
    </div>
    <br />
    <hr />
    <table class="data">
      <tr>
        <th>Group</th>
        <th>Added</th>
        <th>&nbsp;</th>
      </tr>
      {% if device.configgroups_set %}
      {% for group in device.configgroups_set.all %}
      <tr>
        <td><a href="{% url 'Config Management:_group_view' pk=group.id %}">{{ group }}</a></td>
        <td>{{ group.created }}</td>
        <td>&nbsp;</td>
      </tr>
      {% endfor %}
      {% else %}
      <tr>
        <td colspan="3">Nothing Found.</td>
      </tr>
      {% endif %}
    </table>

</div>
</form>
{% endblock %}
