diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 5f61e03ba..84460a632 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -11,13 +11,15 @@ from utilities.tables import ( TagColumn, ToggleColumn, ) from .template_code import ( - CABLETERMINATION, CONSOLEPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES, INTERFACE_TAGGED_VLANS, + CABLETERMINATION, CONSOLEPORT_BUTTONS, CONSOLESERVERPORT_BUTTONS, DEVICE_LINK, INTERFACE_IPADDRESSES, + INTERFACE_TAGGED_VLANS, ) __all__ = ( 'ConsolePortTable', 'ConsoleServerPortTable', 'DeviceConsolePortTable', + 'DeviceConsoleServerPortTable', 'DeviceImportTable', 'DeviceTable', 'DeviceBayTable', @@ -272,6 +274,27 @@ class ConsoleServerPortTable(DeviceComponentTable, PathEndpointTable): default_columns = ('pk', 'device', 'name', 'label', 'type', 'description') +class DeviceConsoleServerPortTable(ConsoleServerPortTable): + name = tables.TemplateColumn( + template_code=' {{ value }}' + ) + actions = ButtonsColumn( + model=ConsoleServerPort, + buttons=('edit', 'delete'), + prepend_template=CONSOLESERVERPORT_BUTTONS + ) + + class Meta(DeviceComponentTable.Meta): + model = ConsoleServerPort + 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 PowerPortTable(DeviceComponentTable, PathEndpointTable): tags = TagColumn( url_name='dcim:powerport_list' diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index e17a5a877..5e2b7e1c6 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -94,3 +94,20 @@ CONSOLEPORT_BUTTONS = """ {% endif %} """ + +CONSOLESERVERPORT_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 3cf011503..0de680420 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1029,6 +1029,10 @@ class DeviceView(ObjectView): ).prefetch_related( 'cable', '_path__destination', ) + consoleserverport_table = tables.DeviceConsoleServerPortTable(consoleserverports, orderable=False) + if request.user.has_perm('dcim.change_consoleserverport') or \ + request.user.has_perm('dcim.delete_consoleserverport'): + consoleserverport_table.columns.show('pk') # Power ports powerports = PowerPort.objects.restrict(request.user, 'view').filter(device=device).prefetch_related( @@ -1083,7 +1087,7 @@ class DeviceView(ObjectView): return render(request, 'dcim/device.html', { 'device': device, 'consoleport_table': consoleport_table, - 'consoleserverports': consoleserverports, + 'consoleserverport_table': consoleserverport_table, 'powerports': powerports, 'poweroutlets': poweroutlets, 'interfaces': interfaces, diff --git a/netbox/templates/dcim/device.html b/netbox/templates/dcim/device.html index 1a74016b2..962d1127f 100644 --- a/netbox/templates/dcim/device.html +++ b/netbox/templates/dcim/device.html @@ -134,7 +134,7 @@ Console Ports {% badge consoleport_table.rows|length %}
  • - Console Server Ports {% badge consoleserverports|length %} + Console Server Ports {% badge consoleserverport_table.rows|length %}
  • Power Ports {% badge powerports|length %} @@ -707,29 +707,9 @@
    Console Server Ports
    - - - - {% if perms.dcim.change_consoleserverport or perms.dcim.delete_consoleserverport %} - - {% endif %} - - - - - - - - - - - {% for csp in consoleserverports %} - {% include 'dcim/inc/consoleserverport.html' %} - {% endfor %} - -
    NameTypeDescriptionCableCable TerminationConnection
    + {% include 'responsive_table.html' with table=consoleserverport_table %} -
    {% endif %} +
    diff --git a/netbox/templates/dcim/inc/consoleserverport.html b/netbox/templates/dcim/inc/consoleserverport.html deleted file mode 100644 index 025b0bf02..000000000 --- a/netbox/templates/dcim/inc/consoleserverport.html +++ /dev/null @@ -1,79 +0,0 @@ -{% load helpers %} - - - - {# Checkbox #} - {% if perms.dcim.change_consoleserverport or perms.dcim.delete_consoleserverport %} - - - - {% endif %} - - {# Name #} - - - {{ csp }} - - - {# Type #} - - {% if csp.type %}{{ csp.get_type_display }}{% else %}—{% endif %} - - - {# Description #} - - {{ csp.description|placeholder }} - - - {# Cable #} - {% if csp.cable %} - - {{ csp.cable }} - - - - - {% include 'dcim/inc/cabletermination.html' with termination=csp.get_cable_peer %} - {% else %} - - Not connected - - {% endif %} - - {# Connection #} - {% include 'dcim/inc/endpoint_connection.html' with path=csp.path %} - - {# Actions #} - - {% if csp.cable %} - {% include 'dcim/inc/cable_toggle_buttons.html' with cable=csp.cable %} - {% elif perms.dcim.add_cable %} - - - - - {% endif %} - {% if perms.dcim.change_consoleserverport %} - - - - {% endif %} - {% if perms.dcim.delete_consoleserverport %} - {% if csp.connected_endpoint %} - - {% else %} - - - - {% endif %} - {% endif %} - -