Skip to content

Commit

Permalink
Introduce panel template for services
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Nov 16, 2022
1 parent 216d8d2 commit f411c4f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 90 deletions.
22 changes: 1 addition & 21 deletions netbox/templates/dcim/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,27 +295,7 @@ <h5 class="card-header">
</div>
</div>
{% endif %}
<div class="card">
<h5 class="card-header">Services</h5>
<div class="card-body">
{% if services %}
<table class="table table-hover">
{% for service in services %}
{% include 'ipam/inc/service.html' %}
{% endfor %}
</table>
{% else %}
<div class="text-muted">None</div>
{% endif %}
</div>
{% if perms.ipam.add_service %}
<div class="card-footer text-end noprint">
<a href="{% url 'ipam:service_add' %}?device={{ object.pk }}" class="btn btn-sm btn-primary">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Assign Service
</a>
</div>
{% endif %}
</div>
{% include 'inc/panels/services.html' %}
{% include 'inc/panels/contacts.html' %}
{% include 'inc/panels/image_attachments.html' %}
{% if object.rack and object.position %}
Expand Down
50 changes: 50 additions & 0 deletions netbox/templates/inc/panels/services.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div class="card">
<h5 class="card-header">Services</h5>
<div class="card-body">
{% if services %}
<table class="table table-hover">
{% for service in services %}
<tr>
<td>{{ service|linkify:"name" }}</td>
<td>{{ service.get_protocol_display }}</td>
<td>{{ service.port_list }}</td>
<td>
{% for ip in service.ipaddresses.all %}
<a href="{{ ip.get_absolute_url }}">{{ ip.address.ip }}</a><br />
{% empty %}
<span class="text-muted">All IPs</span>
{% endfor %}
</td>
<td>{{ service.description }}</td>
<td class="text-end noprint">
<a href="{% url 'ipam:service_changelog' pk=service.pk %}" class="btn btn-sm btn-outline-secondary" title="Change Log">
<i class="mdi mdi-history"></i>
</a>
{% if perms.ipam.change_service %}
<a href="{% url 'ipam:service_edit' pk=service.pk %}?return_url={{ service.parent.get_absolute_url }}" class="btn btn-warning btn-sm" title="Edit Service">
<i class="mdi mdi-pencil"></i>
</a>
{% endif %}
{% if perms.ipam.delete_service %}
<a href="{% url 'ipam:service_delete' pk=service.pk %}?return_url={{ service.parent.get_absolute_url }}" class="btn btn-danger btn-sm">
<i class="mdi mdi-trash-can-outline" title="Delete Service"></i>
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<div class="text-muted">None</div>
{% endif %}
</div>
{% if perms.ipam.add_service %}
{% with object|meta:"model_name" as object_type %}
<div class="card-footer text-end noprint">
<a href="{% url 'ipam:service_add' %}{% if object_type == "device" %}?device={{ object.pk }}{% elif object_type == "virtualmachine" %}?virtual_machine={{ object.pk }}{% endif %}" class="btn btn-sm btn-primary">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Add Service
</a>
</div>
{% endwith %}
{% endif %}
</div>
28 changes: 0 additions & 28 deletions netbox/templates/ipam/inc/service.html

This file was deleted.

19 changes: 1 addition & 18 deletions netbox/templates/ipam/ipaddress.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,7 @@ <h5 class="card-header">
<div class="my-3">
{% include 'inc/panel_table.html' with table=related_ips_table heading='Related IP Addresses' %}
</div>
<div class="card">
<h5 class="card-header">
Services
</h5>
<div class="card-body">
{% if services %}
<table class="table table-hover">
{% for service in services %}
{% include 'ipam/inc/service.html' %}
{% endfor %}
</table>
{% else %}
<div class="text-muted">
None
</div>
{% endif %}
</div>
</div>
{% include 'inc/panels/services.html' %}
{% plugin_right_page object %}
</div>
</div>
Expand Down
24 changes: 1 addition & 23 deletions netbox/templates/virtualization/virtualmachine.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,7 @@ <h5 class="card-header">Resources</h5>
</table>
</div>
</div>
<div class="card">
<h5 class="card-header">
Services
</h5>
<div class="card-body">
{% if services %}
<table class="table table-hover">
{% for service in services %}
{% include 'ipam/inc/service.html' %}
{% endfor %}
</table>
{% else %}
<span class="text-muted">None</span>
{% endif %}
</div>
{% if perms.ipam.add_service %}
<div class="card-footer text-end noprint">
<a href="{% url 'ipam:service_add' %}?virtual_machine={{ object.pk }}" class="btn btn-sm btn-primary">
<span class="mdi mdi-plus-thick" aria-hidden="true"></span> Assign Service
</a>
</div>
{% endif %}
</div>
{% include 'inc/panels/services.html' %}
{% include 'inc/panels/contacts.html' %}
{% plugin_right_page object %}
</div>
Expand Down

0 comments on commit f411c4f

Please sign in to comment.