Skip to content

Commit

Permalink
add 'shared' markdown keyword and action button to render vm infos ab…
Browse files Browse the repository at this point in the history
…out shared vms
  • Loading branch information
Philip Prinz authored and Philip Prinz committed Nov 26, 2024
1 parent 15f283f commit 8c7be59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/app/scenario/md-editor/markdownActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,18 @@ export const ACTIONS: MDEditorAction[] = [
},
{
name: 'VM-Info',
actionBefore: '${vmInfo:<nodeName>:<attribute>}',
actionBefore: '${vminfo:<nodeName>:<attribute>}',
actionAfter: '',
actionEmpty: '',
icon: 'host',
},
{
name: 'Shared-VM-Info',
actionBefore: '${shared:<nodeName>:<attribute>}',
actionAfter: '',
actionEmpty: '',
icon: 'rack-server',
},
{
name: 'Task',
actionBefore: '```verifyTask:<nodeName>:<taskName>',
Expand Down
32 changes: 23 additions & 9 deletions src/app/step/hf-markdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class HfMarkdownComponent implements OnChanges {

constructor(
public markdownService: MarkdownService,
private ctrService: CtrService,
private ctrService: CtrService
) {
mermaid.initialize({
startOnLoad: false,
Expand Down Expand Up @@ -156,7 +156,7 @@ ${token}`;
private renderHighlightedCode(
code: string,
language: string,
fileName?: string,
fileName?: string
) {
const fileNameTag = fileName
? `<p class="filename" (click)=createFile(code,node)>${fileName}</p>`
Expand Down Expand Up @@ -225,26 +225,40 @@ ${token}`;
}

ngOnChanges() {
if(!this.content){
return
if (!this.content) {
return;
}

const contentWithReplacedTokens = this.replaceSessionToken(
this.replaceVmInfoTokens(this.content),
this.replaceVmInfoTokens(this.replaceSharedVmInfoTokens(this.content))
);
// the parse method internally uses the Angular Dom Sanitizer and is therefore safe to use
this.processedContent = this.markdownService.parse(
contentWithReplacedTokens,
contentWithReplacedTokens
);
}

private replaceVmInfoTokens(content: string) {
return content.replace(
/\$\{vmInfo:([^:]*):([^}]*)\}/g,
/\$\{vminfo:([^:]*):([^}]*)\}/g,
(match, vmName, propName) => {
const vm = this.context.vmInfo?.[vmName.toLowerCase()];
return String(vm?.[propName as keyof VM] ?? match);
},
return String(
vm?.vm_type != 'SHARED' ? vm?.[propName as keyof VM] : match
);
}
);
}

private replaceSharedVmInfoTokens(content: string) {
return content.replace(
/\$\{shared:([^:]*):([^}]*)\}/g,
(match, vmName, propName) => {
const vm = this.context.vmInfo?.[vmName.toLowerCase()];
return String(
vm?.vm_type == 'SHARED' ? vm?.[propName as keyof VM] : match
);
}
);
}

Expand Down

0 comments on commit 8c7be59

Please sign in to comment.