diff --git a/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py b/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py index 800698e9a7..07cd24aabf 100644 --- a/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py +++ b/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py @@ -137,7 +137,7 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug 'title': 'Sample Template Editor', 'icon': 'keywords', }, - 'source': '/static/plugin/sample_template_editor.js', + 'source': '/static/plugin/sample_template.js:getTemplateEditor', } ] @@ -150,7 +150,7 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug 'title': 'Sample Template Preview', 'icon': 'category', }, - 'source': '/static/plugin/sample_template_preview.js', + 'source': '/static/plugin/sample_template.js:getTemplatePreview', } ] diff --git a/src/backend/InvenTree/plugin/samples/static/plugin/sample_template.js b/src/backend/InvenTree/plugin/samples/static/plugin/sample_template.js new file mode 100644 index 0000000000..bddaa817fd --- /dev/null +++ b/src/backend/InvenTree/plugin/samples/static/plugin/sample_template.js @@ -0,0 +1,32 @@ +export function getTemplateEditor({ featureContext, pluginContext }) { + const { ref } = featureContext; + console.log("Template editor feature was called with", featureContext, pluginContext); + const t = document.createElement("textarea"); + t.rows = 25; + t.cols = 60; + + featureContext.registerHandlers({ + setCode: (code) => { + t.value = code; + }, + getCode: () => { + return t.value; + } + }); + + ref.innerHTML = ""; + ref.appendChild(t); +} + +export function getTemplatePreview({ featureContext, pluginContext }) { + const { ref } = featureContext; + console.log("Template preview feature was called with", featureContext, pluginContext); + + featureContext.registerHandlers({ + updatePreview: (...args) => { + console.log("updatePreview", args); + } + }); + + ref.innerHTML = "

Hello world

"; +} diff --git a/src/backend/InvenTree/plugin/samples/static/plugin/sample_template_editor.js b/src/backend/InvenTree/plugin/samples/static/plugin/sample_template_editor.js deleted file mode 100644 index 642162b640..0000000000 --- a/src/backend/InvenTree/plugin/samples/static/plugin/sample_template_editor.js +++ /dev/null @@ -1,19 +0,0 @@ -export function getFeature({ featureContext, pluginContext }) { - const { ref } = featureContext; - console.log("Template editor feature was called with", featureContext, pluginContext); - const t = document.createElement("textarea"); - t.rows = 25; - t.cols = 60; - - featureContext.registerHandlers({ - setCode: (code) => { - t.value = code; - }, - getCode: () => { - return t.value; - } - }); - - ref.innerHTML = ""; - ref.appendChild(t); -} diff --git a/src/backend/InvenTree/plugin/samples/static/plugin/sample_template_preview.js b/src/backend/InvenTree/plugin/samples/static/plugin/sample_template_preview.js deleted file mode 100644 index c90d18d0ae..0000000000 --- a/src/backend/InvenTree/plugin/samples/static/plugin/sample_template_preview.js +++ /dev/null @@ -1,12 +0,0 @@ -export function getFeature({ featureContext, pluginContext }) { - const { ref } = featureContext; - console.log("Template preview feature was called with", featureContext, pluginContext); - - featureContext.registerHandlers({ - updatePreview: (...args) => { - console.log("updatePreview", args); - } - }); - - ref.innerHTML = "

Hello world

"; -} diff --git a/src/frontend/src/components/plugins/PluginSource.tsx b/src/frontend/src/components/plugins/PluginSource.tsx index 6db4640493..69239866e3 100644 --- a/src/frontend/src/components/plugins/PluginSource.tsx +++ b/src/frontend/src/components/plugins/PluginSource.tsx @@ -37,6 +37,12 @@ export async function findExternalPluginFunction( source: string, functionName: string ): Promise { + // The source URL may also include the function name divided by a colon + // otherwise the provided function name will be used + if (source.includes(':')) { + [source, functionName] = source.split(':'); + } + const module = await loadExternalPluginSource(source); if (module && module[functionName]) {