From 0797e9ebf02986d214ae897d9ed4b896c6c26f89 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Fri, 6 May 2022 23:19:21 +1000
Subject: [PATCH] Simplify the new template rendering

- No extra template code is required for any new page
- All loaded in base.html or page_base.html
- Oh, so clean!
---
 InvenTree/part/templates/part/detail.html                  | 2 --
 InvenTree/part/templates/part/part_sidebar.html            | 4 +---
 InvenTree/templates/base.html                              | 3 ++-
 InvenTree/templates/page_base.html                         | 2 ++
 .../plugin_panels.html => plugin/panel_content.html}       | 7 ++++---
 .../{panel/plugin_javascript.html => plugin/panel_js.html} | 0
 .../plugin_menu_items.html => plugin/panel_menu.html}      | 5 ++++-
 7 files changed, 13 insertions(+), 10 deletions(-)
 rename InvenTree/templates/{panel/plugin_panels.html => plugin/panel_content.html} (84%)
 rename InvenTree/templates/{panel/plugin_javascript.html => plugin/panel_js.html} (100%)
 rename InvenTree/templates/{panel/plugin_menu_items.html => plugin/panel_menu.html} (54%)

diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html
index e2e3d27be0..bcedc95da8 100644
--- a/InvenTree/part/templates/part/detail.html
+++ b/InvenTree/part/templates/part/detail.html
@@ -400,8 +400,6 @@
     </div>    
 </div>
 
-{% include "panel/plugin_panels.html" %}
-
 {% endblock %}
 
 {% block js_load %}
diff --git a/InvenTree/part/templates/part/part_sidebar.html b/InvenTree/part/templates/part/part_sidebar.html
index 18890b82af..1da07aa0c6 100644
--- a/InvenTree/part/templates/part/part_sidebar.html
+++ b/InvenTree/part/templates/part/part_sidebar.html
@@ -57,6 +57,4 @@
 {% trans "Attachments" as text %}
 {% include "sidebar_item.html" with label="part-attachments" text=text icon="fa-paperclip" %}
 {% trans "Notes" as text %}
-{% include "sidebar_item.html" with label="part-notes" text=text icon="fa-clipboard" %}
-
-{% include "panel/plugin_menu_items.html" %}
\ No newline at end of file
+{% include "sidebar_item.html" with label="part-notes" text=text icon="fa-clipboard" %}
\ No newline at end of file
diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html
index 7dbb17c7d8..0d8272892a 100644
--- a/InvenTree/templates/base.html
+++ b/InvenTree/templates/base.html
@@ -83,6 +83,7 @@
                         {% block sidebar %}
                         <!-- Sidebar goes here -->
                         {% endblock %}
+                        {% include "plugin/panel_menu.html" %}
                         {% include "sidebar_toggle.html" with target='sidebar' %}
                     </ul>
                 </div>
@@ -210,7 +211,7 @@
 
 $(document).ready(function () {
 
-    {% include "panel/plugin_javascript.html" %}
+    {% include "plugin/panel_js.html" %}
 
 {% block js_ready %}
 {% endblock %}
diff --git a/InvenTree/templates/page_base.html b/InvenTree/templates/page_base.html
index 17077700a2..9dcd33912d 100644
--- a/InvenTree/templates/page_base.html
+++ b/InvenTree/templates/page_base.html
@@ -61,6 +61,8 @@
 </div>
 
 {% block page_content %}
+<!-- Custom page content goes here-->
 {% endblock %}
+{% include "plugin/panel_content.html" %}
 
 {% endblock %}
diff --git a/InvenTree/templates/panel/plugin_panels.html b/InvenTree/templates/plugin/panel_content.html
similarity index 84%
rename from InvenTree/templates/panel/plugin_panels.html
rename to InvenTree/templates/plugin/panel_content.html
index ddbdbeee45..6b5c4ed90b 100644
--- a/InvenTree/templates/panel/plugin_panels.html
+++ b/InvenTree/templates/plugin/panel_content.html
@@ -1,5 +1,6 @@
+{% if plugin_panels %}
+<!-- Custom panel items, loaded via plugins -->
 {% for panel in plugin_panels %}
-
 <div class='panel panel-hidden' id='panel-{{ panel.key }}'>
     <div class='panel-heading'>
         <div class='d-flex flex-wrap'>
@@ -14,5 +15,5 @@
         {{ panel.content | safe }}
     </div>
 </div>
-
-{% endfor %}
\ No newline at end of file
+{% endfor %}
+{% endif %}
\ No newline at end of file
diff --git a/InvenTree/templates/panel/plugin_javascript.html b/InvenTree/templates/plugin/panel_js.html
similarity index 100%
rename from InvenTree/templates/panel/plugin_javascript.html
rename to InvenTree/templates/plugin/panel_js.html
diff --git a/InvenTree/templates/panel/plugin_menu_items.html b/InvenTree/templates/plugin/panel_menu.html
similarity index 54%
rename from InvenTree/templates/panel/plugin_menu_items.html
rename to InvenTree/templates/plugin/panel_menu.html
index 2c084a021e..bbbadfdc64 100644
--- a/InvenTree/templates/panel/plugin_menu_items.html
+++ b/InvenTree/templates/plugin/panel_menu.html
@@ -1,3 +1,6 @@
+{% if plugin_panels %}
+<!-- Custom sidebar menu items, loaded via plugins -->
 {% for panel in plugin_panels %}
 {% include "sidebar_item.html" with label=panel.key text=panel.title icon=panel.icon %}
-{% endfor %}
\ No newline at end of file
+{% endfor %}
+{% endif %}
\ No newline at end of file