navigation plugin

This commit is contained in:
Matthias 2021-09-19 16:27:43 +02:00
parent 4c8318440c
commit 1c89e83d28
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 44 additions and 1 deletions

View File

@ -73,6 +73,27 @@ class UrlsMixin:
does this plugin use custom urls
"""
return bool(self.urls)
class NavigationMixin:
"""Mixin that enables adding navigation links with the plugin"""
def __init__(self):
super().__init__()
self.add_mixin('navigation', 'has_naviation')
self.navigation = self.setup_navigation()
def setup_navigation(self):
"""
setup navigation links for this plugin
"""
return getattr(self, 'NAVIGATION', None)
@property
def has_naviation(self):
"""
does this plugin define navigation elements
"""
return bool(self.navigation)
# endregion

View File

@ -4,7 +4,7 @@ from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
class SampleIntegrationPlugin(SettingsMixin, UrlsMixin, IntegrationPlugin):
class SampleIntegrationPlugin(SettingsMixin, UrlsMixin, NavigationMixin, IntegrationPlugin):
"""
An full integration plugin
"""
@ -34,6 +34,10 @@ class SampleIntegrationPlugin(SettingsMixin, UrlsMixin, IntegrationPlugin):
},
}
NAVIGATION= [
{'name': 'SampleIntegration', 'link': 'SampleIntegrationPlugin:hi'},
]
class OtherIntegrationPlugin(UrlsMixin, IntegrationPlugin):
"""

View File

@ -1,5 +1,6 @@
{% load static %}
{% load inventree_extras %}
{% load plugin_extras %}
{% load i18n %}
{% settings_value 'BARCODE_ENABLE' as barcodes %}
@ -57,6 +58,23 @@
</ul>
</li>
{% endif %}
{% plugin_list as pl_list %}
{% for plugin_key, plugin in pl_list.items %}
{% mixin_enabled plugin 'navigation' as navigation %}
{% if navigation %}
<li class='nav navbar-nav'>
<a class='dropdown-toggle' data-toggle='dropdown' href='#'><span class='{{plugin.icon}} icon-header'></span>{{plugin.plugin_name}}</a>
<ul class='dropdown-menu'>
{% for nav_item in plugin.navigation %}
<li><a href="{% url nav_item.name %}"><span class='{{nav_item.icon}} icon-header'></span>{{nav_item.name}}</a>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
<ul class="nav navbar-nav navbar-right">
{% include "search_form.html" %}