diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 3c35ffd41..95e459a47 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -11,8 +11,8 @@ from utilities.tables import ( TagColumn, ToggleColumn, ) from .template_code import ( - CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES, - INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS, + CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, FRONTPORT_BUTTONS, + INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, POWEROUTLET_BUTTONS, POWERPORT_BUTTONS, ) __all__ = ( @@ -21,6 +21,7 @@ __all__ = ( 'DeviceBayTable', 'DeviceConsolePortTable', 'DeviceConsoleServerPortTable', + 'DeviceFrontPortTable', 'DeviceImportTable', 'DevicePowerPortTable', 'DevicePowerOutletTable', @@ -420,6 +421,32 @@ class FrontPortTable(DeviceComponentTable, CableTerminationTable): default_columns = ('pk', 'device', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description') +class DeviceFrontPortTable(FrontPortTable): + name = tables.TemplateColumn( + template_code=' ' + '{{ value }}' + ) + actions = ButtonsColumn( + model=FrontPort, + buttons=('edit', 'delete'), + prepend_template=FRONTPORT_BUTTONS + ) + + class Meta(DeviceComponentTable.Meta): + model = FrontPort + fields = ( + 'pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'cable_peer', + 'connection', 'tags', 'actions', + ) + default_columns = ( + 'pk', 'name', 'label', 'type', 'rear_port', 'rear_port_position', 'description', 'cable', 'cable_peer', + 'actions', + ) + row_attrs = { + 'class': lambda record: record.cable.get_status_class() if record.cable else '' + } + + class RearPortTable(DeviceComponentTable, CableTerminationTable): tags = TagColumn( url_name='dcim:rearport_list' diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index b32d6264e..e7182e1da 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -137,3 +137,23 @@ POWEROUTLET_BUTTONS = """ {% endif %} """ + +FRONTPORT_BUTTONS = """ +{% if frontport.cable %} + {% include 'dcim/inc/cable_toggle_buttons.html' with cable=record.cable %} +{% elif perms.dcim.add_cable %} + + + +{% endif %} +""" diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index ed8652f5e..1056a8078 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1061,6 +1061,9 @@ class DeviceView(ObjectView): frontports = FrontPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related( 'rear_port', 'cable', ) + frontport_table = tables.DeviceFrontPortTable(frontports, orderable=False) + if request.user.has_perm('dcim.change_frontport') or request.user.has_perm('dcim.delete_frontport'): + frontport_table.columns.show('pk') # Rear ports rearports = RearPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related('cable') @@ -1097,7 +1100,7 @@ class DeviceView(ObjectView): 'powerport_table': powerport_table, 'poweroutlet_table': poweroutlet_table, 'interfaces': interfaces, - 'frontports': frontports, + 'frontport_table': frontport_table, 'rearports': rearports, 'devicebays': devicebays, 'inventoryitems': inventoryitems, diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index d1294ed5c..94f66b345 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -125,7 +125,7 @@ + Interfaces {% badge interfaces|length %}
- {% endif %} - | Name | -Type | -Rear Port | -Position | -Description | -Cable | -Cable Termination | -- |
---|