mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	allow to specify the function name via the source file string divided by a colon
This commit is contained in:
		@@ -137,7 +137,7 @@ class SampleUserInterfacePlugin(SettingsMixin, UserInterfaceMixin, InvenTreePlug
 | 
				
			|||||||
                        'title': 'Sample Template Editor',
 | 
					                        'title': 'Sample Template Editor',
 | 
				
			||||||
                        'icon': 'keywords',
 | 
					                        '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',
 | 
					                        'title': 'Sample Template Preview',
 | 
				
			||||||
                        'icon': 'category',
 | 
					                        'icon': 'category',
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                    'source': '/static/plugin/sample_template_preview.js',
 | 
					                    'source': '/static/plugin/sample_template.js:getTemplatePreview',
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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>";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -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);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -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>";
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -37,6 +37,12 @@ export async function findExternalPluginFunction(
 | 
				
			|||||||
  source: string,
 | 
					  source: string,
 | 
				
			||||||
  functionName: string
 | 
					  functionName: string
 | 
				
			||||||
): Promise<Function | null> {
 | 
					): 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);
 | 
					  const module = await loadExternalPluginSource(source);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (module && module[functionName]) {
 | 
					  if (module && module[functionName]) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user