mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-20 02:06:42 -06:00
Add SVG trace support for WirelessLinks
This commit is contained in:
parent
95ed07a95e
commit
43f2d4a331
@ -398,6 +398,39 @@ class CableTraceSVG:
|
|||||||
|
|
||||||
return group
|
return group
|
||||||
|
|
||||||
|
def _draw_wirelesslink(self, url, labels):
|
||||||
|
"""
|
||||||
|
Draw a line with labels representing a WirelessLink.
|
||||||
|
|
||||||
|
:param url: Hyperlink URL
|
||||||
|
:param labels: Iterable of text labels
|
||||||
|
"""
|
||||||
|
group = Group(class_='connector')
|
||||||
|
|
||||||
|
# Draw the wireless link
|
||||||
|
start = (OFFSET + self.center, self.cursor)
|
||||||
|
height = PADDING * 2 + LINE_HEIGHT * len(labels) + PADDING * 2
|
||||||
|
end = (start[0], start[1] + height)
|
||||||
|
line = Line(start=start, end=end, class_='wireless-link')
|
||||||
|
group.add(line)
|
||||||
|
|
||||||
|
self.cursor += PADDING * 2
|
||||||
|
|
||||||
|
# Add link
|
||||||
|
link = Hyperlink(href=f'{self.base_url}{url}', target='_blank')
|
||||||
|
|
||||||
|
# Add text label(s)
|
||||||
|
for i, label in enumerate(labels):
|
||||||
|
self.cursor += LINE_HEIGHT
|
||||||
|
text_coords = (self.center + PADDING * 2, self.cursor - LINE_HEIGHT / 2)
|
||||||
|
text = Text(label, insert=text_coords, class_='bold' if not i else [])
|
||||||
|
link.add(text)
|
||||||
|
|
||||||
|
group.add(link)
|
||||||
|
self.cursor += PADDING * 2
|
||||||
|
|
||||||
|
return group
|
||||||
|
|
||||||
def _draw_attachment(self):
|
def _draw_attachment(self):
|
||||||
"""
|
"""
|
||||||
Return an SVG group containing a line element and "Attachment" label.
|
Return an SVG group containing a line element and "Attachment" label.
|
||||||
@ -418,6 +451,9 @@ class CableTraceSVG:
|
|||||||
"""
|
"""
|
||||||
Return an SVG document representing a cable trace.
|
Return an SVG document representing a cable trace.
|
||||||
"""
|
"""
|
||||||
|
from dcim.models import Cable
|
||||||
|
from wireless.models import WirelessLink
|
||||||
|
|
||||||
traced_path = self.origin.trace()
|
traced_path = self.origin.trace()
|
||||||
|
|
||||||
# Prep elements list
|
# Prep elements list
|
||||||
@ -452,24 +488,39 @@ class CableTraceSVG:
|
|||||||
)
|
)
|
||||||
terminations.append(termination)
|
terminations.append(termination)
|
||||||
|
|
||||||
# Connector (either a Cable or attachment to a ProviderNetwork)
|
# Connector (a Cable or WirelessLink)
|
||||||
if connector is not None:
|
if connector is not None:
|
||||||
|
|
||||||
# Cable
|
# Cable
|
||||||
cable_labels = [
|
if type(connector) is Cable:
|
||||||
f'Cable {connector}',
|
connector_labels = [
|
||||||
connector.get_status_display()
|
f'Cable {connector}',
|
||||||
]
|
connector.get_status_display()
|
||||||
if connector.type:
|
]
|
||||||
cable_labels.append(connector.get_type_display())
|
if connector.type:
|
||||||
if connector.length and connector.length_unit:
|
connector_labels.append(connector.get_type_display())
|
||||||
cable_labels.append(f'{connector.length} {connector.get_length_unit_display()}')
|
if connector.length and connector.length_unit:
|
||||||
cable = self._draw_cable(
|
connector_labels.append(f'{connector.length} {connector.get_length_unit_display()}')
|
||||||
color=connector.color or '000000',
|
cable = self._draw_cable(
|
||||||
url=connector.get_absolute_url(),
|
color=connector.color or '000000',
|
||||||
labels=cable_labels
|
url=connector.get_absolute_url(),
|
||||||
)
|
labels=connector_labels
|
||||||
connectors.append(cable)
|
)
|
||||||
|
connectors.append(cable)
|
||||||
|
|
||||||
|
# WirelessLink
|
||||||
|
elif type(connector) is WirelessLink:
|
||||||
|
connector_labels = [
|
||||||
|
f'Wireless link {connector}',
|
||||||
|
connector.get_status_display()
|
||||||
|
]
|
||||||
|
if connector.ssid:
|
||||||
|
connector_labels.append(connector.ssid)
|
||||||
|
wirelesslink = self._draw_wirelesslink(
|
||||||
|
url=connector.get_absolute_url(),
|
||||||
|
labels=connector_labels
|
||||||
|
)
|
||||||
|
connectors.append(wirelesslink)
|
||||||
|
|
||||||
# Far end termination
|
# Far end termination
|
||||||
termination = self._draw_box(
|
termination = self._draw_box(
|
||||||
|
BIN
netbox/project-static/dist/cable_trace.css
vendored
BIN
netbox/project-static/dist/cable_trace.css
vendored
Binary file not shown.
@ -59,8 +59,13 @@ svg {
|
|||||||
stroke: var(--nbx-trace-cable-shadow);
|
stroke: var(--nbx-trace-cable-shadow);
|
||||||
stroke-width: 7px;
|
stroke-width: 7px;
|
||||||
}
|
}
|
||||||
|
line.wireless-link {
|
||||||
|
stroke: var(--nbx-trace-attachment);
|
||||||
|
stroke-dasharray: 4px 12px;
|
||||||
|
stroke-linecap: round;
|
||||||
|
}
|
||||||
line.attachment {
|
line.attachment {
|
||||||
stroke: var(--nbx-trace-attachment);
|
stroke: var(--nbx-trace-attachment);
|
||||||
stroke-dasharray: 5px, 5px;
|
stroke-dasharray: 5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user