-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
BugSomething isn't workingSomething isn't working
Milestone
Description
Describe the bug
When we put the position of component(s) in the library template. After using this component template in leto-modelizer position are not retrieve from template configuration, due to id are generate in component template file and not share with the configuration of the position.
Potential solution
Create a map of id link by a key:
const ids = new Map();In template use this map to store id associated of the key:
# serverX is the key associated to the new id
resource "server" "{{ generateId('serverX', 'resource_')}}" {
(...)
}Then in the position configuration you can reuse it with getId function:
{
"terrator-plugin": {
"{{getId(serverX)}}": {
"x": 30,
"y": 30,
"width": 110,
"height": 80,
"needsResizing": false,
"needsPositioning": false
},
}
}So in Leto-modelizer you have to modify two functions in src/composables/TemplateManager.js:
getTemplateFilesgenerateTemplate
export function generateTemplate(ids, content) {
return nunjucks.renderString(content, {
generateId: (key, prefix) => {
const id = `${prefix || ''}${randomHexString(6)}`;
ids.set(key, id);
return id;
},
getId: (key) => ids.get(key),
});
}
(...)
export async function getTemplateFiles(path, templateDefinition) {
const ids = new Map();
return Promise.all(
templateDefinition.files.map(
(file) => getTemplateFileByPath(`templates/${templateDefinition.key}/${file}`)
.then(({ data }) => new FileInput({
path: `${path}/${file}`,
content: generateTemplate(ids, data),
})),
),
);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugSomething isn't workingSomething isn't working
Type
Projects
Status
π Ready