From a72d845271aa1e2ec54427017849deb4c651f213 Mon Sep 17 00:00:00 2001 From: wolflu05 <76838159+wolflu05@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:24:01 +0200 Subject: [PATCH] allow to specify the function name via the source file string divided by a colon --- .../integration/user_interface_sample.py | 4 +-- .../samples/static/plugin/sample_template.js | 32 +++++++++++++++++++ .../static/plugin/sample_template_editor.js | 19 ----------- .../static/plugin/sample_template_preview.js | 12 ------- .../src/components/plugins/PluginSource.tsx | 6 ++++ 5 files changed, 40 insertions(+), 33 deletions(-) create mode 100644 src/backend/InvenTree/plugin/samples/static/plugin/sample_template.js delete mode 100644 src/backend/InvenTree/plugin/samples/static/plugin/sample_template_editor.js delete mode 100644 src/backend/InvenTree/plugin/samples/static/plugin/sample_template_preview.js 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 = "