aboutsummaryrefslogtreecommitdiffstats
path: root/cds-ui
diff options
context:
space:
mode:
authorAhmedeldeeb50 <ahmed.eldeeb.ext@orange.com>2020-10-05 10:23:48 +0200
committerAhmedeldeeb50 <ahmed.eldeeb.ext@orange.com>2020-10-05 10:23:48 +0200
commit178dbc0bcb8b3b685a9f1c45eb4d21d062c8ee86 (patch)
treefa644d71bdc7337f19be6789d0666d7e7a8f91d4 /cds-ui
parent133afdcc3d4580cb61e1a2134e0ab617c3901eb0 (diff)
in Jinja Template support the parsing of parent variable in dictionary mapping file
Issue-ID: CCSDK-2866 Signed-off-by: Ahmedeldeeb50 <ahmed.eldeeb.ext@orange.com> Change-Id: Ib3d4f70cd1728e34b8db362dcb1435ea5386cade
Diffstat (limited to 'cds-ui')
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts10
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts6
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts6
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts18
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts37
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts2
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts2
7 files changed, 70 insertions, 11 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts
index 57c2bcbfa..47128130c 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/shared-service.ts
@@ -10,11 +10,17 @@ export class SharedService {
// 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);
@@ -28,7 +34,7 @@ export class SharedService {
this.list.next(filename);
}
listAction(): Observable<string> {
- return this.list.asObservable();
+ return this.listState;
}
}
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts
index 8c4eab8f5..8c1279fbe 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts
@@ -1,4 +1,4 @@
-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';
@@ -290,7 +290,7 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy {
const parser = new XmlParser();
this.variables = parser.getVariables(fileReader.result.toString());
}
- console.log(this.variables);
+ console.log('variables = ' + this.variables);
this.getMappingTableFromTemplate(null);
};
@@ -373,7 +373,7 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy {
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 => {
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts
index 3f54f6742..80e5f7c99 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-listing/templ-mapp-listing.component.ts
@@ -41,6 +41,8 @@ export class TemplMappListingComponent implements OnInit, OnDestroy {
}
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 => {
@@ -152,7 +154,9 @@ export class TemplMappListingComponent implements OnInit, OnDestroy {
}
this.templateStore.changeTemplateInfo(templateInfo);
this.openCreationView();
- this.sharedService.enableEdit();
+ if (templateInfo.fileName && templateInfo.fileName.length > 0) {
+ this.sharedService.enableEdit();
+ }
});
}
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts
index 11d1ad7f0..6ecee9070 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/JinjaYML.ts
@@ -4,18 +4,30 @@ export class JinjaYMLParser implements Parser {
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];
+ }
+
}
/*
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts
index aab37c722..3a1880c99 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/Parser.spec.ts
@@ -72,7 +72,7 @@ fdescribe('ImportsTabComponent', () => {
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');
@@ -115,4 +115,39 @@ fdescribe('ImportsTabComponent', () => {
});
+
+
+
+
+
+ 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');
+
+ });
+
+
+
});
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
index a5c92e441..b64afeed0 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
@@ -23,6 +23,7 @@ export class ParserFactory {
} else if (this.isASCII(fileContent)) {
parser = new ASCIIParser();
} else {
+ console.log('Velocity YML parser....');
parser = new VtlYMLParser();
}
@@ -35,6 +36,7 @@ export class ParserFactory {
} else if (this.isASCII(fileContent)) {
parser = new ASCIIParser();
} else {
+ console.log('Jinja YML parser....');
parser = new JinjaYMLParser();
}
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts
index 4b7d22762..6c3a0e0fd 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/VtlYMLParser.ts
@@ -7,7 +7,7 @@ export class VtlYMLParser implements Parser {
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);
}