2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 11:35:41 +00:00

allow to specify the function name via the source file string divided by a colon

This commit is contained in:
wolflu05
2024-09-18 11:24:01 +02:00
parent 5ec5aa7264
commit a72d845271
5 changed files with 40 additions and 33 deletions

View File

@ -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',
}
]

View File

@ -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 = "<h1>Hello world</h1>";
}

View File

@ -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);
}

View File

@ -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 = "<h1>Hello world</h1>";
}

View File

@ -37,6 +37,12 @@ export async function findExternalPluginFunction(
source: string,
functionName: string
): Promise<Function | null> {
// 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]) {