diff options
author | 2020-03-03 15:29:38 +0200 | |
---|---|---|
committer | 2020-03-06 16:23:50 +0000 | |
commit | 88929cf6c21023328644fc637627371733b085d8 (patch) | |
tree | 3a097e24a3f7d0ac3a23c2f1ac275b6e12aaa3f1 /cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts | |
parent | fdfeef7ae2f543553e2f7a7cf322b6d075599e20 (diff) |
Fixing some bugs in package creation tabs
Issue-ID: CCSDK-2123
Signed-off-by: Ahmed <ahmed.eldeeb.ext@orange.com>
Change-Id: Id7a457470b14ab3491d4e6b9bdd74ef93990dd2c
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts')
-rw-r--r-- | cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts index 36cccc88c..5387489a2 100644 --- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts +++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/scripts-tab/scripts-tab.component.ts @@ -1,6 +1,6 @@ -import {Component, OnInit} from '@angular/core'; -import {FileSystemFileEntry, NgxFileDropEntry} from 'ngx-file-drop'; -import {PackageCreationStore} from '../package-creation.store'; +import { Component, OnInit } from '@angular/core'; +import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop'; +import { PackageCreationStore } from '../package-creation.store'; import 'ace-builds/src-noconflict/ace'; import 'ace-builds/webpack-resolver'; @@ -18,9 +18,7 @@ export class ScriptsTabComponent implements OnInit { constructor( private packageCreationStore: PackageCreationStore, - ) { - - } + ) { } ngOnInit() { @@ -29,13 +27,6 @@ export class ScriptsTabComponent implements OnInit { this.scriptsFiles = cbaPackage.scripts.files; } }); - - /* this.packageStore.state$.subscribe(res => { - // 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 = []; } |