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';
8 selector: 'app-imports-tab',
9 templateUrl: './imports-tab.component.html',
10 styleUrls: ['./imports-tab.component.css']
12 export class ImportsTabComponent implements OnInit {
14 public definitionFiles: Map<string, string> = new Map<string, string>();
15 public uploadedFiles: FileSystemFileEntry[] = [];
16 private fileNames: Set<string> = new Set();
18 public files: NgxFileDropEntry[] = [];
20 constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) {
23 this.packageCreationStore.state$.subscribe(cbaPackage => {
24 if (cbaPackage.definitions && cbaPackage.definitions.imports && cbaPackage.definitions.imports.size > 0) {
25 this.definitionFiles = cbaPackage.definitions.imports;
30 public dropped(files: NgxFileDropEntry[]) {
32 for (const droppedFile of files) {
33 // Is it a file? & Not added before
34 if (droppedFile.fileEntry.isFile && !this.fileNames.has(droppedFile.fileEntry.name)) {
35 const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
36 this.uploadedFiles.push(fileEntry);
37 console.log(fileEntry.name);
38 this.fileNames.add(fileEntry.name);
44 removeFile(fileIndex: number) {
45 const filename = 'Definitions/' + this.uploadedFiles[fileIndex].name;
46 this.packageCreationStore.removeFileFromDefinition(filename);
47 this.uploadedFiles.splice(fileIndex, 1);
50 public fileOver(event) {
54 public fileLeave(event) {
59 for (const droppedFile of this.uploadedFiles) {
60 droppedFile.file((file: File) => {
61 const fileReader = new FileReader();
62 fileReader.onload = (e) => {
63 this.packageCreationStore.addDefinition('Definitions/' + droppedFile.name,
64 fileReader.result.toString());
66 fileReader.readAsText(file);
72 resetTheUploadedFiles() {
73 this.uploadedFiles = [];
76 textChanges(code: any, key: string) {
77 this.packageCreationStore.addDefinition(key, code);