1 import {Component, OnInit} from '@angular/core';
2 import {FileSystemFileEntry, NgxFileDropEntry} from 'ngx-file-drop';
3 import {PackageCreationStore} from '../package-creation.store';
4 import {PackageCreationUtils} from '../package-creation.utils';
5 import 'ace-builds/src-noconflict/ace';
6 import 'ace-builds/webpack-resolver';
9 selector: 'app-scripts-tab',
10 templateUrl: './scripts-tab.component.html',
11 styleUrls: ['./scripts-tab.component.css']
13 export class ScriptsTabComponent implements OnInit {
15 public scriptsFiles: Map<string, string> = new Map<string, string>();
16 public uploadedFiles: FileSystemFileEntry[] = [];
17 public files: NgxFileDropEntry[] = [];
18 private fileNames: Set<string> = new Set();
20 constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) {
21 this.packageCreationStore.state$.subscribe(cbaPackage => {
22 if (cbaPackage.scripts && cbaPackage.scripts.files && cbaPackage.scripts.files.size > 0) {
23 this.scriptsFiles = cbaPackage.scripts.files;
32 public dropped(files: NgxFileDropEntry[]) {
34 for (const droppedFile of files) {
35 // Is it a file & Not added before ?
36 if (droppedFile.fileEntry.isFile && !this.fileNames.has(droppedFile.fileEntry.name)) {
37 const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
38 this.uploadedFiles.push(fileEntry);
39 console.log(fileEntry.name);
40 this.fileNames.add(fileEntry.name);
46 removeFile(fileIndex: number) {
47 console.log(this.uploadedFiles[fileIndex]);
48 const filename = 'Scripts/' + this.uploadedFiles[fileIndex].name;
49 this.packageCreationStore.removeFileFromState(filename);
50 this.uploadedFiles.splice(fileIndex, 1);
53 public fileOver(event) {
57 public fileLeave(event) {
63 for (const droppedFile of this.uploadedFiles) {
64 droppedFile.file((file: File) => {
65 const fileReader = new FileReader();
66 fileReader.onload = (e) => {
67 this.packageCreationStore.addScripts('Scripts/' + droppedFile.name,
68 fileReader.result.toString());
70 fileReader.readAsText(file);
76 resetTheUploadedFiles() {
77 this.uploadedFiles = [];
80 textChanges(code: any, key: string) {
81 this.packageCreationStore.addScripts(key, code);