mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +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 import IntegrationPluginBase
|
||||||
from plugin.mixins import PanelMixin
|
from plugin.mixins import PanelMixin, SettingsMixin
|
||||||
|
|
||||||
from part.views import PartDetail
|
from part.views import PartDetail
|
||||||
from stock.views import StockLocationDetail
|
from stock.views import StockLocationDetail
|
||||||
|
|
||||||
|
|
||||||
class CustomPanelSample(PanelMixin, IntegrationPluginBase):
|
class CustomPanelSample(PanelMixin, SettingsMixin, IntegrationPluginBase):
|
||||||
"""
|
"""
|
||||||
A sample plugin which renders some custom panels.
|
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"
|
DESCRIPTION = "An example plugin demonstrating how custom panels can be added to the user interface"
|
||||||
VERSION = "0.1"
|
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):
|
def render_location_info(self, loc):
|
||||||
"""
|
"""
|
||||||
Demonstrate that we can render information particular to a page
|
Demonstrate that we can render information particular to a page
|
||||||
@ -46,18 +55,20 @@ class CustomPanelSample(PanelMixin, IntegrationPluginBase):
|
|||||||
|
|
||||||
panels = [
|
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
|
# This 'hello world' panel will be displayed on any view which implements custom panels
|
||||||
'title': 'Hello World',
|
'title': 'Hello World',
|
||||||
'icon': 'fas fa-boxes',
|
'icon': 'fas fa-boxes',
|
||||||
'content': '<b>Hello world!</b>',
|
'content': '<b>Hello world!</b>',
|
||||||
'description': 'A simple panel which renders hello world',
|
'description': 'A simple panel which renders hello world',
|
||||||
'javascript': 'alert("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
|
# This panel will *only* display on the PartDetail view
|
||||||
if isinstance(view, PartDetail):
|
if isinstance(view, PartDetail):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user