diff --git a/src/backend/InvenTree/plugin/api.py b/src/backend/InvenTree/plugin/api.py index 9d74f024ab..0af8722ece 100644 --- a/src/backend/InvenTree/plugin/api.py +++ b/src/backend/InvenTree/plugin/api.py @@ -440,47 +440,11 @@ class PluginPanelList(APIView): if plugin_panels and type(plugin_panels) is list: for panel in plugin_panels: + panel['plugin'] = _plugin.slug + # TODO: Validate each panel before inserting panels.append(panel) - if target_model == 'part' and target_id: - panels = [ - *panels, - { - 'plugin': 'myplugin', - 'name': 'test-plugin', - 'label': 'My Plugin', - 'icon': 'part', - 'content': '
hello world
', - }, - { - 'plugin': 'myplugin', - 'name': 'test-plugin-2', - 'label': 'My Plugin 2', - 'icon': 'email', - 'content': '
hello world 2
', - }, - { - 'plugin': 'myplugin', - 'name': 'test-plugin-3', - 'label': 'My Plugin 3', - 'icon': 'website', - 'content': '
hello world 3
', - }, - ] - - if target_model == 'partcategory': - panels = [ - *panels, - { - 'plugin': 'cat', - 'name': 'demo-cat', - 'label': 'Custom Category', - 'icon': 'customer', - 'content': 'This should only appear for a category', - }, - ] - return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data) diff --git a/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py b/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py index cbd3999ef9..90cadb4265 100644 --- a/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py +++ b/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py @@ -29,3 +29,36 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug 'validator': bool, }, } + + def get_custom_panels(self, instance_type: str, instance_id: int, request): + """Return a list of custom panels to be injected into the UI.""" + panels = [] + + # First, add a custom panel which will appear on every type of page + # This panel will contain a simple message + panels.append({ + 'name': 'sample_panel', + 'label': 'Sample Panel', + 'content': 'This is a sample panel which appears on every page. It renders a simple string of HTML content.', + }) + + # Next, add a custom panel which will appear on the 'part' page + if self.get_setting('ENABLE_PART_PANELS') and instance_type == 'part': + panels.append({ + 'name': 'part_panel', + 'label': 'Part Panel', + 'content': 'This is a custom panel which appears on the Part view page.', + }) + + # Next, add a custom panel which will appear on the 'purchaseorder' page + if ( + self.get_setting('ENABLE_PURCHASE_ORDER_PANELS') + and instance_type == 'purchaseorder' + ): + panels.append({ + 'name': 'purchase_order_panel', + 'label': 'Purchase Order Panel', + 'content': 'This is a custom panel which appears on the Purchase Order view page.', + }) + + return panels diff --git a/src/backend/InvenTree/plugin/serializers.py b/src/backend/InvenTree/plugin/serializers.py index 8bd385c5e0..11d6a7de18 100644 --- a/src/backend/InvenTree/plugin/serializers.py +++ b/src/backend/InvenTree/plugin/serializers.py @@ -311,10 +311,26 @@ class PluginPanelSerializer(serializers.Serializer): class Meta: """Meta for serializer.""" - fields = ['plugin', 'name', 'label', 'icon'] + fields = ['plugin', 'name', 'label', 'icon', 'content', 'source'] - plugin = serializers.CharField(label=_('Plugin Key')) - name = serializers.CharField(label=_('Panel Name')) - label = serializers.CharField(label=_('Panel Label')) - icon = serializers.CharField(label=_('Panel Icon')) - content = serializers.CharField(label=_('Panel Content')) + # Required fields + plugin = serializers.CharField( + label=_('Plugin Key'), required=True, allow_blank=False + ) + name = serializers.CharField( + label=_('Panel Name'), required=True, allow_blank=False + ) + label = serializers.CharField( + label=_('Panel Title'), required=True, allow_blank=False + ) + + # Optional fields + icon = serializers.CharField( + label=_('Panel Icon'), required=False, allow_blank=True + ) + content = serializers.CharField( + label=_('Panel Content (HTML)'), required=False, allow_blank=True + ) + source = serializers.CharField( + label=_('Panel Source (javascript)'), required=False, allow_blank=True + )