diff options
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 | 46 |
1 files changed, 34 insertions, 12 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 eee291bba..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,7 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop'; import { PackageCreationStore } from '../package-creation.store'; -import { PackageCreationUtils } from '../package-creation.utils'; import 'ace-builds/src-noconflict/ace'; import 'ace-builds/webpack-resolver'; @@ -17,7 +16,12 @@ export class ScriptsTabComponent implements OnInit { public files: NgxFileDropEntry[] = []; private fileNames: Set<string> = new Set(); - constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) { + constructor( + private packageCreationStore: PackageCreationStore, + ) { } + + + ngOnInit() { this.packageCreationStore.state$.subscribe(cbaPackage => { if (cbaPackage.scripts && cbaPackage.scripts.files && cbaPackage.scripts.files.size > 0) { this.scriptsFiles = cbaPackage.scripts.files; @@ -25,10 +29,6 @@ export class ScriptsTabComponent implements OnInit { }); } - - ngOnInit() { - } - public dropped(files: NgxFileDropEntry[]) { this.files = files; for (const droppedFile of files) { @@ -43,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) { @@ -64,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); @@ -73,7 +80,22 @@ 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 = []; } + + textChanges(code: any, key: string) { + this.packageCreationStore.addScripts(key, code); + } } |