Add inventory items panel to device component views

This commit is contained in:
jeremystretch 2021-12-28 11:06:34 -05:00
parent e0319cc894
commit a0836b6876
8 changed files with 145 additions and 79 deletions

View File

@ -58,91 +58,92 @@
</h5> </h5>
<div class="card-body"> <div class="card-body">
{% if object.mark_connected %} {% if object.mark_connected %}
<span class="text-success"><i class="mdi mdi-check-bold"></i></span> Marked as connected <span class="text-success"><i class="mdi mdi-check-bold"></i></span> Marked as connected
{% elif object.cable %} {% elif object.cable %}
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
<tr>
<th scope="row">Cable</th>
<td>
<a href="{{ object.cable.get_absolute_url }}">{{ object.cable }}</a>
<a href="{% url 'dcim:consoleport_trace' pk=object.pk %}" class="btn btn-primary btn-sm lh-1" title="Trace">
<i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i>
</a>
</td>
</tr>
{% if object.connected_endpoint %}
<tr> <tr>
<th scope="row">Device</th> <th scope="row">Cable</th>
<td> <td>
<a href="{{ object.connected_endpoint.device.get_absolute_url }}">{{ object.connected_endpoint.device }}</a> <a href="{{ object.cable.get_absolute_url }}">{{ object.cable }}</a>
<a href="{% url 'dcim:consoleport_trace' pk=object.pk %}" class="btn btn-primary btn-sm lh-1" title="Trace">
<i class="mdi mdi-transit-connection-variant" aria-hidden="true"></i>
</a>
</td> </td>
</tr> </tr>
<tr> {% if object.connected_endpoint %}
<th scope="row">Name</th> <tr>
<td> <th scope="row">Device</th>
<a href="{{ object.connected_endpoint.get_absolute_url }}">{{ object.connected_endpoint.name }}</a> <td>
</td> <a href="{{ object.connected_endpoint.device.get_absolute_url }}">{{ object.connected_endpoint.device }}</a>
</tr> </td>
<tr> </tr>
<th scope="row">Type</th> <tr>
<td>{{ object.connected_endpoint.get_type_display|placeholder }}</td> <th scope="row">Name</th>
</tr> <td>
<tr> <a href="{{ object.connected_endpoint.get_absolute_url }}">{{ object.connected_endpoint.name }}</a>
<th scope="row">Description</th> </td>
<td>{{ object.connected_endpoint.description|placeholder }}</td> </tr>
</tr> <tr>
<tr> <th scope="row">Type</th>
<th scope="row">Path Status</th> <td>{{ object.connected_endpoint.get_type_display|placeholder }}</td>
<td> </tr>
{% if object.path.is_active %} <tr>
<span class="badge bg-success">Reachable</span> <th scope="row">Description</th>
{% else %} <td>{{ object.connected_endpoint.description|placeholder }}</td>
<span class="badge bg-danger">Not Reachable</span> </tr>
{% endif %} <tr>
</td> <th scope="row">Path Status</th>
</tr> <td>
{% endif %} {% if object.path.is_active %}
</table> <span class="badge bg-success">Reachable</span>
{% else %} {% else %}
<div class="text-muted"> <span class="badge bg-danger">Not Reachable</span>
Not Connected {% endif %}
{% if perms.dcim.add_cable %} </td>
<div class="dropdown float-end"> </tr>
<button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> {% endif %}
<span class="mdi mdi-ethernet-cable" aria-hidden="true"></span> Connect </table>
</button> {% else %}
<ul class="dropdown-menu dropdown-menu-end"> <div class="text-muted">
<li> Not Connected
<a {% if perms.dcim.add_cable %}
class="dropdown-item" <div class="dropdown float-end">
href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='console-server-port' %}?return_url={{ object.get_absolute_url }}" <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
> <span class="mdi mdi-ethernet-cable" aria-hidden="true"></span> Connect
Console Server Port </button>
</a> <ul class="dropdown-menu dropdown-menu-end">
</li> <li>
<li> <a
<a class="dropdown-item"
class="dropdown-item" href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='console-server-port' %}?return_url={{ object.get_absolute_url }}"
href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='front-port' %}?return_url={{ object.get_absolute_url }}" >
> Console Server Port
Front Port </a>
</a> </li>
</li> <li>
<li> <a
<a class="dropdown-item"
class="dropdown-item" href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='front-port' %}?return_url={{ object.get_absolute_url }}"
href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='rear-port' %}?return_url={{ object.get_absolute_url }}" >
> Front Port
Rear Port </a>
</a> </li>
</li> <li>
</ul> <a
</div> class="dropdown-item"
{% endif %} href="{% url 'dcim:consoleport_connect' termination_a_id=object.pk termination_b_type='rear-port' %}?return_url={{ object.get_absolute_url }}"
</div> >
{% endif %} Rear Port
</div> </a>
</li>
</ul>
</div>
{% endif %}
</div>
{% endif %}
</div>
</div> </div>
{% include 'dcim/inc/panels/inventory_items.html' %}
{% plugin_right_page object %} {% plugin_right_page object %}
</div> </div>
</div> </div>

