mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 11:36:44 +00:00
Updates to samplepanel plugin
- Enhanced content for "hello world" panel - Add an optional panel which breaks rendering
This commit is contained in:
parent
14b60cdedc
commit
ebcb9685b5
@ -12,7 +12,7 @@ class EventPluginSample(EventMixin, InvenTreePlugin):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
NAME = "EventPlugin"
|
NAME = "EventPlugin"
|
||||||
SLUG = "event"
|
SLUG = "sampleevent"
|
||||||
TITLE = "Triggered Events"
|
TITLE = "Triggered Events"
|
||||||
|
|
||||||
def process_event(self, event, *args, **kwargs):
|
def process_event(self, event, *args, **kwargs):
|
||||||
|
@ -15,17 +15,23 @@ class CustomPanelSample(PanelMixin, SettingsMixin, InvenTreePlugin):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
NAME = "CustomPanelExample"
|
NAME = "CustomPanelExample"
|
||||||
SLUG = "panel"
|
SLUG = "samplepanel"
|
||||||
TITLE = "Custom Panel Example"
|
TITLE = "Custom Panel Example"
|
||||||
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 = {
|
SETTINGS = {
|
||||||
'ENABLE_HELLO_WORLD': {
|
'ENABLE_HELLO_WORLD': {
|
||||||
'name': 'Hello World',
|
'name': 'Enable Hello World',
|
||||||
'description': 'Enable a custom hello world panel on every page',
|
'description': 'Enable a custom hello world panel on every page',
|
||||||
'default': False,
|
'default': False,
|
||||||
'validator': bool,
|
'validator': bool,
|
||||||
|
},
|
||||||
|
'ENABLE_BROKEN_PANEL': {
|
||||||
|
'name': 'Enable Broken Panel',
|
||||||
|
'description': 'Enable a panel with rendering issues',
|
||||||
|
'default': False,
|
||||||
|
'validator': bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,15 +64,42 @@ class CustomPanelSample(PanelMixin, SettingsMixin, InvenTreePlugin):
|
|||||||
]
|
]
|
||||||
|
|
||||||
if self.get_setting('ENABLE_HELLO_WORLD'):
|
if self.get_setting('ENABLE_HELLO_WORLD'):
|
||||||
|
|
||||||
|
# We can use template rendering in the raw content
|
||||||
|
content = """
|
||||||
|
<strong>Hello world!</strong>
|
||||||
|
<hr>
|
||||||
|
<div class='alert-alert-block alert-info'>
|
||||||
|
<em>We can render custom content using the templating system!</em>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
<table class='table table-striped'>
|
||||||
|
<tr><td><strong>Path</strong></td><td>{{ request.path }}</tr>
|
||||||
|
<tr><td><strong>User</strong></td><td>{{ user.username }}</tr>
|
||||||
|
</table>
|
||||||
|
"""
|
||||||
|
|
||||||
panels.append({
|
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': content,
|
||||||
'description': 'A simple panel which renders hello world',
|
'description': 'A simple panel which renders hello world',
|
||||||
'javascript': 'console.log("Hello world, from a custom panel!");',
|
'javascript': 'console.log("Hello world, from a custom panel!");',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if self.get_setting('ENABLE_BROKEN_PANEL'):
|
||||||
|
|
||||||
|
# Enabling this panel will cause panel rendering to break,
|
||||||
|
# due to the invalid tags
|
||||||
|
panels.append({
|
||||||
|
'title': 'Broken Panel',
|
||||||
|
'icon': 'fas fa-times-circle',
|
||||||
|
'content': '{% tag_not_loaded %}',
|
||||||
|
'description': 'This panel is broken',
|
||||||
|
'javascript': '{% another_bad_tag %}',
|
||||||
|
})
|
||||||
|
|
||||||
# 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):
|
||||||
panels.append({
|
panels.append({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user