Move DeviceInterfaceTable coloring logic into CSS
Preparatory work for simplifying toggle button code for cable status.
This commit is contained in:
parent
d44f67aea5
commit
27864ec865
|
@ -6,6 +6,7 @@ from dcim import models
|
|||
from netbox.tables import NetBoxTable, columns
|
||||
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
|
||||
from .template_code import *
|
||||
from dcim.choices import LinkStatusChoices
|
||||
|
||||
__all__ = (
|
||||
'BaseInterfaceTable',
|
||||
|
@ -51,14 +52,6 @@ def get_cabletermination_row_class(record):
|
|||
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):
|
||||
"""
|
||||
Get interface enabled state as string to attach to <tr/> DOM element.
|
||||
|
@ -700,7 +693,6 @@ class DeviceInterfaceTable(InterfaceTable):
|
|||
'cable', 'connection',
|
||||
)
|
||||
row_attrs = {
|
||||
'class': get_interface_row_class,
|
||||
'data-name': lambda record: record.name,
|
||||
'data-enabled': get_interface_state_attribute,
|
||||
'data-virtual': get_interface_virtual_attribute,
|
||||
|
@ -708,6 +700,7 @@ class DeviceInterfaceTable(InterfaceTable):
|
|||
'data-cable-status': get_interface_cable_status_attribute,
|
||||
'data-type': lambda record: record.type,
|
||||
}
|
||||
cable_status_styles = [(slug, color) for slug, _, color in LinkStatusChoices.CHOICES]
|
||||
|
||||
|
||||
class FrontPortTable(ModularDeviceComponentTable, CableTerminationTable):
|
||||
|
|
|
@ -30,3 +30,23 @@
|
|||
</div>
|
||||
{% endif %}
|
||||
{% 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 %}
|
||||
|
|
Loading…
Reference in New Issue