diff --git a/InvenTree/plugin/samples/integration/custom_panel_sample.py b/InvenTree/plugin/samples/integration/custom_panel_sample.py index e5b027fdac..0eada9c8ab 100644 --- a/InvenTree/plugin/samples/integration/custom_panel_sample.py +++ b/InvenTree/plugin/samples/integration/custom_panel_sample.py @@ -3,13 +3,13 @@ Sample plugin which renders custom panels on certain pages """ from plugin import IntegrationPluginBase -from plugin.mixins import PanelMixin +from plugin.mixins import PanelMixin, SettingsMixin from part.views import PartDetail from stock.views import StockLocationDetail -class CustomPanelSample(PanelMixin, IntegrationPluginBase): +class CustomPanelSample(PanelMixin, SettingsMixin, IntegrationPluginBase): """ A sample plugin which renders some custom panels. """ @@ -20,6 +20,15 @@ class CustomPanelSample(PanelMixin, IntegrationPluginBase): DESCRIPTION = "An example plugin demonstrating how custom panels can be added to the user interface" VERSION = "0.1" + SETTINGS = { + 'ENABLE_HELLO_WORLD': { + 'name': 'Hello World', + 'description': 'Enable a custom hello world panel on every page', + 'default': False, + 'validator': bool, + } + } + def render_location_info(self, loc): """ Demonstrate that we can render information particular to a page @@ -46,18 +55,20 @@ class CustomPanelSample(PanelMixin, IntegrationPluginBase): panels = [ { + # This panel will not be displayed, as it is missing the 'content' key + 'title': 'No Content', + } + ] + + if self.get_setting('ENABLE_HELLO_WORLD'): + panels.append({ # This 'hello world' panel will be displayed on any view which implements custom panels 'title': 'Hello World', 'icon': 'fas fa-boxes', 'content': 'Hello world!', 'description': 'A simple panel which renders hello world', 'javascript': 'alert("Hello world");', - }, - { - # This panel will not be displayed, as it is missing the 'content' key - 'title': 'No Content', - } - ] + }) # This panel will *only* display on the PartDetail view if isinstance(view, PartDetail):