diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 21c2f4244..5f61e03ba 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -10,11 +10,14 @@ from utilities.tables import ( BaseTable, BooleanColumn, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn, TagColumn, ToggleColumn, ) -from .template_code import CABLETERMINATION, DEVICE_LINK, INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS +from .template_code import ( + CABLETERMINATION, CONSOLEPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, +) __all__ = ( 'ConsolePortTable', 'ConsoleServerPortTable', + 'DeviceConsolePortTable', 'DeviceImportTable', 'DeviceTable', 'DeviceBayTable', @@ -237,6 +240,27 @@ class ConsolePortTable(DeviceComponentTable, PathEndpointTable): default_columns = ('pk', 'device', 'name', 'label', 'type', 'description') +class DeviceConsolePortTable(ConsolePortTable): + name = tables.TemplateColumn( + template_code=' {{ value }}' + ) + actions = ButtonsColumn( + model=ConsolePort, + buttons=('edit', 'delete'), + prepend_template=CONSOLEPORT_BUTTONS + ) + + class Meta(DeviceComponentTable.Meta): + model = ConsolePort + fields = ( + 'pk', 'name', 'label', 'type', 'description', 'cable', 'cable_peer', 'connection', 'tags', 'actions' + ) + default_columns = ('pk', 'name', 'label', 'type', 'description', 'cable', 'cable_peer', 'actions') + row_attrs = { + 'class': lambda record: record.cable.get_status_class() if record.cable else '' + } + + class ConsoleServerPortTable(DeviceComponentTable, PathEndpointTable): tags = TagColumn( url_name='dcim:consoleserverport_list' diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index 7278de113..e17a5a877 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -73,3 +73,24 @@ UTILIZATION_GRAPH = """ {% load helpers %} {% utilization_graph value %} """ + +# +# Device component buttons +# + +CONSOLEPORT_BUTTONS = """ +{% if record.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 06fb7619f..3cf011503 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1019,6 +1019,9 @@ class DeviceView(ObjectView): consoleports = ConsolePort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related( 'cable', '_path__destination', ) + consoleport_table = tables.DeviceConsolePortTable(consoleports, orderable=False) + if request.user.has_perm('dcim.change_consoleport') or request.user.has_perm('dcim.delete_consoleport'): + consoleport_table.columns.show('pk') # Console server ports consoleserverports = ConsoleServerPort.objects.restrict(request.user, 'view').filter( @@ -1079,7 +1082,7 @@ class DeviceView(ObjectView): return render(request, 'dcim/device.html', { 'device': device, - 'consoleports': consoleports, + 'consoleport_table': consoleport_table, 'consoleserverports': consoleserverports, 'powerports': powerports, 'poweroutlets': poweroutlets, diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index c06f86bf0..1a74016b2 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -131,7 +131,7 @@ + Rear Ports {% badge rearports|length %}
- {% endif %} - | Name | -Type | -Description | -Cable | -Cable Termination | -Connection | -- |
---|