Skip to content

Commit 663e064

Browse files
authored
Some fixes
Refactor port class and tooltip title logic
2 parents b699072 + bd7fd52 commit 663e064

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

netbox_device_view/templates/netbox_device_view/ports.html

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,38 @@ <h2 class="card-header">Deviceview {{ object.name }}</h2>
2828
{% for int in interfaces %}
2929
<a
3030
href="{{int.get_absolute_url}}trace/"
31-
class="{% if int.enabled and int.connected_endpoints|length > 0 %}bg-success{% elif int.enabled %}bg-secondary{% else %}bg-danger{% endif %}"
32-
title="{{ int.name }}{% if int.connected_endpoints|length > 0 %}<hr>{{ int.connected_endpoints.0.device }} | {{ int.connected_endpoints.0.name }}{% endif %}"
33-
style="grid-area: {{ int.stylename }}"
31+
class="device-view-port
32+
{% if cable_colors == "on" and int.cable.color == "" or cable_colors == "on" and int.cable == None %}
33+
nocolor
34+
{% elif cable_colors == "on" %}
35+
{% elif int.enabled and int.connected_endpoints|length > 0 or int.is_port and int.link_peers|length > 0 %}
36+
bg-success
37+
{% elif int.enabled %}
38+
bg-secondary
39+
{% else %}
40+
bg-danger
41+
{% endif %}"
42+
title="{{ int.name }}
43+
{% if int.connected_endpoints|length > 0 %}<hr>
44+
{% for ce in int.connected_endpoints %}
45+
{{ ce.device }} | {{ ce.name }}
46+
{% endfor %}
47+
{% elif int.link_peers|length > 0 %}<hr>
48+
{% for lp in int.link_peers %}
49+
{% if lp.device %}
50+
{{ lp.device }} | {{ lp.name }}
51+
{% elif lp.circuit %}
52+
{{ lp }}
53+
{% endif %}
54+
{% endfor %}
55+
{% endif %}
56+
"
57+
style="grid-area: {{ int.stylename }}{% if cable_colors == 'on' and int.cable.color != '' %}; background-color: #{{ int.cable.color }}{% endif %}"
3458
data-bs-toggle="tooltip"
3559
data-bs-html="true"
3660
data-bs-custom-class="device-view-tooltip"
3761
>
38-
{% if int.enabled and int.connected_endpoints|length > 0 %}
62+
{% if int.enabled and int.connected_endpoints|length > 0 or int.is_port and int.link_peers|length > 0 %}
3963
<span class="text-white"><i class="mdi mdi-check-bold"></i></span>
4064
{% elif int.enabled %}
4165
<span class="text-white"><i class="mdi mdi-check-bold"></i></span>

netbox_device_view/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ def process_interfaces(interfaces, ports_chassis, dev):
1313
regex = r"^(?P<type>([a-zA-Z\-_]*))(\/|(?P<dev>[0-9]+).|\s)?((?P<module>[0-9]+).|\s)?((?P<port>[0-9]+))$"
1414
matches = re.search(regex, itf.name.lower())
1515
if matches:
16-
itf.stylename = (
17-
(matches["type"] or "")
18-
+ (matches["module"] or "")
19-
+ "-"
20-
+ matches["port"]
21-
)
16+
if not matches["type"] and not matches["type"]:
17+
stylename = matches["port"]
18+
else:
19+
stylename = (
20+
(matches["type"] or "")
21+
+ (matches["module"] or "")
22+
+ "-"
23+
+ matches["port"]
24+
)
2225
else:
2326
itf.stylename = re.sub(r"[^.a-zA-Z\d]", "-", itf.name.lower())
2427
if itf.stylename.isdigit():

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="netbox-device-view",
8-
version="0.1.13",
8+
version="0.1.14",
99
description="NetBox Device View plugin",
1010
packages=find_packages(),
1111
author="Peter Baumert",

0 commit comments

Comments
 (0)