From 771c453c404dfe189d312df3a99568d75b4d3f00 Mon Sep 17 00:00:00 2001
From: Matthias <matthias.mair@oewf.org>
Date: Fri, 17 Sep 2021 22:47:49 +0200
Subject: [PATCH] settings UI integration

---
 InvenTree/part/templatetags/plugin_extras.py  | 22 ++++++++++++++++
 .../templates/InvenTree/settings/navbar.html  | 17 +++++++++++++
 .../InvenTree/settings/plugin_settings.html   | 25 +++++++++++++++++++
 .../InvenTree/settings/settings.html          |  8 ++++++
 4 files changed, 72 insertions(+)
 create mode 100644 InvenTree/part/templatetags/plugin_extras.py
 create mode 100644 InvenTree/templates/InvenTree/settings/plugin_settings.html

diff --git a/InvenTree/part/templatetags/plugin_extras.py b/InvenTree/part/templatetags/plugin_extras.py
new file mode 100644
index 0000000000..af80c46ccb
--- /dev/null
+++ b/InvenTree/part/templatetags/plugin_extras.py
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+
+""" This module provides template tags for handeling plugins
+"""
+from django.utils.translation import ugettext_lazy as _
+from django.conf import settings as djangosettings
+
+from django import template
+
+
+register = template.Library()
+
+
+@register.simple_tag()
+def plugin_list(*args, **kwargs):
+    """ Return a list of all installed integration plugins """
+    return djangosettings.INTEGRATION_PLUGIN_LIST
+
+@register.simple_tag()
+def plugin_settings(plugin, *args, **kwargs):
+    """ Return a list of all settings for a plugin """
+    return djangosettings.INTEGRATION_PLUGIN_SETTING.get(plugin)
diff --git a/InvenTree/templates/InvenTree/settings/navbar.html b/InvenTree/templates/InvenTree/settings/navbar.html
index ebf24bffb1..1b4137a40d 100644
--- a/InvenTree/templates/InvenTree/settings/navbar.html
+++ b/InvenTree/templates/InvenTree/settings/navbar.html
@@ -1,4 +1,5 @@
 {% load i18n %}
+{% load plugin_extras %}
 
 <ul class='list-group'>
 
@@ -116,6 +117,22 @@
         </a>
     </li>
 
+
+    <li class='list-group-item'>
+        <strong>{% trans "Plugin Settings" %}</strong>
+    </li>
+
+    {% plugin_list as pl_list %}
+    {% for plugin_key, plugin in pl_list.items %}
+        {% if plugin.has_settings %}
+            <li class='list-group-item' title='{{ plugin.plugin_name }}'>
+                <a href='#' class='nav-toggle' id='select-plugin-{{plugin_key}}'>
+                    {{ plugin.plugin_name}}
+                </a>
+            </li>
+        {% endif %}
+    {% endfor %}
+
     {% endif %}
 
 </ul>
\ No newline at end of file
diff --git a/InvenTree/templates/InvenTree/settings/plugin_settings.html b/InvenTree/templates/InvenTree/settings/plugin_settings.html
new file mode 100644
index 0000000000..7f4deeace8
--- /dev/null
+++ b/InvenTree/templates/InvenTree/settings/plugin_settings.html
@@ -0,0 +1,25 @@
+{% extends "panel.html" %}
+{% load i18n %}
+{% load inventree_extras %}
+{% load plugin_extras %}
+
+{% block label %}plugin-{{plugin_key}}{% endblock %}
+
+
+{% block heading %}
+{% blocktrans with name=plugin.plugin_name %}Plugin Settings for {{name}}{% endblocktrans %}
+{% endblock %}
+
+{% block content %}
+{% plugin_settings plugin_key as plugin_settings %}
+
+<table class='table table-striped table-condensed'>
+    {% include "InvenTree/settings/header.html" %}
+    <tbody>
+        {% for setting in plugin_settings %}
+            {% include "InvenTree/settings/setting.html" with key=setting%}
+        {% endfor %}
+    </tbody>
+</table>
+
+{% endblock %}
diff --git a/InvenTree/templates/InvenTree/settings/settings.html b/InvenTree/templates/InvenTree/settings/settings.html
index beb7f5eb04..96b7c35723 100644
--- a/InvenTree/templates/InvenTree/settings/settings.html
+++ b/InvenTree/templates/InvenTree/settings/settings.html
@@ -3,6 +3,7 @@
 {% load i18n %}
 {% load static %}
 {% load inventree_extras %}
+{% load plugin_extras %}
 
 {% block page_title %}
 {% inventree_title %} | {% trans "Settings" %}
@@ -34,6 +35,13 @@
 {% include "InvenTree/settings/po.html" %}
 {% include "InvenTree/settings/so.html" %}
 
+{% plugin_list as pl_list %}
+{% for plugin_key, plugin in pl_list.items %}
+    {% if plugin.has_settings %}
+        {% include "InvenTree/settings/plugin_settings.html" %}
+    {% endif %}
+{% endfor %}
+
 {% endif %}
 
 {% endblock %}