mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Standardize naming of menu items
This commit is contained in:
@ -11,7 +11,7 @@ from utilities.choices import ButtonColorChoices
|
|||||||
|
|
||||||
# Initialize plugin registry stores
|
# Initialize plugin registry stores
|
||||||
registry['plugin_template_extensions'] = collections.defaultdict(list)
|
registry['plugin_template_extensions'] = collections.defaultdict(list)
|
||||||
registry['plugin_nav_menu_links'] = {}
|
registry['plugin_menu_items'] = {}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -154,7 +154,7 @@ def register_template_extensions(class_list):
|
|||||||
|
|
||||||
class PluginMenuItem:
|
class PluginMenuItem:
|
||||||
"""
|
"""
|
||||||
This class represents a nav menu item. This constitutes primary link and its text, but also allows for
|
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.
|
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.
|
||||||
@ -172,8 +172,8 @@ class PluginMenuItem:
|
|||||||
|
|
||||||
class PluginMenuButton:
|
class PluginMenuButton:
|
||||||
"""
|
"""
|
||||||
This class represents a button which is a part of the nav menu link item.
|
This class represents a button within a PluginMenuItem. Note that button colors should come from
|
||||||
Note that button colors should come from ButtonColorChoices
|
ButtonColorChoices.
|
||||||
"""
|
"""
|
||||||
color = ButtonColorChoices.DEFAULT
|
color = ButtonColorChoices.DEFAULT
|
||||||
|
|
||||||
@ -199,4 +199,4 @@ def register_menu_items(section_name, class_list):
|
|||||||
if not isinstance(button, PluginMenuButton):
|
if not isinstance(button, PluginMenuButton):
|
||||||
raise TypeError(f"{button} must be an instance of extras.plugins.PluginMenuButton")
|
raise TypeError(f"{button} must be an instance of extras.plugins.PluginMenuButton")
|
||||||
|
|
||||||
registry['plugin_nav_menu_links'][section_name] = class_list
|
registry['plugin_menu_items'][section_name] = class_list
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from extras.registry import registry
|
from extras.registry import registry
|
||||||
|
|
||||||
|
|
||||||
def nav_menu_links(request):
|
def plugin_menu_items(request):
|
||||||
"""
|
"""
|
||||||
Retrieve and expose all plugin registered nav links
|
Retrieve and expose all plugin registered navigation menu items.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
'plugin_nav_menu_links': registry['plugin_nav_menu_links']
|
'plugin_menu_items': registry['plugin_menu_items']
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ TEMPLATES = [
|
|||||||
'django.contrib.auth.context_processors.auth',
|
'django.contrib.auth.context_processors.auth',
|
||||||
'django.contrib.messages.context_processors.messages',
|
'django.contrib.messages.context_processors.messages',
|
||||||
'utilities.context_processors.settings',
|
'utilities.context_processors.settings',
|
||||||
'extras.plugins.context_processors.nav_menu_links',
|
'extras.plugins.context_processors.plugin_menu_items',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -504,8 +504,8 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
{% if plugin_nav_menu_links %}
|
{% if plugin_menu_items %}
|
||||||
{% include 'inc/plugin_nav_menu_items.html' %}
|
{% include 'inc/plugin_menu_items.html' %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Plugins <span class="caret"></span></a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Plugins <span class="caret"></span></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
{% for section_name, link_items in plugin_nav_menu_links.items %}
|
{% for section_name, menu_items in plugin_menu_items.items %}
|
||||||
<li class="dropdown-header">{{ section_name }}</li>
|
<li class="dropdown-header">{{ section_name }}</li>
|
||||||
{% for link_item in link_items %}
|
{% for menu_item in menu_items %}
|
||||||
{% if link_item.permission %}
|
{% if menu_item.permission %}
|
||||||
<li{% if not link_item.permission in perms %} class="disabled"{% endif %}>
|
<li{% if not menu_item.permission in perms %} class="disabled"{% endif %}>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li>
|
<li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if link_item.buttons %}
|
{% if menu_item.buttons %}
|
||||||
<div class="buttons pull-right">
|
<div class="buttons pull-right">
|
||||||
{% for button in link_item.buttons %}
|
{% for button in menu_item.buttons %}
|
||||||
{% if not button.permission or button.permission in perms %}
|
{% if not button.permission or button.permission in perms %}
|
||||||
<a href="{% url button.link %}" class="btn btn-xs btn-{{ button.color }}" title="{{ button.title }}"><i class="fa {{ button.icon_class }}"></i></a>
|
<a href="{% url button.link %}" class="btn btn-xs btn-{{ button.color }}" title="{{ button.title }}"><i class="fa {{ button.icon_class }}"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{% url link_item.link %}">{{ link_item.link_text }}</a>
|
<a href="{% url menu_item.link %}">{{ menu_item.link_text }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if not forloop.last %}
|
{% if not forloop.last %}
|
Reference in New Issue
Block a user