mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Adds a PanelMixin plugin mixin class
Intended to allow rendering of custom panels on pages
This commit is contained in:
parent
170cb54490
commit
28e16616e5
@ -542,3 +542,47 @@ class APICallMixin:
|
|||||||
if simple_response:
|
if simple_response:
|
||||||
return response.json()
|
return response.json()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class PanelMixin:
|
||||||
|
"""
|
||||||
|
Mixin which allows integration of custom 'panels' into a particular page.
|
||||||
|
|
||||||
|
The mixin provides a number of key functionalities:
|
||||||
|
|
||||||
|
- Adds an (initially hidden) panel to the page
|
||||||
|
- Allows rendering of custom templated content to the panel
|
||||||
|
- Adds a menu item to the 'navbar' on the left side of the screen
|
||||||
|
- Allows custom javascript to be run when the panel is initially loaded
|
||||||
|
|
||||||
|
The PanelMixin class allows multiple panels to be returned for any page,
|
||||||
|
and also allows the plugin to return panels for many different pages.
|
||||||
|
|
||||||
|
Any class implementing this mixin must provide the 'get_custom_panels' method,
|
||||||
|
which dynamically returns the custom panels for a particular page.
|
||||||
|
|
||||||
|
This method is provided with:
|
||||||
|
|
||||||
|
- page: The name of the page e.g. 'part-detail'
|
||||||
|
- instance: The model instance specific to the page
|
||||||
|
- request: The request object responsible for the page load
|
||||||
|
|
||||||
|
It must return a list of CustomPanel class instances (see below).
|
||||||
|
|
||||||
|
Note that as this is called dynamically (per request),
|
||||||
|
then the actual panels returned can vary depending on the particular request or page
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
class CustomPanel:
|
||||||
|
...
|
||||||
|
|
||||||
|
class MixinMeta:
|
||||||
|
MIXIN_NAME = 'Panel'
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.add_mixin('panel', True, __class__)
|
||||||
|
|
||||||
|
def get_custom_panels(self, page, instance, request):
|
||||||
|
raise NotImplementedError(f"{__class__} is missing the 'get_custom_panels' method")
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
Utility class to enable simpler imports
|
Utility class to enable simpler imports
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ..builtin.integration.mixins import APICallMixin, AppMixin, LabelPrintingMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin
|
from ..builtin.integration.mixins import APICallMixin, AppMixin, LabelPrintingMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin, PanelMixin
|
||||||
|
|
||||||
from common.notifications import SingleNotificationMethod, BulkNotificationMethod
|
from common.notifications import SingleNotificationMethod, BulkNotificationMethod
|
||||||
|
|
||||||
from ..builtin.action.mixins import ActionMixin
|
from ..builtin.action.mixins import ActionMixin
|
||||||
@ -17,6 +18,7 @@ __all__ = [
|
|||||||
'ScheduleMixin',
|
'ScheduleMixin',
|
||||||
'SettingsMixin',
|
'SettingsMixin',
|
||||||
'UrlsMixin',
|
'UrlsMixin',
|
||||||
|
'PanelMixin',
|
||||||
'ActionMixin',
|
'ActionMixin',
|
||||||
'BarcodeMixin',
|
'BarcodeMixin',
|
||||||
'SingleNotificationMethod',
|
'SingleNotificationMethod',
|
||||||
|
22
InvenTree/plugin/samples/integration/custom_panel_sample.py
Normal file
22
InvenTree/plugin/samples/integration/custom_panel_sample.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"""
|
||||||
|
Sample plugin which renders custom panels on certain pages
|
||||||
|
"""
|
||||||
|
|
||||||
|
from plugin import IntegrationPluginBase
|
||||||
|
from plugin.mixins import PanelMixin
|
||||||
|
|
||||||
|
|
||||||
|
class CustomPanelSample(PanelMixin, IntegrationPluginBase):
|
||||||
|
"""
|
||||||
|
A sample plugin which renders some custom panels.
|
||||||
|
"""
|
||||||
|
|
||||||
|
PLUGIN_NAME = "CustomPanelExample"
|
||||||
|
PLUGIN_SLUG = "panel"
|
||||||
|
PLUGIN_TITLE = "Custom Panel Example"
|
||||||
|
|
||||||
|
def get_custom_panels(self, page, instance, request):
|
||||||
|
|
||||||
|
print("get_custom_panels:")
|
||||||
|
|
||||||
|
return []
|
Loading…
Reference in New Issue
Block a user