2025-06-25 10:55:50 +02:00
|
|
|
|
|
|
|
|
class PhysicalPositionMenu {
|
|
|
|
|
|
|
|
|
|
// 1) Server-side: provide the option groups
|
|
|
|
|
getAllMenuData() {
|
|
|
|
|
return {
|
|
|
|
|
positionGroups: [
|
|
|
|
|
{ group: 'Positional', options: [
|
2025-07-01 17:05:09 +02:00
|
|
|
{ value: 'upstream', label: '← Upstream', icon: '←'},
|
|
|
|
|
{ value: 'atEquipment', label: '⊥ in place' , icon: '⊥' },
|
|
|
|
|
{ value: 'downstream', label: '→ Downstream' , icon: '→' }
|
2025-06-25 10:55:50 +02:00
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2) HTML template (pure markup)
|
|
|
|
|
getHtmlTemplate() {
|
|
|
|
|
return `
|
|
|
|
|
<hr />
|
|
|
|
|
<h3>Physical Position vs parent</h3>
|
|
|
|
|
<div class="form-row">
|
2025-06-25 14:59:37 +02:00
|
|
|
<label for="node-input-positionVsParent"><i class="fa fa-map-marker"></i>Position</label>
|
|
|
|
|
<select id="node-input-positionVsParent" style="width:70%;">
|
2025-06-25 10:55:50 +02:00
|
|
|
<!-- optgroups will be injected -->
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<hr />
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3) HTML injector
|
|
|
|
|
getHtmlInjectionCode(nodeName) {
|
|
|
|
|
const tpl = this.getHtmlTemplate()
|
|
|
|
|
.replace(/`/g,'\\`').replace(/\$/g,'\\$');
|
|
|
|
|
return `
|
|
|
|
|
// PhysicalPosition HTML injection for ${nodeName}
|
|
|
|
|
window.EVOLV.nodes.${nodeName}.positionMenu.injectHtml = function() {
|
|
|
|
|
const ph = document.getElementById('position-fields-placeholder');
|
|
|
|
|
if (ph && !ph.hasChildNodes()) {
|
|
|
|
|
ph.innerHTML = \`${tpl}\`;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4) Data-loader injector
|
|
|
|
|
getDataInjectionCode(nodeName) {
|
|
|
|
|
return `
|
|
|
|
|
// PhysicalPosition data loader for ${nodeName}
|
|
|
|
|
window.EVOLV.nodes.${nodeName}.positionMenu.loadData = function(node) {
|
|
|
|
|
const data = window.EVOLV.nodes.${nodeName}.menuData.position;
|
2025-06-25 14:59:37 +02:00
|
|
|
const sel = document.getElementById('node-input-positionVsParent');
|
2025-06-25 10:55:50 +02:00
|
|
|
if (!sel) return;
|
|
|
|
|
sel.innerHTML = '';
|
|
|
|
|
(data.positionGroups||[]).forEach(grp => {
|
|
|
|
|
const optg = document.createElement('optgroup');
|
|
|
|
|
optg.label = grp.group;
|
|
|
|
|
grp.options.forEach(o=>{
|
|
|
|
|
const opt = document.createElement('option');
|
|
|
|
|
opt.value = o.value;
|
|
|
|
|
opt.textContent = o.label;
|
2025-07-01 17:05:09 +02:00
|
|
|
opt.setAttribute('data-icon', o.icon);
|
2025-06-25 10:55:50 +02:00
|
|
|
optg.appendChild(opt);
|
|
|
|
|
});
|
|
|
|
|
sel.appendChild(optg);
|
|
|
|
|
});
|
|
|
|
|
// default to “atEquipment” if not set
|
2025-06-25 14:59:37 +02:00
|
|
|
sel.value = node.positionVsParent || 'atEquipment';
|
2025-06-25 10:55:50 +02:00
|
|
|
};
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 5) (no special events needed, but stub for symmetry)
|
|
|
|
|
getEventInjectionCode(nodeName) {
|
|
|
|
|
return `
|
|
|
|
|
// PhysicalPosition events for ${nodeName}
|
|
|
|
|
window.EVOLV.nodes.${nodeName}.positionMenu.wireEvents = function(node) {
|
|
|
|
|
// no dynamic behavior
|
|
|
|
|
};
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 6) Save-logic injector
|
|
|
|
|
getSaveInjectionCode(nodeName) {
|
|
|
|
|
return `
|
|
|
|
|
// PhysicalPosition Save injection for ${nodeName}
|
|
|
|
|
window.EVOLV.nodes.${nodeName}.positionMenu.saveEditor = function(node) {
|
2025-06-25 14:59:37 +02:00
|
|
|
const sel = document.getElementById('node-input-positionVsParent');
|
|
|
|
|
node.positionVsParent = sel? sel.value : 'atEquipment';
|
2025-07-01 17:05:09 +02:00
|
|
|
node.positionLabel = sel? sel.options[sel.selectedIndex].textContent : 'At Equipment';
|
|
|
|
|
node.positionIcon = sel? sel.options[sel.selectedIndex].getAttribute('data-icon') : 'fa fa-cog';
|
2025-06-25 10:55:50 +02:00
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 7) Compose everything into one client bundle
|
|
|
|
|
getClientInitCode(nodeName) {
|
|
|
|
|
const htmlCode = this.getHtmlInjectionCode(nodeName);
|
|
|
|
|
const dataCode = this.getDataInjectionCode(nodeName);
|
|
|
|
|
const eventCode = this.getEventInjectionCode(nodeName);
|
|
|
|
|
const saveCode = this.getSaveInjectionCode(nodeName);
|
|
|
|
|
|
|
|
|
|
return `
|
|
|
|
|
// --- PhysicalPositionMenu for ${nodeName} ---
|
|
|
|
|
window.EVOLV.nodes.${nodeName}.positionMenu =
|
|
|
|
|
window.EVOLV.nodes.${nodeName}.positionMenu || {};
|
|
|
|
|
|
|
|
|
|
${htmlCode}
|
|
|
|
|
${dataCode}
|
|
|
|
|
${eventCode}
|
|
|
|
|
${saveCode}
|
|
|
|
|
|
|
|
|
|
// hook into oneditprepare
|
|
|
|
|
window.EVOLV.nodes.${nodeName}.positionMenu.initEditor = function(node) {
|
|
|
|
|
this.injectHtml();
|
|
|
|
|
this.loadData(node);
|
|
|
|
|
this.wireEvents(node);
|
|
|
|
|
};
|
|
|
|
|
`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = PhysicalPositionMenu;
|