Skip to content

Closes: #19793 - Nav menu link customization #19794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
11 changes: 8 additions & 3 deletions netbox/netbox/plugins/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ class PluginMenuItem:
This class represents a navigation menu item. This constitutes primary link and its text, but also allows for
specifying additional link buttons that appear to the right of the item in the van menu.

Links are specified as Django reverse URL strings.
Links are specified as Django reverse URL strings suitable for rendering via {% url item.link %}.
Alternatively, a pre-generated url can be specified which will be rendered literally.
Buttons are each specified as a list of PluginMenuButton instances.
"""
permissions = []
buttons = []

def __init__(self, link, link_text, auth_required=False, staff_only=False, permissions=None, buttons=None):
def __init__(
self, link, link_text, url=None, auth_required=False, staff_only=False, permissions=None, buttons=None
):
self.link = link
self.link_text = link_text
self.url = url
self.auth_required = auth_required
self.staff_only = staff_only
if permissions is not None:
Expand All @@ -61,10 +65,11 @@ class PluginMenuButton:
color = ButtonColorChoices.DEFAULT
permissions = []

def __init__(self, link, title, icon_class, color=None, permissions=None):
def __init__(self, link, title, icon_class, url=None, color=None, permissions=None):
self.link = link
self.title = title
self.icon_class = icon_class
self.url = url
if permissions is not None:
if type(permissions) not in (list, tuple):
raise TypeError(_("Permissions must be passed as a tuple or list."))
Expand Down
4 changes: 2 additions & 2 deletions netbox/utilities/templates/navigation/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
</div>
{% for item, buttons in items %}
<div class="dropdown-item d-flex justify-content-between ps-3 py-0">
<a href="{% url item.link %}" class="d-inline-flex flex-fill py-1">{{ item.link_text }}</a>
<a href="{% if item.url %}{{ item.url }}{% else %}{% url item.link %}{% endif %}" class="d-inline-flex flex-fill py-1">{{ item.link_text }}</a>
{% if buttons %}
<div class="btn-group ms-1">
{% for button in buttons %}
<a href="{% url button.link %}" class="btn btn-sm btn-{{ button.color|default:"outline" }} lh-2 px-2" title="{{ button.title }}">
<a href="{% if button.url %}{{ button.url }}{% else %}{% url button.link %}{% endif %}" class="btn btn-sm btn-{{ button.color|default:"outline" }} lh-2 px-2" title="{{ button.title }}">
<i class="{{ button.icon_class }}"></i>
</a>
{% endfor %}
Expand Down