2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-06-15 04:50:49 +00:00

Example of plugin panel selection based on page

This commit is contained in:
Oliver Walters
2024-06-18 13:17:30 +00:00
parent 299839312f
commit e03dafbdd6
2 changed files with 54 additions and 25 deletions
+41 -23
View File
@@ -427,29 +427,47 @@ class PluginPanelList(APIView):
# TODO: Allow plugins to fill this data out
...
panels = [
{
'plugin': 'myplugin',
'name': 'test-plugin',
'label': 'My Plugin',
'icon': 'part',
'content': '<div>hello world</div>',
},
{
'plugin': 'myplugin',
'name': 'test-plugin-2',
'label': 'My Plugin 2',
'icon': 'email',
'content': '<div>hello world 2</div>',
},
{
'plugin': 'myplugin',
'name': 'test-plugin-3',
'label': 'My Plugin 3',
'icon': 'website',
'content': '<div>hello world 3</div>',
},
]
user = request.user
target_model = request.query_params.get('target_model', None)
target_id = request.query_params.get('target_id', None)
if target_model == 'part' and target_id:
panels = [
*panels,
{
'plugin': 'myplugin',
'name': 'test-plugin',
'label': 'My Plugin',
'icon': 'part',
'content': '<div>hello world</div>',
},
{
'plugin': 'myplugin',
'name': 'test-plugin-2',
'label': 'My Plugin 2',
'icon': 'email',
'content': '<div>hello world 2</div>',
},
{
'plugin': 'myplugin',
'name': 'test-plugin-3',
'label': 'My Plugin 3',
'icon': 'website',
'content': '<div>hello world 3</div>',
},
]
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)