Added new menu jsons
This commit is contained in:
@@ -2,13 +2,17 @@ const AssetMenu = require('./asset.js');
|
||||
const { TagcodeApp, DynamicAssetMenu } = require('./tagcodeApp.js');
|
||||
const LoggerMenu = require('./logger.js');
|
||||
const PhysicalPositionMenu = require('./physicalPosition.js');
|
||||
const ConfigManager = require('../configs');
|
||||
|
||||
class MenuManager {
|
||||
|
||||
constructor() {
|
||||
this.registeredMenus = new Map();
|
||||
this.configManager = new ConfigManager('../configs');
|
||||
// Register factory functions
|
||||
this.registerMenu('asset', () => new AssetMenu()); // static menu to be replaced by dynamic one but later
|
||||
this.registerMenu('asset', (nodeName) => new AssetMenu({
|
||||
softwareType: this._getSoftwareType(nodeName)
|
||||
})); // static menu to be replaced by dynamic one but later
|
||||
//this.registerMenu('asset', (nodeName) => new DynamicAssetMenu(nodeName, new TagcodeApp()));
|
||||
this.registerMenu('logger', () => new LoggerMenu());
|
||||
this.registerMenu('position', () => new PhysicalPositionMenu());
|
||||
@@ -23,6 +27,20 @@ class MenuManager {
|
||||
this.registeredMenus.set(menuType, menuFactory);
|
||||
}
|
||||
|
||||
_getSoftwareType(nodeName) {
|
||||
if (!nodeName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const config = this.configManager.getConfig(nodeName);
|
||||
return config?.functionality?.softwareType || nodeName;
|
||||
} catch (error) {
|
||||
console.warn(`Unable to determine softwareType for ${nodeName}: ${error.message}`);
|
||||
return nodeName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a complete endpoint script with data and initialization functions
|
||||
* @param {string} nodeName - The name of the node type
|
||||
@@ -54,7 +72,7 @@ class MenuManager {
|
||||
try {
|
||||
const handler = instantiatedMenus.get(menuType);
|
||||
if (handler && typeof handler.getAllMenuData === 'function') {
|
||||
menuData[menuType] = handler.getAllMenuData();
|
||||
menuData[menuType] = handler.getAllMenuData(nodeName);
|
||||
} else {
|
||||
// Provide default empty data if method doesn't exist
|
||||
menuData[menuType] = {};
|
||||
@@ -172,4 +190,4 @@ class MenuManager {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MenuManager;
|
||||
module.exports = MenuManager;
|
||||
|
||||
Reference in New Issue
Block a user