mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
[PUI] Panels plugin fix (#8147)
* Rename "get_custom_panels" method - So that PUI plugin does not conflict with CUI plugin * Update docstrings * Rename "get_ui_panels" -> "ui_panels" * Docs fix * rename "ui_panels" -> "get_ui_panels"
This commit is contained in:
parent
6a8875a4a6
commit
8514970da5
@ -18,9 +18,9 @@ When rendering certain content in the user interface, the rendering functions ar
|
|||||||
|
|
||||||
## Custom Panels
|
## Custom Panels
|
||||||
|
|
||||||
Many of the pages in the InvenTree web interface are built using a series of "panels" which are displayed on the page. Custom panels can be added to these pages, by implementing the `get_custom_panels` method:
|
Many of the pages in the InvenTree web interface are built using a series of "panels" which are displayed on the page. Custom panels can be added to these pages, by implementing the `get_ui_panels` method:
|
||||||
|
|
||||||
::: plugin.base.integration.UserInterfaceMixin.UserInterfaceMixin.get_custom_panels
|
::: plugin.base.integration.UserInterfaceMixin.UserInterfaceMixin.get_ui_panels
|
||||||
options:
|
options:
|
||||||
show_bases: False
|
show_bases: False
|
||||||
show_root_heading: False
|
show_root_heading: False
|
||||||
|
@ -19,6 +19,7 @@ import plugin.serializers as PluginSerializers
|
|||||||
from common.api import GlobalSettingsPermissions
|
from common.api import GlobalSettingsPermissions
|
||||||
from common.settings import get_global_setting
|
from common.settings import get_global_setting
|
||||||
from InvenTree.api import MetadataView
|
from InvenTree.api import MetadataView
|
||||||
|
from InvenTree.exceptions import log_error
|
||||||
from InvenTree.filters import SEARCH_ORDER_FILTER
|
from InvenTree.filters import SEARCH_ORDER_FILTER
|
||||||
from InvenTree.mixins import (
|
from InvenTree.mixins import (
|
||||||
CreateAPI,
|
CreateAPI,
|
||||||
@ -433,17 +434,22 @@ class PluginPanelList(APIView):
|
|||||||
if get_global_setting('ENABLE_PLUGINS_INTERFACE'):
|
if get_global_setting('ENABLE_PLUGINS_INTERFACE'):
|
||||||
# Extract all plugins from the registry which provide custom panels
|
# Extract all plugins from the registry which provide custom panels
|
||||||
for _plugin in registry.with_mixin('ui', active=True):
|
for _plugin in registry.with_mixin('ui', active=True):
|
||||||
# Allow plugins to fill this data out
|
try:
|
||||||
plugin_panels = _plugin.get_custom_panels(
|
# Allow plugins to fill this data out
|
||||||
target_model, target_id, request
|
plugin_panels = _plugin.get_ui_panels(
|
||||||
)
|
target_model, target_id, request
|
||||||
|
)
|
||||||
|
|
||||||
if plugin_panels and type(plugin_panels) is list:
|
if plugin_panels and type(plugin_panels) is list:
|
||||||
for panel in plugin_panels:
|
for panel in plugin_panels:
|
||||||
panel['plugin'] = _plugin.slug
|
panel['plugin'] = _plugin.slug
|
||||||
|
|
||||||
# TODO: Validate each panel before inserting
|
# TODO: Validate each panel before inserting
|
||||||
panels.append(panel)
|
panels.append(panel)
|
||||||
|
except Exception:
|
||||||
|
# Custom panels could not load
|
||||||
|
# Log the error and continue
|
||||||
|
log_error(f'{_plugin.slug}.get_ui_panels')
|
||||||
|
|
||||||
return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data)
|
return Response(PluginSerializers.PluginPanelSerializer(panels, many=True).data)
|
||||||
|
|
||||||
|
@ -34,6 +34,10 @@ class UserInterfaceMixin:
|
|||||||
|
|
||||||
- All content is accessed via the API, as requested by the user interface.
|
- All content is accessed via the API, as requested by the user interface.
|
||||||
- This means that content can be dynamically generated, based on the current state of the system.
|
- This means that content can be dynamically generated, based on the current state of the system.
|
||||||
|
|
||||||
|
The following custom UI methods are available:
|
||||||
|
- get_ui_panels: Return a list of custom panels to be injected into the UI
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class MixinMeta:
|
class MixinMeta:
|
||||||
@ -46,8 +50,8 @@ class UserInterfaceMixin:
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
self.add_mixin('ui', True, __class__)
|
self.add_mixin('ui', True, __class__)
|
||||||
|
|
||||||
def get_custom_panels(
|
def get_ui_panels(
|
||||||
self, instance_type: str, instance_id: int, request: Request
|
self, instance_type: str, instance_id: int, request: Request, **kwargs
|
||||||
) -> list[CustomPanel]:
|
) -> list[CustomPanel]:
|
||||||
"""Return a list of custom panels to be injected into the UI.
|
"""Return a list of custom panels to be injected into the UI.
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_custom_panels(self, instance_type: str, instance_id: int, request):
|
def get_ui_panels(self, instance_type: str, instance_id: int, request, **kwargs):
|
||||||
"""Return a list of custom panels to be injected into the UI."""
|
"""Return a list of custom panels to be injected into the UI."""
|
||||||
panels = []
|
panels = []
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user