From 88929cf6c21023328644fc637627371733b085d8 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Tue, 3 Mar 2020 15:29:38 +0200 Subject: Fixing some bugs in package creation tabs Issue-ID: CCSDK-2123 Signed-off-by: Ahmed Change-Id: Id7a457470b14ab3491d4e6b9bdd74ef93990dd2c --- .../scripts-tab/scripts-tab.component.html | 3 +- .../scripts-tab/scripts-tab.component.ts | 47 +++++++++++++--------- 2 files changed, 30 insertions(+), 20 deletions(-) (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab') diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html index 8d1894c57..5dd68ed72 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.html @@ -24,7 +24,8 @@ aria-expanded="false" class="btn btn-link collapsed" data-toggle="collapse"> {{file.key}} - +
{ - // this.scriptsFiles = - console.log('from scripts'); - console.log(res.scripts); - this.scriptsFiles = res.scripts.files; - });*/ } public dropped(files: NgxFileDropEntry[]) { @@ -52,11 +43,18 @@ export class ScriptsTabComponent implements OnInit { } } - removeFile(fileIndex: number) { - console.log(this.uploadedFiles[fileIndex]); - const filename = 'Scripts/' + this.uploadedFiles[fileIndex].name; - this.packageCreationStore.removeFileFromState(filename); - this.uploadedFiles.splice(fileIndex, 1); + removeFile(filePath: string, FileIndex: number) { + const filename = filePath.split('/')[2] || ''; + // const filename = 'Scripts/' + this.getFileType(this.uploadedFiles[fileIndex].name) + '/' + this.uploadedFiles[fileIndex].name; + this.packageCreationStore.removeFileFromState(filePath); + // remove from upload files array + // tslint:disable-next-line: prefer-for-of + for (let i = 0; i < this.uploadedFiles.length; i++) { + if (this.uploadedFiles[i].name === filename) { + this.uploadedFiles.splice(i, 1); + break; + } + } } public fileOver(event) { @@ -73,7 +71,7 @@ export class ScriptsTabComponent implements OnInit { droppedFile.file((file: File) => { const fileReader = new FileReader(); fileReader.onload = (e) => { - this.packageCreationStore.addScripts('Scripts/' + droppedFile.name, + this.packageCreationStore.addScripts('Scripts/' + this.getFileType(droppedFile.name) + '/' + droppedFile.name, fileReader.result.toString()); }; fileReader.readAsText(file); @@ -82,6 +80,17 @@ export class ScriptsTabComponent implements OnInit { } } + getFileType(filename: string): string { + let fileType = ''; + const fileExtension = filename.substring(filename.lastIndexOf('.') + 1); + if (fileExtension === 'py') { + fileType = 'python'; + } else if (fileExtension === 'kt') { + fileType = 'kotlin'; + } + return fileType; + } + resetTheUploadedFiles() { this.uploadedFiles = []; } -- cgit 1.2.3-korg