Skip to content

Commit

Permalink
Updates to match InvenTree code
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Oct 16, 2024
1 parent 9c90623 commit aafff67
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/src/WirevizPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function WirevizPanel({context}: {context: any}) {
* @param target
* @param context
*/
export function renderPanel(target: HTMLElement | null, context: any) {
export function renderWirevizPanel(target: HTMLElement | null, context: any) {

createRoot(target!).render(
<StrictMode>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { renderPanel } from './WirevizPanel.tsx'
import { renderWirevizPanel } from './WirevizPanel.tsx'

/**
* Demo for rendering the Wireviz panel with some sample content
*/
renderPanel(
renderWirevizPanel(
document.getElementById('root'),
{
context: {
Expand Down
25 changes: 20 additions & 5 deletions inventree_wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class WirevizPlugin(PanelMixin, ReportMixin, SettingsMixin, UrlsMixin, UserInter
TITLE = "Wireviz Plugin"

# Javascript file which renders custom plugin settings
ADMIN_PANEL_JS_FILE = "WirevizSettings.js"
ADMIN_SOURCE = "WirevizSettings.js"

# Filenames and key constants
HARNESS_SVG_FILE = "wireviz_harness.svg"
Expand Down Expand Up @@ -219,18 +219,33 @@ def get_custom_panels(self, view, request):

return panels

def get_ui_panels(self, instance_type, instance_id, request, **kwargs):
def get_ui_panels(self, request, context=None, **kwargs):
"""Return custom UI panels for the wireviz plugin."""

from build.models import Build

context = context or {}

target_model = context.get('target_model', None)
target_id = context.get('target_id', None)

panels = []
part = None

if instance_type == 'part':
if target_model == 'part':
try:
part = Part.objects.get(pk=instance_id)
part = Part.objects.get(pk=target_id)
except Part.DoesNotExist:
part = None

elif target_model == 'build':
# Display on the "build" page too
try:
build = Build.objects.get(pk=target_id)
part = build.part
except Build.DoesNotExist:
part = None

if part and part.get_metadata('wireviz'):

ctx = self.panel_context_from_instance(part)
Expand All @@ -241,7 +256,7 @@ def get_ui_panels(self, instance_type, instance_id, request, **kwargs):
'name': 'wireviz',
'label': 'Harness Diagram',
'context': ctx,
'source': self.plugin_static_file('WirevizPanel.js'),
'source': self.plugin_static_file('WirevizPanel.js:renderWirevizPanel'),
})

return panels
Expand Down

0 comments on commit aafff67

Please sign in to comment.