mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Convert device rear ports list to table
This commit is contained in:
@ -12,7 +12,7 @@ from utilities.tables import (
|
|||||||
)
|
)
|
||||||
from .template_code import (
|
from .template_code import (
|
||||||
CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, FRONTPORT_BUTTONS,
|
CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, FRONTPORT_BUTTONS,
|
||||||
INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS,
|
INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS, REARPORT_BUTTONS,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -25,6 +25,7 @@ __all__ = (
|
|||||||
'DeviceImportTable',
|
'DeviceImportTable',
|
||||||
'DevicePowerPortTable',
|
'DevicePowerPortTable',
|
||||||
'DevicePowerOutletTable',
|
'DevicePowerOutletTable',
|
||||||
|
'DeviceRearPortTable',
|
||||||
'DeviceRoleTable',
|
'DeviceRoleTable',
|
||||||
'DeviceTable',
|
'DeviceTable',
|
||||||
'FrontPortTable',
|
'FrontPortTable',
|
||||||
@ -458,6 +459,31 @@ class RearPortTable(DeviceComponentTable, CableTerminationTable):
|
|||||||
default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
|
default_columns = ('pk', 'device', 'name', 'label', 'type', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceRearPortTable(RearPortTable):
|
||||||
|
name = tables.TemplateColumn(
|
||||||
|
template_code='<i class="fa fa-square{% if not record.cable %}-o{% endif %}"></i> '
|
||||||
|
'<a href="{{ record.get_absolute_url }}">{{ value }}</a>'
|
||||||
|
)
|
||||||
|
actions = ButtonsColumn(
|
||||||
|
model=RearPort,
|
||||||
|
buttons=('edit', 'delete'),
|
||||||
|
prepend_template=REARPORT_BUTTONS
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta(DeviceComponentTable.Meta):
|
||||||
|
model = RearPort
|
||||||
|
fields = (
|
||||||
|
'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'connection', 'tags',
|
||||||
|
'actions',
|
||||||
|
)
|
||||||
|
default_columns = (
|
||||||
|
'pk', 'name', 'label', 'type', 'positions', 'description', 'cable', 'cable_peer', 'actions',
|
||||||
|
)
|
||||||
|
row_attrs = {
|
||||||
|
'class': lambda record: record.cable.get_status_class() if record.cable else ''
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DeviceBayTable(DeviceComponentTable):
|
class DeviceBayTable(DeviceComponentTable):
|
||||||
installed_device = tables.Column(
|
installed_device = tables.Column(
|
||||||
linkify=True
|
linkify=True
|
||||||
|
@ -157,3 +157,21 @@ FRONTPORT_BUTTONS = """
|
|||||||
</span>
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
REARPORT_BUTTONS = """
|
||||||
|
{% if record.cable %}
|
||||||
|
{% include 'dcim/inc/cable_toggle_buttons.html' with cable=record.cable %}
|
||||||
|
{% elif perms.dcim.add_cable %}
|
||||||
|
<span class="dropdown">
|
||||||
|
<button type="button" class="btn btn-success btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<span class="glyphicon glyphicon-resize-small" aria-hidden="true"></span>
|
||||||
|
</button>
|
||||||
|
<ul class="dropdown-menu dropdown-menu-right">
|
||||||
|
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=record.pk termination_b_type='interface' %}?return_url={{ device.get_absolute_url }}">Interface</a></li>
|
||||||
|
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=record.pk termination_b_type='front-port' %}?return_url={{ device.get_absolute_url }}">Front Port</a></li>
|
||||||
|
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=record.pk termination_b_type='rear-port' %}?return_url={{ device.get_absolute_url }}">Rear Port</a></li>
|
||||||
|
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=record.pk termination_b_type='circuit-termination' %}?return_url={{ device.get_absolute_url }}">Circuit Termination</a></li>
|
||||||
|
</ul>
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
@ -1067,6 +1067,9 @@ class DeviceView(ObjectView):
|
|||||||
|
|
||||||
# Rear ports
|
# Rear ports
|
||||||
rearports = RearPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related('cable')
|
rearports = RearPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related('cable')
|
||||||
|
rearport_table = tables.DeviceRearPortTable(rearports, orderable=False)
|
||||||
|
if request.user.has_perm('dcim.change_rearport') or request.user.has_perm('dcim.delete_rearport'):
|
||||||
|
rearport_table.columns.show('pk')
|
||||||
|
|
||||||
# Device bays
|
# Device bays
|
||||||
devicebays = DeviceBay.objects.restrict(request.user, 'view').filter(device=device).prefetch_related(
|
devicebays = DeviceBay.objects.restrict(request.user, 'view').filter(device=device).prefetch_related(
|
||||||
@ -1101,7 +1104,7 @@ class DeviceView(ObjectView):
|
|||||||
'poweroutlet_table': poweroutlet_table,
|
'poweroutlet_table': poweroutlet_table,
|
||||||
'interfaces': interfaces,
|
'interfaces': interfaces,
|
||||||
'frontport_table': frontport_table,
|
'frontport_table': frontport_table,
|
||||||
'rearports': rearports,
|
'rearport_table': rearport_table,
|
||||||
'devicebays': devicebays,
|
'devicebays': devicebays,
|
||||||
'inventoryitems': inventoryitems,
|
'inventoryitems': inventoryitems,
|
||||||
'services': services,
|
'services': services,
|
||||||
|
@ -128,7 +128,7 @@
|
|||||||
<a href="#frontports" role="tab" data-toggle="tab">Front Ports {% badge frontport_table.rows|length %}</a>
|
<a href="#frontports" role="tab" data-toggle="tab">Front Ports {% badge frontport_table.rows|length %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#rearports" role="tab" data-toggle="tab">Rear Ports {% badge rearports|length %}</a>
|
<a href="#rearports" role="tab" data-toggle="tab">Rear Ports {% badge rearport_table.rows|length %}</a>
|
||||||
</li>
|
</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleport_table.rows|length %}</a>
|
<a href="#consoleports" role="tab" data-toggle="tab">Console Ports {% badge consoleport_table.rows|length %}</a>
|
||||||
@ -557,7 +557,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% include 'responsive_table.html' with table=frontport_table %}
|
{% include 'responsive_table.html' with table=frontport_table %}
|
||||||
<div class="panel-footer noprint">
|
<div class="panel-footer noprint">
|
||||||
{% if frontports and perms.dcim.change_frontport %}
|
{% if perms.dcim.change_frontport %}
|
||||||
<button type="submit" name="_rename" formaction="{% url 'dcim:frontport_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
<button type="submit" name="_rename" formaction="{% url 'dcim:frontport_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
||||||
</button>
|
</button>
|
||||||
@ -568,7 +568,7 @@
|
|||||||
<span class="glyphicon glyphicon-resize-full" aria-hidden="true"></span> Disconnect
|
<span class="glyphicon glyphicon-resize-full" aria-hidden="true"></span> Disconnect
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if frontports and perms.dcim.delete_frontport %}
|
{% if perms.dcim.delete_frontport %}
|
||||||
<button type="submit" formaction="{% url 'dcim:frontport_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
<button type="submit" formaction="{% url 'dcim:frontport_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
||||||
</button>
|
</button>
|
||||||
@ -592,29 +592,9 @@
|
|||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
<strong>Rear Ports</strong>
|
<strong>Rear Ports</strong>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-hover table-headings panel-body component-list">
|
{% include 'responsive_table.html' with table=rearport_table %}
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
{% if perms.dcim.change_rearport or perms.dcim.delete_rearport %}
|
|
||||||
<th class="pk"><input type="checkbox" class="toggle" title="Toggle all" /></th>
|
|
||||||
{% endif %}
|
|
||||||
<th>Name</th>
|
|
||||||
<th>Type</th>
|
|
||||||
<th>Positions</th>
|
|
||||||
<th>Description</th>
|
|
||||||
<th>Cable</th>
|
|
||||||
<th colspan="2">Cable Termination</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{% for rearport in rearports %}
|
|
||||||
{% include 'dcim/inc/rearport.html' %}
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="panel-footer noprint">
|
<div class="panel-footer noprint">
|
||||||
{% if rearports and perms.dcim.change_rearport %}
|
{% if perms.dcim.change_rearport %}
|
||||||
<button type="submit" name="_rename" formaction="{% url 'dcim:rearport_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
<button type="submit" name="_rename" formaction="{% url 'dcim:rearport_bulk_rename' %}?return_url={{ device.get_absolute_url }}" class="btn btn-warning btn-xs">
|
||||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Rename
|
||||||
</button>
|
</button>
|
||||||
@ -625,7 +605,7 @@
|
|||||||
<span class="glyphicon glyphicon-resize-full" aria-hidden="true"></span> Disconnect
|
<span class="glyphicon glyphicon-resize-full" aria-hidden="true"></span> Disconnect
|
||||||
</button>
|
</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if rearports and perms.dcim.delete_rearport %}
|
{% if perms.dcim.delete_rearport %}
|
||||||
<button type="submit" formaction="{% url 'dcim:rearport_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
<button type="submit" formaction="{% url 'dcim:rearport_bulk_delete' %}?return_url={{ device.get_absolute_url }}" class="btn btn-danger btn-xs">
|
||||||
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Delete
|
||||||
</button>
|
</button>
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
{% load helpers %}
|
|
||||||
<tr class="rearport{% if rearport.cable %} {{ rearport.cable.get_status_class }}{% endif %}">
|
|
||||||
|
|
||||||
{# Checkbox #}
|
|
||||||
{% if perms.dcim.change_rearport or perms.dcim.delete_rearport %}
|
|
||||||
<td class="pk">
|
|
||||||
<input name="pk" type="checkbox" value="{{ rearport.pk }}" />
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# Name #}
|
|
||||||
<td>
|
|
||||||
<i class="fa fa-fw fa-square{% if not rearport.cable %}-o{% endif %}"></i>
|
|
||||||
<a href="{{ rearport.get_absolute_url }}">{{ rearport }}</a>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
{# Type #}
|
|
||||||
<td>{{ rearport.get_type_display }}</td>
|
|
||||||
|
|
||||||
{# Positions #}
|
|
||||||
<td>{{ rearport.positions }}</td>
|
|
||||||
|
|
||||||
{# Description #}
|
|
||||||
<td>{{ rearport.description|placeholder }}</td>
|
|
||||||
|
|
||||||
{# Cable #}
|
|
||||||
{% if rearport.cable %}
|
|
||||||
<td>
|
|
||||||
<a href="{{ rearport.cable.get_absolute_url }}">{{ rearport.cable }}</a>
|
|
||||||
<a href="{% url 'dcim:rearport_trace' pk=rearport.pk %}" class="btn btn-primary btn-xs" title="Trace">
|
|
||||||
<i class="fa fa-share-alt" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
{% include 'dcim/inc/cabletermination.html' with termination=rearport.get_cable_peer %}
|
|
||||||
{% else %}
|
|
||||||
<td colspan="3">
|
|
||||||
<span class="text-muted">Not connected</span>
|
|
||||||
</td>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{# Actions #}
|
|
||||||
<td class="text-right noprint">
|
|
||||||
{% if rearport.cable %}
|
|
||||||
{% include 'dcim/inc/cable_toggle_buttons.html' with cable=rearport.cable %}
|
|
||||||
{% elif perms.dcim.add_cable %}
|
|
||||||
<span class="dropdown">
|
|
||||||
<button type="button" class="btn btn-success btn-xs dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
||||||
<span class="glyphicon glyphicon-resize-small" aria-hidden="true"></span>
|
|
||||||
</button>
|
|
||||||
<ul class="dropdown-menu dropdown-menu-right">
|
|
||||||
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=rearport.pk termination_b_type='interface' %}?return_url={{ device.get_absolute_url }}">Interface</a></li>
|
|
||||||
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=rearport.pk termination_b_type='front-port' %}?return_url={{ device.get_absolute_url }}">Front Port</a></li>
|
|
||||||
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=rearport.pk termination_b_type='rear-port' %}?return_url={{ device.get_absolute_url }}">Rear Port</a></li>
|
|
||||||
<li><a href="{% url 'dcim:rearport_connect' termination_a_id=rearport.pk termination_b_type='circuit-termination' %}?return_url={{ device.get_absolute_url }}">Circuit Termination</a></li>
|
|
||||||
</ul>
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.dcim.change_rearport %}
|
|
||||||
<a href="{% url 'dcim:rearport_edit' pk=rearport.pk %}?return_url={{ device.get_absolute_url }}" title="Edit port" class="btn btn-info btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-pencil" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.dcim.delete_rearport %}
|
|
||||||
<a href="{% url 'dcim:rearport_delete' pk=rearport.pk %}?return_url={{ device.get_absolute_url }}" title="Delete port" class="btn btn-danger btn-xs">
|
|
||||||
<i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
|
|
||||||
</a>
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
Reference in New Issue
Block a user