// based on edit Mode, edit=false
mode = new BehaviorSubject(false);
list = new BehaviorSubject('');
+ modeState: Observable<boolean>;
+ listState: Observable<string>;
constructor() {
+ this.mode = new BehaviorSubject(false);
+ this.list = new BehaviorSubject('');
+ this.modeState = this.mode.asObservable();
+ this.listState = this.list.asObservable();
}
isEdit(): Observable<boolean> {
- return this.mode.asObservable();
+ return this.modeState;
}
enableEdit() {
this.mode.next(true);
this.list.next(filename);
}
listAction(): Observable<string> {
- return this.list.asObservable();
+ return this.listState;
}
}
-import {Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
+import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
import { PackageCreationStore } from '../../package-creation.store';
import { TemplateInfo, TemplateStore } from '../../template.store';
const parser = new XmlParser();
this.variables = parser.getVariables(fileReader.result.toString());
}
- console.log(this.variables);
+ console.log('variables = ' + this.variables);
this.getMappingTableFromTemplate(null);
};
e.preventDefault();
}
this.variables = this.getTemplateVariable(this.templateFileContent);
- console.log(this.variables);
+ console.log('variables = ' + this.variables);
if (this.variables && this.variables.length > 0) {
console.log('base');
this.packageCreationService.getTemplateAndMapping(this.variables).subscribe(res => {
}
ngOnInit() {
+ this.templateAndMappingMap = new Map<string, TemplateAndMapping>();
+ this.edit = false;
if (this.route.snapshot.paramMap.has('id')) {
this.isCreate = false;
this.sharedService.isEdit().subscribe(res => {
}
this.templateStore.changeTemplateInfo(templateInfo);
this.openCreationView();
- this.sharedService.enableEdit();
+ if (templateInfo.fileName && templateInfo.fileName.length > 0) {
+ this.sharedService.enableEdit();
+ }
});
}
variables: Set<string> = new Set();
getVariables(fileContent: string): string[] {
if (fileContent.includes('{{')) {
- const xmlSplit = fileContent.split(new RegExp('[{]+[ ]*.[V-v]alues.'));
+ // '[{]+[ ]*.[V-v]alues.' old regex
+ const xmlSplit = fileContent.split(new RegExp('[{]+[ ]*.'));
for (const val of xmlSplit) {
const res = val.substring(0, val.indexOf('}}'));
if (res && res.length > 0) {
- this.variables.add(res.trim());
+ console.log(res);
+ if (res.includes('Value')) {
+ this.variables.add(this.extractValues(res.trim()));
+ } else {
+ this.variables.add(this.extractParent(res.trim()).toLowerCase());
+ }
}
-
}
}
return [...this.variables];
}
+ extractValues(value) {
+ return value.split('Values.')[1];
+ }
+ extractParent(value): string {
+ return value.split('.')[0];
+ }
+
}
/*
const parser = parserFactory.getParser(fileContent, FileExtension.Jinja);
const res = parser.getVariables(fileContent);
console.log(res);
- expect(res.length).toEqual(2);
+ expect(res.length).toEqual(4);
expect(res[0]).toEqual('vpg_name_0');
expect(res[1]).toEqual('vnf_name');
});
+
+
+
+
+
+ it('Test Velocity YML Parser', () => {
+ const fileContent = `apiVersion: v1
+ kind: Service
+ metadata:
+ name: {{ .Values.vpg_name_0 }}-ssh
+ labels:
+ vnf-name: {{ .Values.vnf_name }}
+ vf-module-name: {{ .Values.vpg_name_0 }}
+ release: {{ .Release.Name }}
+ chart: {{ .Chart.Name }}
+ spec:
+ type: NodePort
+ ports:
+ port: 22
+ nodePort: \${vpg-management-port}
+ selector:
+ vf-module-name: {{ .Values.vpg_name_0 }}
+ release: {{ .Release.Name }}
+ chart: {{ .Chart.Name }}`;
+
+ const parser = parserFactory.getParser(fileContent, FileExtension.Velocity);
+ const res = parser.getVariables(fileContent);
+ console.log(res);
+ expect(res.length).toEqual(1);
+ expect(res[0]).toEqual('vpg-management-port');
+
+ });
+
+
+
});
} else if (this.isASCII(fileContent)) {
parser = new ASCIIParser();
} else {
+ console.log('Velocity YML parser....');
parser = new VtlYMLParser();
}
} else if (this.isASCII(fileContent)) {
parser = new ASCIIParser();
} else {
+ console.log('Jinja YML parser....');
parser = new JinjaYMLParser();
}
const xmlSplit = fileContent.split('${');
for (const val of xmlSplit) {
const res = val.substring(0, val.indexOf('}'));
- if (res && res.length > 0) {
+ if (res && res.length > 0 && !res.includes('{')) {
this.variables.add(res);
}