View File

@ -143,6 +143,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% include 'dcim/inc/panels/inventory_items.html' %}
{% plugin_right_page object %} {% plugin_right_page object %}
</div> </div>
</div> </div>

View File

@ -129,6 +129,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% include 'dcim/inc/panels/inventory_items.html' %}
{% plugin_right_page object %} {% plugin_right_page object %}
</div> </div>
</div> </div>

View File

@ -0,0 +1,59 @@
{% load helpers %}
<div class="card">
<h5 class="card-header">Inventory Items</h5>
<div class="card-body">
<table class="table table-hover table-headings">
<thead>
<tr>
<th>Name</th>
<th>Label</th>
<th>Role</th>
<th></th>
</tr>
</thead>
<tbody>
{% for item in object.inventory_items.all %}
<tr>
<td>
<a href="{{ item.get_absolute_url }}">{{ item.name }}</a>
</td>
<td>
{{ item.label|placeholder }}
</td>
<td>
{% if item.role %}
<a href="{{ item.role.get_absolute_url }}">{{ item.role }}</a>
{% else %}
<span class="text-muted">&mdash;</span>
{% endif %}
</td>
<td class="text-end noprint">
{% if perms.dcim.change_inventoryitem %}
<a href="{% url 'dcim:inventoryitem_edit' pk=item.pk %}?return_url={{ object.get_absolute_url }}" class="btn btn-warning btn-sm lh-1" title="Edit">
<i class="mdi mdi-pencil" aria-hidden="true"></i>
</a>
{% endif %}
{% if perms.ipam.delete_inventoryitem %}
<a href="{% url 'dcim:inventoryitem_delete' pk=item.pk %}?return_url={{ object.get_absolute_url }}" class="btn btn-danger btn-sm lh-1" title="Delete">
<i class="mdi mdi-trash-can-outline" aria-hidden="true"></i>
</a>
{% endif %}
</td>
</tr>
{% empty %}
<tr>
<td colspan="5" class="text-muted">None</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="card-footer text-end noprint">
{% if perms.dcim.add_inventoryitem %}
<a href="{% url 'dcim:inventoryitem_add' %}?device={{ object.device.pk }}&component_type={{ object|content_type_id }}&component_id={{ object.pk }}&return_url={{ object.get_absolute_url }}" class="btn btn-sm btn-primary">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add Inventory Item
</a>
{% endif %}
</div>
</div>

View File

@ -448,6 +448,7 @@
</div> </div>
{% endif %} {% endif %}
{% include 'ipam/inc/panels/fhrp_groups.html' %} {% include 'ipam/inc/panels/fhrp_groups.html' %}
{% include 'dcim/inc/panels/inventory_items.html' %}
{% plugin_right_page object %} {% plugin_right_page object %}
</div> </div>
</div> </div>

View File

@ -121,6 +121,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% include 'dcim/inc/panels/inventory_items.html' %}
{% plugin_right_page object %} {% plugin_right_page object %}
</div> </div>
</div> </div>

View File

@ -131,6 +131,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% include 'dcim/inc/panels/inventory_items.html' %}
{% plugin_right_page object %} {% plugin_right_page object %}
</div> </div>
</div> </div>

View File

@ -117,6 +117,7 @@
{% endif %} {% endif %}
</div> </div>
</div> </div>
{% include 'dcim/inc/panels/inventory_items.html' %}
{% plugin_right_page object %} {% plugin_right_page object %}
</div> </div>
</div> </div>