mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add a configurable setting to the demo plugin
This commit is contained in:
parent
96f61dfcdb
commit
44c4e88646
@ -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': '<b>Hello world!</b>',
|
||||
'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):
|
||||
|
Loading…
Reference in New Issue
Block a user