From 296d2bdbaba99d34ce62a8483b5d8d4f90761379 Mon Sep 17 00:00:00 2001 From: AhmedEldeeb50 Date: Wed, 15 Jul 2020 21:58:59 +0200 Subject: support XML for "Upload Attributes List" button for mapping Issue-ID: CCSDK-2571 Signed-off-by: AhmedEldeeb50 Change-Id: I4164fdef145e92faa2cf2550a036d50273127c6a --- .../templ-mapp-creation.component.ts | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/templ-mapp-creation/templ-mapp-creation.component.ts') 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 af7acc2d0..61ea374a3 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 @@ -10,6 +10,7 @@ import { PackageCreationUtils } from '../../package-creation.utils'; import { JsonConvert, Any } from 'json2typescript'; import { ToastrService } from 'ngx-toastr'; import { SharedService } from '../shared-service'; +import { XmlParser } from '../utils/XmlParser'; declare var $: any; @Component({ @@ -21,8 +22,8 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { @Output() showListView = new EventEmitter(); @Output() showCreationView = new EventEmitter(); public uploadedFiles: FileSystemFileEntry[] = []; - fileNames: Set = new Set(); - jsonConvert = new JsonConvert(); + fileNames: Set = new Set(); + jsonConvert = new JsonConvert(); public files: NgxFileDropEntry[] = []; fileName: any; templateInfo = new TemplateInfo(); @@ -132,6 +133,11 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { } } + fileExtensionFromString(filename: string): string { + const fileExtension = filename.substring(filename.lastIndexOf('.') + 1); + return fileExtension; + } + public getTemplateVariable(fileContent: string) { const variables: string[] = []; const stringsSlittedByBraces = fileContent.split('${'); @@ -196,22 +202,26 @@ export class TemplMappCreationComponent implements OnInit, OnDestroy { uploadFile() { this.dependancies.clear(); this.dependanciesSource.clear(); - if (this.allowedExt.includes('.csv')) { - this.fetchCSVkeys(); + if (this.allowedExt.includes('.csv') || this.allowedExt.includes('.xml')) { + this.fetchkeysfromfile(); } else { this.setTemplateFilesToStore(); } $('.btn-cancel').click(); - - } - fetchCSVkeys() { + fetchkeysfromfile() { for (const droppedFile of this.uploadedFiles) { droppedFile.file((file: File) => { const fileReader = new FileReader(); fileReader.onload = (e) => { - this.variables = fileReader.result.toString().split(','); + const fileExt = this.fileExtensionFromString(droppedFile.name); + if (fileExt === 'csv') { + this.variables = fileReader.result.toString().split(','); + } else { + const parser = new XmlParser(); + this.variables = parser.getVariables(fileReader.result.toString()); + } console.log(this.variables); this.getMappingTableFromTemplate(null); -- cgit 1.2.3-korg