Explorar o código

Move DeviceInterfaceTable coloring logic into CSS

Preparatory work for simplifying toggle button code for cable status.
Per von Zweigbergk %!s(int64=2) %!d(string=hai) anos
pai
achega
27864ec865

+ 2 - 9
netbox/dcim/tables/devices.py

@@ -6,6 +6,7 @@ from dcim import models
 from netbox.tables import NetBoxTable, columns
 from netbox.tables import NetBoxTable, columns
 from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
 from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
 from .template_code import *
 from .template_code import *
+from dcim.choices import LinkStatusChoices
 
 
 __all__ = (
 __all__ = (
     'BaseInterfaceTable',
     'BaseInterfaceTable',
@@ -51,14 +52,6 @@ def get_cabletermination_row_class(record):
     return ''
     return ''
 
 
 
 
-def get_interface_row_class(record):
-    if not record.enabled:
-        return 'danger'
-    elif record.is_virtual:
-        return 'primary'
-    return get_cabletermination_row_class(record)
-
-
 def get_interface_state_attribute(record):
 def get_interface_state_attribute(record):
     """
     """
     Get interface enabled state as string to attach to <tr/> DOM element.
     Get interface enabled state as string to attach to <tr/> DOM element.
@@ -700,7 +693,6 @@ class DeviceInterfaceTable(InterfaceTable):
             'cable', 'connection',
             'cable', 'connection',
         )
         )
         row_attrs = {
         row_attrs = {
-            'class': get_interface_row_class,
             'data-name': lambda record: record.name,
             'data-name': lambda record: record.name,
             'data-enabled': get_interface_state_attribute,
             'data-enabled': get_interface_state_attribute,
             'data-virtual': get_interface_virtual_attribute,
             'data-virtual': get_interface_virtual_attribute,
@@ -708,6 +700,7 @@ class DeviceInterfaceTable(InterfaceTable):
             'data-cable-status': get_interface_cable_status_attribute,
             'data-cable-status': get_interface_cable_status_attribute,
             'data-type': lambda record: record.type,
             'data-type': lambda record: record.type,
         }
         }
+        cable_status_styles = [(slug, color) for slug, _, color in LinkStatusChoices.CHOICES]
 
 
 
 
 class FrontPortTable(ModularDeviceComponentTable, CableTerminationTable):
 class FrontPortTable(ModularDeviceComponentTable, CableTerminationTable):

+ 20 - 0
netbox/templates/dcim/device/interfaces.html

@@ -30,3 +30,23 @@
         </div>
         </div>
     {% endif %}
     {% endif %}
 {% endblock bulk_extra_controls %}
 {% endblock bulk_extra_controls %}
+
+{% block head %}
+    {{ block.super }}
+    <style>
+        {% for status, color in table.Meta.cable_status_styles %}
+        tr[data-cable-status={{ status }}] {
+            background-color: var(--nbx-color-{{ color }}-a15);
+        }
+        {% endfor %}
+        tr[data-mark-connected=true] {
+            background-color: var(--nbx-color-success-a15);
+        }
+        tr[data-virtual=true] {
+            background-color: var(--nbx-color-primary-a15);
+        }
+        tr[data-enabled=disabled] {
+            background-color: var(--nbx-color-danger-a15);
+        }
+    </style>
+{% endblock %}